forked from fanruan/finekit
richie
5 years ago
1 changed files with 136 additions and 1 deletions
@ -1,4 +1,139 @@
|
||||
package com.fanruan.api.design.work; |
||||
|
||||
public class ReportletPane extends com.fr.design.gui.itree.filetree.ReportletPane { |
||||
import com.fanruan.api.design.DesignKit; |
||||
import com.fanruan.api.design.ui.component.UIButton; |
||||
import com.fanruan.api.design.ui.component.UITextArea; |
||||
import com.fanruan.api.design.ui.container.UIScrollPane; |
||||
import com.fanruan.api.design.util.GUICoreKit; |
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.itree.filetree.ClassFileTree; |
||||
import com.fr.design.gui.itree.filetree.TemplateFileTree; |
||||
import com.fr.file.filetree.IOFileNodeFilter; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
/** |
||||
* 模板选择视图面板 |
||||
*/ |
||||
public class ReportletPane extends BasicPane { |
||||
|
||||
private TemplateFileTree templateReportletTree; |
||||
private UIScrollPane templateScrollPane; |
||||
private ClassFileTree classReportletTree; |
||||
private UIScrollPane classScrollPane; |
||||
|
||||
private UIButton switchButton; |
||||
private CardLayout card; |
||||
private JPanel cardPane; |
||||
|
||||
public ReportletPane() { |
||||
this.setLayout(new BorderLayout()); |
||||
UITextArea textPane = new UITextArea(); |
||||
this.add(textPane, BorderLayout.NORTH); |
||||
textPane.setEditable(false); |
||||
textPane.setLineWrap(true); |
||||
|
||||
textPane.setFont(FRContext.getDefaultValues().getFRFont().deriveFont(Font.BOLD, 12)); |
||||
textPane.setText(DesignKit.i18nText("Fine-Design_Basic_Schedule_The_Selected_File_Must_Be_End_With_Filter")); |
||||
|
||||
JPanel centerPane = GUICoreKit.createBorderLayoutPane(); |
||||
this.add(centerPane, BorderLayout.CENTER); |
||||
|
||||
switchButton = new UIButton("switch"); |
||||
centerPane.add(GUICoreKit.createBorderLayoutPane(switchButton, BorderLayout.WEST), BorderLayout.NORTH); |
||||
switchButton.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent evt) { |
||||
switchCardPane(templateScrollPane.isVisible()); |
||||
} |
||||
}); |
||||
|
||||
cardPane = new JPanel(); |
||||
centerPane.add(cardPane, BorderLayout.CENTER); |
||||
cardPane.setLayout(card = new CardLayout()); |
||||
templateReportletTree = new TemplateFileTree(); |
||||
IOFileNodeFilter filter = new IOFileNodeFilter(new String[]{".cpt", ".class", ".frm", ".form"}); |
||||
templateReportletTree.setFileNodeFilter(filter); |
||||
cardPane.add(templateScrollPane = new UIScrollPane(templateReportletTree), "TEMPLATE"); |
||||
classReportletTree = new ClassFileTree(); |
||||
cardPane.add(classScrollPane = new UIScrollPane(classReportletTree), "CLASS"); |
||||
|
||||
this.refreshEnv(); |
||||
} |
||||
|
||||
/* |
||||
* 切换CardPane |
||||
*/ |
||||
private void switchCardPane(boolean switch2Class) { |
||||
if (switch2Class) { |
||||
card.show(cardPane, "CLASS"); |
||||
switchButton.setText(DesignKit.i18nText("Fine-Design_Basic_Utils_Switch_To_Template_Reportlet")); |
||||
} else { |
||||
card.show(cardPane, "TEMPLATE"); |
||||
switchButton.setText(DesignKit.i18nText("Fine-Design_Basic_Utils_Switch_To_Class_Reportlet")); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 检查是否符合规范 |
||||
* |
||||
* @throws Exception 抛错 |
||||
*/ |
||||
public void checkValid() throws Exception { |
||||
String path = this.getSelectedReportletPath(); |
||||
if (path == null) { |
||||
throw new Exception(DesignKit.i18nText("Fine-Design_Basic_Function_The_Selected_File_Cannot_Be_Null")); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 刷新Env |
||||
*/ |
||||
public void refreshEnv() { |
||||
this.templateReportletTree.refreshEnv(); |
||||
this.classReportletTree.refreshEnv(); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reportlet"); |
||||
} |
||||
|
||||
/** |
||||
* 返回选中的模板的路径 |
||||
* |
||||
* @return 模板路径 |
||||
*/ |
||||
public String getSelectedReportletPath() { |
||||
if (templateScrollPane.isVisible()) { |
||||
return templateReportletTree.getSelectedTemplatePath(); |
||||
} else if (classScrollPane.isVisible()) { |
||||
return classReportletTree.getSelectedClassPath(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 根据路径设置视图中被选中的模板 |
||||
* |
||||
* @param templatePath 模板路径 |
||||
*/ |
||||
public void setSelectedReportletPath(String templatePath) { |
||||
if (templatePath == null) { |
||||
return; |
||||
} |
||||
|
||||
if (templatePath.endsWith(".class")) { |
||||
switchCardPane(true); |
||||
classReportletTree.setSelectedClassPath(templatePath); |
||||
} else { |
||||
switchCardPane(false); |
||||
templateReportletTree.setSelectedTemplatePath(templatePath); |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue