From e9abf0da09956d0fc402a03d33e7d70b9295464a Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 17 Mar 2020 11:58:43 +0800 Subject: [PATCH 1/5] =?UTF-8?q?REPORT-27434=201.15jar=E5=81=87=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E9=97=AE=E9=A2=98=20=E7=9B=91=E5=90=AC=E8=A3=85?= =?UTF-8?q?=E7=BD=AE=E9=9C=80=E8=A6=81=E5=90=8C=E6=AD=A5=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JTemplate.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 482b0d337..a6d33b3a4 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -93,6 +93,7 @@ public abstract class JTemplate> protected U authorityUndoState = null; protected T template; // 当前模板 protected TemplateProcessInfo processInfo; // 模板过程的相关信息 + private JComponent centerPane; private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复 private DesignModelAdapter designModel; private PreviewProvider previewType; @@ -121,15 +122,15 @@ public abstract class JTemplate> this.template = t; this.previewType = parserPreviewProvider(t.getPreviewType()); this.editingFILE = file; + addCenterPane(); this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setBorder(BorderFactory.createEmptyBorder()); - this.add(createCenterPane(), BorderLayout.CENTER); this.undoState = createUndoState(); designModel = createDesignModel(); consumeTimer.setEnabled(shouldInitForCollectInfo(isNewFile)); } - + void onGetFocus() { consumeTimer.start(); } @@ -248,17 +249,38 @@ public abstract class JTemplate> /** * 刷新内部资源 + * + * 刷新资源的同时。 + * CenterPane 负责监听改动。 + * 所以需要同步处理 */ public void refreshResource() { try { this.template = JTemplateFactory.asIOFile(this.editingFILE); setTarget(this.template); + + // 先移除旧的。 + removeCenterPane(); + // 加入新的 + addCenterPane(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } } - + + private void addCenterPane() { + + this.centerPane = createCenterPane(); + this.add(centerPane, BorderLayout.CENTER); + } + + private void removeCenterPane() { + + JComponent centerPane = this.centerPane; + this.remove(centerPane); + } + /** * 刷新容器 */ From 872096f863776e74e2efa84aa332c4510d41ae5f Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 17 Mar 2020 20:16:24 +0800 Subject: [PATCH 2/5] =?UTF-8?q?REPORT-27434=201.15jar=E5=81=87=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E9=97=AE=E9=A2=98=20=E6=9B=B4=E6=8D=A2=E4=B8=8B?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E3=80=82=20=E9=87=8D=E6=9E=84=E5=90=8E?= =?UTF-8?q?=E6=94=B9=E5=8A=A8=E4=BA=86=E4=BB=A3=E7=A0=81=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E3=80=82=20=E6=B2=A1=E5=86=8D=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/mainframe/JTemplate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index a6d33b3a4..ef125dc18 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -122,9 +122,9 @@ public abstract class JTemplate> this.template = t; this.previewType = parserPreviewProvider(t.getPreviewType()); this.editingFILE = file; - addCenterPane(); this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setBorder(BorderFactory.createEmptyBorder()); + addCenterPane(); this.undoState = createUndoState(); designModel = createDesignModel(); From 137ef15f48605eaa7db42c38c98b140096c46392 Mon Sep 17 00:00:00 2001 From: hades Date: Thu, 19 Mar 2020 21:19:37 +0800 Subject: [PATCH 3/5] =?UTF-8?q?REPORT-28459=20JWorkBook=E6=9C=AA=E9=87=8A?= =?UTF-8?q?=E6=94=BE=E9=97=AE=E9=A2=98=20=E5=90=8C=E6=AD=A5=E5=88=B0final?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/data/DesignTableDataManager.java | 1 + .../com/fr/design/event/RemoveListener.java | 11 ++++++++++ .../com/fr/design/mainframe/JTemplate.java | 7 +++++++ .../com/fr/design/mainframe/JWorkBook.java | 5 +++++ .../mainframe/ReportComponentComposite.java | 8 ++++++- .../fr/design/mainframe/SheetNameTabPane.java | 21 ++++++++++++++----- 6 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/event/RemoveListener.java diff --git a/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java b/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java index 25492c55e..a84e1337b 100644 --- a/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java +++ b/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java @@ -114,6 +114,7 @@ public abstract class DesignTableDataManager { public static void closeTemplate(JTemplate template) { if (template != null) { + template.whenClose(); columnCache.remove(getEditingTableDataSource()); dsListenersMap.remove(template.getPath()); } diff --git a/designer-base/src/main/java/com/fr/design/event/RemoveListener.java b/designer-base/src/main/java/com/fr/design/event/RemoveListener.java new file mode 100644 index 000000000..ff3eae305 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/event/RemoveListener.java @@ -0,0 +1,11 @@ +package com.fr.design.event; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/3/19 + */ +public interface RemoveListener { + + void doRemoveAction(); +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index ef125dc18..29c1dcb53 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -247,6 +247,13 @@ public abstract class JTemplate> } + /** + * 模板关闭时 + */ + public void whenClose() { + // do nothing + } + /** * 刷新内部资源 * diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java b/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java index 621d3f40b..0759ddf98 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java @@ -1188,4 +1188,9 @@ public class JWorkBook extends JTemplate { provider.addChooseFileFilter(fileChooser, this.suffix()); } } + + @Override + public void whenClose() { + reportComposite.doRemoveAction(); + } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/ReportComponentComposite.java b/designer-realize/src/main/java/com/fr/design/mainframe/ReportComponentComposite.java index 71fb27502..0299899a0 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/ReportComponentComposite.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/ReportComponentComposite.java @@ -3,6 +3,7 @@ package com.fr.design.mainframe; import com.fr.base.ScreenResolution; import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.designer.EditingState; +import com.fr.design.event.RemoveListener; import com.fr.design.event.TargetModifiedListener; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icontainer.UIModeControlContainer; @@ -30,7 +31,7 @@ import java.util.ArrayList; * @editor zhou * @since 2012-3-27下午12:12:05 */ -public class ReportComponentComposite extends JComponent { +public class ReportComponentComposite extends JComponent implements RemoveListener { private static final int MAX = 400; private static final int HUND = 100; @@ -250,4 +251,9 @@ public class ReportComponentComposite extends JComponent { public void fireTargetModified() { parent.fireTargetModified(); } + + @Override + public void doRemoveAction() { + sheetNameTab.doRemoveAction(); + } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/SheetNameTabPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/SheetNameTabPane.java index 747789cdb..74443e831 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/SheetNameTabPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/SheetNameTabPane.java @@ -5,6 +5,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; @@ -27,6 +28,7 @@ import com.fr.base.vcs.DesignerMode; import com.fr.design.actions.UpdateAction; import com.fr.design.constants.UIConstants; import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.event.RemoveListener; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButtonUI; @@ -44,7 +46,6 @@ import com.fr.poly.PolyDesigner; import com.fr.report.poly.PolyWorkSheet; import com.fr.report.report.TemplateReport; import com.fr.report.worksheet.WorkSheet; -import com.fr.stable.ProductConstants; /** * NameTabPane of sheets @@ -52,7 +53,7 @@ import com.fr.stable.ProductConstants; * @editor zhou * @since 2012-3-26下午1:45:53 */ -public class SheetNameTabPane extends JComponent implements MouseListener, MouseMotionListener { +public class SheetNameTabPane extends JComponent implements MouseListener, MouseMotionListener, RemoveListener { private static final Color LINE_COLOR = new Color(0xababab); @@ -140,6 +141,10 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse private boolean isAuthorityEditing = false; + private ComponentListener listener; + + private DesignerFrame designerFrame; + public SheetNameTabPane(ReportComponentComposite reportCompositeX) { this.reportComposite = reportCompositeX; this.setLayout(new BorderLayout(0, 0)); @@ -203,14 +208,20 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse } } }); - - DesignerContext.getDesignerFrame().addComponentListener(new ComponentAdapter(){ + listener = new ComponentAdapter(){ @Override public void componentResized(ComponentEvent e) { for (int i = 0; i < lastOneIndex * NUM; i++) { moveLeft(); } } - }); + }; + designerFrame = DesignerContext.getDesignerFrame(); + designerFrame.addComponentListener(listener); + } + + @Override + public void doRemoveAction() { + designerFrame.removeComponentListener(listener); } private ActionListener createLeftButtonActionListener() { From aaa47a74c6215c43a436289ea10f58ec67ce1bf0 Mon Sep 17 00:00:00 2001 From: hades Date: Fri, 20 Mar 2020 14:53:03 +0800 Subject: [PATCH 4/5] =?UTF-8?q?REPORT-28459=20=E5=9C=BA=E6=99=AF=E8=A1=A5?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/mainframe/DesignerFrame.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java index b7fbae773..38d6a5efe 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java @@ -1110,7 +1110,10 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta int index = HistoryTemplateListCache.getInstance().contains(jt); List> historyList = HistoryTemplateListCache.getInstance().getHistoryList(); if (index != -1) { - historyList.get(index).activeJTemplate(index, jt); + JTemplate currentTemplate = historyList.get(index); + // 双击激活已经打开的模板之前 需要释放一下 + currentTemplate.whenClose(); + currentTemplate.activeJTemplate(index, jt); } else { this.addAndActivateJTemplate(jt); } From 63d019cb6e6903e8fb26fd48705f3267ea29e5cd Mon Sep 17 00:00:00 2001 From: hades Date: Mon, 23 Mar 2020 15:14:21 +0800 Subject: [PATCH 5/5] =?UTF-8?q?REPORT-28459=20JWorkBook=20=E6=9C=AA?= =?UTF-8?q?=E9=87=8A=E6=94=BE=20=E5=90=8C=E6=AD=A5=E5=88=B0final?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/file/HistoryTemplateListCache.java | 17 ++++++++-- .../fr/design/mainframe/DesignerFrame.java | 28 +++++----------- .../file/HistoryTemplateListCacheTest.java | 33 +++++++++++++++++++ 3 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/file/HistoryTemplateListCacheTest.java diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 2f9a69b31..6568f458d 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -178,15 +178,28 @@ public class HistoryTemplateListCache implements CallbackEvent { * @return 位置 */ public int contains(JTemplate jt) { + return contains(jt, null); + } + + public int contains(FILE file) { + return contains(null, file); + } + + private int contains(JTemplate jt, FILE file) { + FILE item = null; + if (jt != null) { + item = jt.getEditingFILE(); + } else { + item = file; + } for (int i = 0; i < historyList.size(); i++) { - if (ComparatorUtils.equals(historyList.get(i).getEditingFILE(), jt.getEditingFILE())) { + if (ComparatorUtils.equals(historyList.get(i).getEditingFILE(), item)) { return i; } } return -1; } - /** * 判断是否打开过该模板 * 由于切换环境不会关闭模板,可能存在同名的模板,所以该方法不能准确找到所选的模板, diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java index 38d6a5efe..dd31d8322 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java @@ -1085,6 +1085,14 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta */ private void openFile(FILE tplFile) { + if (tplFile != null) { + int index = HistoryTemplateListCache.getInstance().contains(tplFile); + if (index != -1) { + HistoryTemplateListCache.getInstance().getHistoryList().get(index).activeOldJTemplate(); + return; + } + } + JTemplate jt = JTemplateFactory.createJTemplate(tplFile); if (jt == null) { return; @@ -1094,26 +1102,6 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta this.addAndActivateJTemplate(); MutilTempalteTabPane.getInstance().setTemTemplate( HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); - } else { - activeTemplate(jt); - } - } - - /** - * 激活指定的模板 - * - * @param jt 当前报表 - * @date 2014-10-14-下午6:31:23 - */ - private void activeTemplate(JTemplate jt) { - // 如果该模板已经打开,则进行激活就可以了 - int index = HistoryTemplateListCache.getInstance().contains(jt); - List> historyList = HistoryTemplateListCache.getInstance().getHistoryList(); - if (index != -1) { - JTemplate currentTemplate = historyList.get(index); - // 双击激活已经打开的模板之前 需要释放一下 - currentTemplate.whenClose(); - currentTemplate.activeJTemplate(index, jt); } else { this.addAndActivateJTemplate(jt); } diff --git a/designer-base/src/test/java/com/fr/design/file/HistoryTemplateListCacheTest.java b/designer-base/src/test/java/com/fr/design/file/HistoryTemplateListCacheTest.java new file mode 100644 index 000000000..bd9f8484d --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/file/HistoryTemplateListCacheTest.java @@ -0,0 +1,33 @@ +package com.fr.design.file; + +import com.fr.design.mainframe.JTemplate; +import com.fr.file.FILE; +import com.fr.invoke.Reflect; +import junit.framework.TestCase; +import org.easymock.EasyMock; +import org.junit.Assert; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/3/23 + */ +public class HistoryTemplateListCacheTest extends TestCase { + + public void testContains() { + JTemplate jTemplate = EasyMock.mock(JTemplate.class); + FILE file = EasyMock.mock(FILE.class); + EasyMock.expect(jTemplate.getEditingFILE()).andReturn(file).anyTimes(); + EasyMock.replay(file); + EasyMock.replay(jTemplate); + Assert.assertEquals(-1, HistoryTemplateListCache.getInstance().contains(file)); + Assert.assertEquals(-1, HistoryTemplateListCache.getInstance().contains(jTemplate)); + Reflect.on(HistoryTemplateListCache.getInstance()).set("historyList", new ArrayList<>(Arrays.asList(jTemplate))); + Assert.assertEquals(0, HistoryTemplateListCache.getInstance().contains(file)); + Assert.assertEquals(0, HistoryTemplateListCache.getInstance().contains(jTemplate)); + } + +} \ No newline at end of file