From 0b3aac756a2d086bd96c00a7d21d7fc337cffa48 Mon Sep 17 00:00:00 2001 From: hades Date: Thu, 4 Jun 2020 11:26:59 +0800 Subject: [PATCH] =?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 437569348..466e919b7 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 2cfd36687..e52d4333f 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();