From 16b158d12797ac54427b7e19e62b00d085cfdb49 Mon Sep 17 00:00:00 2001 From: MoMeak Date: Tue, 21 Nov 2017 15:39:21 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-5033=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E6=89=93=E5=BC=80=E6=A8=A1=E6=9D=BF=E5=86=85=E5=AD=98=E4=BC=98?= =?UTF-8?q?=E5=8C=96.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JWorkBook.java | 5 + .../fr/design/designer/TargetComponent.java | 2 + .../design/file/HistoryTemplateListPane.java | 43 +++ .../fr/design/file/MutilTempalteTabPane.java | 22 +- .../fr/design/mainframe/DesignerFrame.java | 8 +- .../com/fr/design/mainframe/JTemplate.java | 9 + .../fr/design/mainframe/JVirtualTemplate.java | 253 ++++++++++++++++++ .../src/com/fr/design/mainframe/JForm.java | 5 + 8 files changed, 341 insertions(+), 6 deletions(-) create mode 100644 designer_base/src/com/fr/design/mainframe/JVirtualTemplate.java diff --git a/designer/src/com/fr/design/mainframe/JWorkBook.java b/designer/src/com/fr/design/mainframe/JWorkBook.java index 2b23dabb7..f36771277 100644 --- a/designer/src/com/fr/design/mainframe/JWorkBook.java +++ b/designer/src/com/fr/design/mainframe/JWorkBook.java @@ -849,6 +849,11 @@ public class JWorkBook extends JTemplate { return true; } + @Override + public boolean isJVirtualTemplate() { + return false; + } + @Override public HyperlinkGroupPane getHyperLinkPane(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) { return ReportHyperlinkGroupPane.getInstance(hyperlinkGroupPaneActionProvider); diff --git a/designer_base/src/com/fr/design/designer/TargetComponent.java b/designer_base/src/com/fr/design/designer/TargetComponent.java index 4eedfa012..1e5cf9cf4 100644 --- a/designer_base/src/com/fr/design/designer/TargetComponent.java +++ b/designer_base/src/com/fr/design/designer/TargetComponent.java @@ -22,6 +22,8 @@ public abstract class TargetComponent extends JComponent { this.target = t; } + public TargetComponent() {} + // TODO ALEX_SEP JWorkBook不想有copy, paste, cut的操作,怎么办? public abstract void copy(); diff --git a/designer_base/src/com/fr/design/file/HistoryTemplateListPane.java b/designer_base/src/com/fr/design/file/HistoryTemplateListPane.java index c61a39c43..de16dd2d9 100644 --- a/designer_base/src/com/fr/design/file/HistoryTemplateListPane.java +++ b/designer_base/src/com/fr/design/file/HistoryTemplateListPane.java @@ -25,6 +25,7 @@ import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilist.UIList; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.JVirtualTemplate; import com.fr.design.module.DesignModuleFactory; import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; @@ -36,6 +37,8 @@ import com.fr.stable.project.ProjectConstants; import com.fr.design.utils.gui.GUIPaintUtils; public class HistoryTemplateListPane extends JPanel implements FileOperations { + //最大保存内存中面板数,为0时关闭优化内存 + private static final int DEAD_LINE = 5; private static final int LIST_BORDER = 4; private List> historyList; private JTemplate editingTemplate; @@ -124,6 +127,26 @@ public class HistoryTemplateListPane extends JPanel implements FileOperations { } + /** + * 临时关闭选择的文件 + * @param selected 选择的 + */ + public void closeVirtualSelectedReport(JTemplate selected) { + DesignModuleFactory.clearChartPropertyPane(); + DesignTableDataManager.closeTemplate(selected); + GeneralContext.removeEnvWillChangedListener(selected.getFullPathName()); + if (contains(selected) == -1) { + return; + } + selected.fireJTemplateClosed(); + selected.stopEditing(); + try { + selected.getEditingFILE().closeTemplate(); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + public JTemplate getCurrentEditingTemplate() { return this.editingTemplate; } @@ -281,10 +304,30 @@ public class HistoryTemplateListPane extends JPanel implements FileOperations { public void add(JTemplate jt) { historyList.add(jt); + closeOverLineTemplate(); refresh(); } } + /** + * 打开new模板的同时关闭old模板,优先关已保存的、先打开的 + */ + public void closeOverLineTemplate() { + int size = historyList.size(); + int vCount = size - DEAD_LINE; + if (DEAD_LINE == 0 || vCount <= 0) { + return; + } + for (int i = 0; i < vCount; i++) { + JTemplate overTemplate = historyList.get(i); + if (!overTemplate.isJVirtualTemplate() && overTemplate.getEditingFILE().exists() && overTemplate.isALLSaved() && overTemplate != editingTemplate) { + closeVirtualSelectedReport(overTemplate); + historyList.set(i, new JVirtualTemplate(overTemplate.getEditingFILE())); + } + } + MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList); + } + /** * 刷新 */ diff --git a/designer_base/src/com/fr/design/file/MutilTempalteTabPane.java b/designer_base/src/com/fr/design/file/MutilTempalteTabPane.java index 4fc8b0640..2e6840728 100644 --- a/designer_base/src/com/fr/design/file/MutilTempalteTabPane.java +++ b/designer_base/src/com/fr/design/file/MutilTempalteTabPane.java @@ -219,12 +219,14 @@ public class MutilTempalteTabPane extends JComponent implements MouseListener, M templates[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectedIndex = index; - DesignerContext.getDesignerFrame().addAndActivateJTemplate(tem); + if (!tem.isJVirtualTemplate()) { + DesignerContext.getDesignerFrame().addAndActivateJTemplate(tem); + } else { + DesignerContext.getDesignerFrame().openTemplate(tem.getEditingFILE()); + } } }); } - - return templates; } @@ -672,7 +674,12 @@ public class MutilTempalteTabPane extends JComponent implements MouseListener, M this.repaint(); return; } - DesignerContext.getDesignerFrame().addAndActivateJTemplate(openedTemplate.get(getTemplateIndex(evtX))); + JTemplate evtXTemplate = openedTemplate.get(getTemplateIndex(evtX)); + if (!evtXTemplate.isJVirtualTemplate()) { + DesignerContext.getDesignerFrame().addAndActivateJTemplate(openedTemplate.get(getTemplateIndex(evtX))); + } else { + DesignerContext.getDesignerFrame().openTemplate(evtXTemplate.getEditingFILE()); + } } isShowList = false; } @@ -779,7 +786,12 @@ public class MutilTempalteTabPane extends JComponent implements MouseListener, M //如果关闭的模板不是当前选中的模板,则激活的模板不变 selectedIndex = HistoryTemplateListPane.getInstance().contains(fileName); } - DesignerContext.getDesignerFrame().activateJTemplate(openedTemplate.get(selectedIndex)); + //如果是已后台关闭的模板,则重新打开文件 + if (!openedTemplate.get(selectedIndex).isJVirtualTemplate()) { + DesignerContext.getDesignerFrame().activateJTemplate(openedTemplate.get(selectedIndex)); + } else { + DesignerContext.getDesignerFrame().openTemplate(openedTemplate.get(selectedIndex).getEditingFILE()); + } } } diff --git a/designer_base/src/com/fr/design/mainframe/DesignerFrame.java b/designer_base/src/com/fr/design/mainframe/DesignerFrame.java index f28c43de7..d51fdafc1 100644 --- a/designer_base/src/com/fr/design/mainframe/DesignerFrame.java +++ b/designer_base/src/com/fr/design/mainframe/DesignerFrame.java @@ -933,8 +933,14 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta } fullName = fullName.replaceAll("/", "\\\\"); int index = HistoryTemplateListPane.getInstance().contains(fullName); + List> historyList = HistoryTemplateListPane.getInstance().getHistoryList(); if (index != -1) { - this.activateJTemplate(HistoryTemplateListPane.getInstance().getHistoryList().get(index)); + if (!historyList.get(index).isJVirtualTemplate()) { + this.activateJTemplate(historyList.get(index)); + } else { + historyList.set(index, jt); + this.addAndActivateJTemplate(historyList.get(index)); + } } else { this.addAndActivateJTemplate(jt); } diff --git a/designer_base/src/com/fr/design/mainframe/JTemplate.java b/designer_base/src/com/fr/design/mainframe/JTemplate.java index aa42804db..f5269efaa 100644 --- a/designer_base/src/com/fr/design/mainframe/JTemplate.java +++ b/designer_base/src/com/fr/design/mainframe/JTemplate.java @@ -83,6 +83,8 @@ public abstract class JTemplate> ex private StringBuilder process = new StringBuilder(""); // 制作模板的过程 public int resolution = ScreenResolution.getScreenResolution(); + public JTemplate() {} + public JTemplate(T t, String defaultFileName) { this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)), true); openTime = System.currentTimeMillis(); @@ -884,6 +886,13 @@ public abstract class JTemplate> ex */ public abstract boolean isJWorkBook(); + /** + * 是否是虚拟工作薄,用于释放该template内存 + * + * @return 是则返回true + */ + public abstract boolean isJVirtualTemplate(); + /** * 返回当前支持的超链界面pane * @return 超链连接界面 diff --git a/designer_base/src/com/fr/design/mainframe/JVirtualTemplate.java b/designer_base/src/com/fr/design/mainframe/JVirtualTemplate.java new file mode 100644 index 000000000..9f047d532 --- /dev/null +++ b/designer_base/src/com/fr/design/mainframe/JVirtualTemplate.java @@ -0,0 +1,253 @@ +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.design.DesignModelAdapter; +import com.fr.design.designer.TargetComponent; +import com.fr.design.gui.frpane.HyperlinkGroupPane; +import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.mainframe.templateinfo.TemplateProcessInfo; +import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; +import com.fr.design.menu.ShortCut; +import com.fr.design.menu.ToolBarDef; +import com.fr.file.FILE; +import com.fr.file.FileNodeFILE; +import com.fr.stable.project.ProjectConstants; + +import javax.swing.*; +import java.io.File; + +/** + * Author : MoMeak + * Date: 17-11-20 + * 极简模式模板----for减少堆内存引用 + * 其他参数都去掉,只保留触发重新激活的文件路径 + */ +public class JVirtualTemplate extends JTemplate { + + private FILE editingFILE = null; + + public JVirtualTemplate(FILE editingFILE) { + setEditingFILE(editingFILE); + } + + public String getFullPathName() { + String editingFileName = getEditingFILE().getPath(); + if (editingFileName.startsWith(ProjectConstants.REPORTLETS_NAME)) { + editingFileName = ((FileNodeFILE) getEditingFILE()).getEnvPath() + File.separator + editingFileName; + } + return editingFileName.replaceAll("/", "\\\\"); + } + + /** + * 得到正在编辑的FILE + * + * @return + */ + public FILE getEditingFILE() { + return this.editingFILE; + } + + /** + * 正在编辑的FILE + * + * @return + */ + public void setEditingFILE(FILE editingFILE) { + this.editingFILE = editingFILE; + } + + @Override + public void refreshEastPropertiesPane() { + + } + + @Override + public TargetComponent getCurrentElementCasePane() { + return null; + } + + @Override + public JComponent getCurrentReportComponentPane() { + return null; + } + + @Override + public TemplateProcessInfo getProcessInfo() { + return null; + } + + @Override + public void setJTemplateResolution(int resolution) { + + } + + @Override + public int getJTemplateResolution() { + return 0; + } + + @Override + protected JComponent createCenterPane() { + return null; + } + + @Override + public void removeTemplateSelection() { + + } + + @Override + public void refreshContainer() { + + } + + @Override + public void removeParameterPaneSelection() { + + } + + @Override + public void setScale(int resolution) { + + } + + @Override + public int getScale() { + return 0; + } + + @Override + public int selfAdaptUpdate() { + return 0; + } + + @Override + protected DesignModelAdapter createDesignModel() { + return null; + } + + @Override + public UIMenuItem[] createMenuItem4Preview() { + return new UIMenuItem[0]; + } + + @Override + protected BaseUndoState createUndoState() { + return null; + } + + @Override + public String suffix() { + return null; + } + + @Override + public void copy() { + + } + + @Override + public boolean paste() { + return false; + } + + @Override + public boolean cut() { + return false; + } + + @Override + public AuthorityEditPane createAuthorityEditPane() { + return null; + } + + @Override + public ToolBarMenuDockPlus getToolBarMenuDockPlus() { + return null; + } + + @Override + public JPanel getEastUpPane() { + return null; + } + + @Override + public JPanel getEastDownPane() { + return null; + } + + @Override + public ToolBarDef[] toolbars4Target() { + return new ToolBarDef[0]; + } + + @Override + public JPanel[] toolbarPanes4Form() { + return new JPanel[0]; + } + + @Override + public ShortCut[] shortcut4TemplateMenu() { + return new ShortCut[0]; + } + + @Override + public ShortCut[] shortCuts4Authority() { + return new ShortCut[0]; + } + + @Override + public JComponent[] toolBarButton4Form() { + return new JComponent[0]; + } + + @Override + public JComponent toolBar4Authority() { + return null; + } + + @Override + public int getToolBarHeight() { + return 0; + } + + @Override + public boolean isJWorkBook() { + return false; + } + + @Override + public boolean isJVirtualTemplate() { + return true; + } + + @Override + public HyperlinkGroupPane getHyperLinkPane(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) { + return null; + } + + @Override + public HyperlinkGroupPane getHyperLinkPaneNoPop(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) { + return null; + } + + @Override + public void setAuthorityMode(boolean isUpMode) { + + } + + @Override + public Icon getIcon() { + if (getFullPathName().endsWith("cpt")) { + return BaseUtils.readIcon("/com/fr/design/images/buttonicon/newcpts.png"); + } else { + return BaseUtils.readIcon("/com/fr/web/images/form/new_form3.png"); + } + } + + @Override + protected void applyUndoState(BaseUndoState baseUndoState) { + + } +} diff --git a/designer_form/src/com/fr/design/mainframe/JForm.java b/designer_form/src/com/fr/design/mainframe/JForm.java index c84f572fd..b2656cb64 100644 --- a/designer_form/src/com/fr/design/mainframe/JForm.java +++ b/designer_form/src/com/fr/design/mainframe/JForm.java @@ -142,6 +142,11 @@ public class JForm extends JTemplate implements BaseJForm { return false; } + @Override + public boolean isJVirtualTemplate() { + return false; + } + /** * 返回当前支持的超链界面pane *