From 9018c51a45ac44d0d2fb795875f205d9dd400a11 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 3 Jun 2020 22:30:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-32939=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E6=AD=A3=E5=B8=B82g=E7=9B=AE=E5=89=8D=E7=BB=8F=E5=B8=B8?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E6=8E=92=E9=98=9F=E7=8E=B0=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/file/HistoryTemplateListCache.java | 36 +++++++++++++++++++ .../fr/design/mainframe/DesignerFrame.java | 16 ++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) 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 cb68bb6e47..4375693485 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 @@ -42,6 +42,14 @@ public class HistoryTemplateListCache implements CallbackEvent { private List> historyList; private JTemplate editingTemplate; + /** + * 当设计器打开的模板数大于模板缓存对象个数时,会产生JVirtualTemplate(个数=打开的总模板数 - 缓存模板数) + * 每次点击切换模板时,当切换到JVirtualTemplate,会创建真实的JTemplate,但是该JTemplate创建后不会释放掉,需要调用whenClose主动释放 + * 该变量对JVirtualTemplate创建真实的JTemplate管理 + */ + private JTemplate currentVirtualReplaceTemplate; + + public static HistoryTemplateListCache getInstance() { return Holder.INSTANCE; } @@ -112,6 +120,14 @@ public class HistoryTemplateListCache implements CallbackEvent { * @see DesignerFrameFileDealerPane#setCurrentEditingTemplate(JTemplate) */ public void setCurrentEditingTemplate(JTemplate jt) { + + // 模板之间切换 如果存在上次JVirtualTemplate创建的真实模板 需要在此关闭,并释放掉 + boolean canReleaseVirtualReplaceTemplate = this.currentVirtualReplaceTemplate != null && jt != null + && !ComparatorUtils.equals(this.currentVirtualReplaceTemplate.getEditingFILE(), jt.getEditingFILE()); + if (canReleaseVirtualReplaceTemplate) { + HistoryTemplateListCache.getInstance().releaseVirtualReplaceTemplate(); + } + this.editingTemplate = jt; //如果当前历史面板中没有 @@ -423,4 +439,24 @@ public class HistoryTemplateListCache implements CallbackEvent { } } + + public void setCurrentVirtualReplaceTemplate(JTemplate currentVirtualReplaceTemplate) { + // 保证先释放 + releaseVirtualReplaceTemplate(); + this.currentVirtualReplaceTemplate = currentVirtualReplaceTemplate; + } + + public JTemplate getCurrentVirtualReplaceTemplate() { + return currentVirtualReplaceTemplate; + } + + /** + * 释放JVirtualTemplate创建的真实模板JTemplate + */ + private void releaseVirtualReplaceTemplate() { + if (this.currentVirtualReplaceTemplate != null) { + this.currentVirtualReplaceTemplate.whenClose(); + this.currentVirtualReplaceTemplate = null; + } + } } 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 2cf8d8c350..e5b8e8b7e0 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 @@ -1101,11 +1101,19 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta */ private void openFile(FILE tplFile) { + boolean virtualTemplate = false; if (tplFile != null) { int index = HistoryTemplateListCache.getInstance().contains(tplFile); if (index != -1) { JTemplate jt = HistoryTemplateListCache.getInstance().getHistoryList().get(index); - if (!(jt instanceof JVirtualTemplate)) { + if (jt instanceof JVirtualTemplate) { + JTemplate currentVirtualReplaceTemplate = HistoryTemplateListCache.getInstance().getCurrentVirtualReplaceTemplate(); + if (currentVirtualReplaceTemplate != null && ComparatorUtils.equals(currentVirtualReplaceTemplate.getEditingFILE(), jt.getEditingFILE())) { + currentVirtualReplaceTemplate.activeOldJTemplate(); + return; + } + virtualTemplate = true; + } else { jt.activeOldJTemplate(); return; } @@ -1116,6 +1124,12 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta if (jt == null) { return; } + + // 将JVirtualTemplate创建的真实模板管理起来 + if (virtualTemplate) { + HistoryTemplateListCache.getInstance().setCurrentVirtualReplaceTemplate(jt); + } + // 新的form不往前兼容 if (inValidDesigner(jt)) { this.addAndActivateJTemplate(); From 838183e165e8c864ef7a66c30cdee5cf635d6ac2 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 3 Jun 2020 22:37:06 +0800 Subject: [PATCH 2/3] REPORT-32939 add comment --- .../src/main/java/com/fr/design/mainframe/DesignerFrame.java | 1 + 1 file changed, 1 insertion(+) 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 e5b8e8b7e0..2cfd36687b 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 @@ -1109,6 +1109,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta if (jt instanceof JVirtualTemplate) { JTemplate currentVirtualReplaceTemplate = HistoryTemplateListCache.getInstance().getCurrentVirtualReplaceTemplate(); if (currentVirtualReplaceTemplate != null && ComparatorUtils.equals(currentVirtualReplaceTemplate.getEditingFILE(), jt.getEditingFILE())) { + // 防止在打开了模板的情况下 去双击目录树对应的模板重复创建JTemplate currentVirtualReplaceTemplate.activeOldJTemplate(); return; } From 0b3aac756a2d086bd96c00a7d21d7fc337cffa48 Mon Sep 17 00:00:00 2001 From: hades Date: Thu, 4 Jun 2020 11:26:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-33018=20=20fix=20=E6=B2=BF=E7=94=A8?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84=E6=96=B9=E6=A1=88=E9=80=BB=E8=BE=91?= =?UTF-8?q?=20=E9=98=B2=E6=AD=A2=E4=BA=A7=E7=94=9F=E5=81=87=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/file/HistoryTemplateListCache.java | 37 ------------------- .../fr/design/mainframe/DesignerFrame.java | 19 ++++------ 2 files changed, 7 insertions(+), 49 deletions(-) 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 4375693485..466e919b72 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 @@ -42,14 +42,6 @@ public class HistoryTemplateListCache implements CallbackEvent { private List> historyList; private JTemplate editingTemplate; - /** - * 当设计器打开的模板数大于模板缓存对象个数时,会产生JVirtualTemplate(个数=打开的总模板数 - 缓存模板数) - * 每次点击切换模板时,当切换到JVirtualTemplate,会创建真实的JTemplate,但是该JTemplate创建后不会释放掉,需要调用whenClose主动释放 - * 该变量对JVirtualTemplate创建真实的JTemplate管理 - */ - private JTemplate currentVirtualReplaceTemplate; - - public static HistoryTemplateListCache getInstance() { return Holder.INSTANCE; } @@ -120,14 +112,6 @@ public class HistoryTemplateListCache implements CallbackEvent { * @see DesignerFrameFileDealerPane#setCurrentEditingTemplate(JTemplate) */ public void setCurrentEditingTemplate(JTemplate jt) { - - // 模板之间切换 如果存在上次JVirtualTemplate创建的真实模板 需要在此关闭,并释放掉 - boolean canReleaseVirtualReplaceTemplate = this.currentVirtualReplaceTemplate != null && jt != null - && !ComparatorUtils.equals(this.currentVirtualReplaceTemplate.getEditingFILE(), jt.getEditingFILE()); - if (canReleaseVirtualReplaceTemplate) { - HistoryTemplateListCache.getInstance().releaseVirtualReplaceTemplate(); - } - this.editingTemplate = jt; //如果当前历史面板中没有 @@ -438,25 +422,4 @@ public class HistoryTemplateListCache implements CallbackEvent { jt.refreshResource(); } } - - - public void setCurrentVirtualReplaceTemplate(JTemplate currentVirtualReplaceTemplate) { - // 保证先释放 - releaseVirtualReplaceTemplate(); - this.currentVirtualReplaceTemplate = currentVirtualReplaceTemplate; - } - - public JTemplate getCurrentVirtualReplaceTemplate() { - return currentVirtualReplaceTemplate; - } - - /** - * 释放JVirtualTemplate创建的真实模板JTemplate - */ - private void releaseVirtualReplaceTemplate() { - if (this.currentVirtualReplaceTemplate != null) { - this.currentVirtualReplaceTemplate.whenClose(); - this.currentVirtualReplaceTemplate = null; - } - } } 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 2cfd36687b..e52d4333fd 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 @@ -1101,19 +1101,20 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta */ private void openFile(FILE tplFile) { - boolean virtualTemplate = false; if (tplFile != null) { int index = HistoryTemplateListCache.getInstance().contains(tplFile); if (index != -1) { JTemplate jt = HistoryTemplateListCache.getInstance().getHistoryList().get(index); if (jt instanceof JVirtualTemplate) { - JTemplate currentVirtualReplaceTemplate = HistoryTemplateListCache.getInstance().getCurrentVirtualReplaceTemplate(); - if (currentVirtualReplaceTemplate != null && ComparatorUtils.equals(currentVirtualReplaceTemplate.getEditingFILE(), jt.getEditingFILE())) { - // 防止在打开了模板的情况下 去双击目录树对应的模板重复创建JTemplate - currentVirtualReplaceTemplate.activeOldJTemplate(); + // 如果是JVirtualTemplate 创建真实JTemplate + JTemplate realJTemplate = JTemplateFactory.createJTemplate(tplFile); + if (realJTemplate == null) { return; } - virtualTemplate = true; + // 由JVirtualTemplate激活真实JTemplate 本质在historyList中进行替换 + // 同时 realJTemplate被管理起来 不需要主动释放 关闭时会自动释放 + jt.activeJTemplate(index, realJTemplate); + return; } else { jt.activeOldJTemplate(); return; @@ -1125,12 +1126,6 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta if (jt == null) { return; } - - // 将JVirtualTemplate创建的真实模板管理起来 - if (virtualTemplate) { - HistoryTemplateListCache.getInstance().setCurrentVirtualReplaceTemplate(jt); - } - // 新的form不往前兼容 if (inValidDesigner(jt)) { this.addAndActivateJTemplate();