From 5b503ffba630dc6c9189702a0cb601762c3a3113 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Thu, 13 Oct 2022 16:07:40 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-81880=20=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=AE=9A=E4=BD=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/DesignerFrame.java | 35 ++++++++++++++++++ .../actions/replace/ui/ITTableButton.java | 37 +------------------ 2 files changed, 37 insertions(+), 35 deletions(-) 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 dfd2a20cd0..a18cd724d7 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 @@ -886,6 +886,39 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta layeredPane.repaint(); } + /** + * 激活模板 + *

+ * activateJTemplate需要模板存在,openTemplate需要模板保存过,该方法模板保存与未保存皆可激活,模板如果关闭,并且保存过,会重新打开 + * + * @param templatePath 模板路径 template.getPath() + * @param templateName 模板名称 + */ + public void openOrActiveTemplate(String templatePath, String templateName) { + //没保存过的模板如果要激活就要从当前历史模板列表里面找 + if (isTemplateNeverSaved(templatePath)) { + int index = HistoryTemplateListCache.getInstance().contains(templateName); + //如果历史模板列表中存在则激活 + if (index != -1) { + DesignerContext.getDesignerFrame().activateJTemplate(HistoryTemplateListCache.getInstance().getTemplate(index)); + } + } else { + DesignerContext.getDesignerFrame().openTemplate(FILEFactory.createFILE(templatePath)); + } + } + + /** + * 指定路径的模板是否保存过 + * + * @param templatePath 模板路径 template.getPath() + * @return 如果模板没保存过则返回true + */ + private boolean isTemplateNeverSaved(String templatePath) { + FILE tplFile = FILEFactory.createFILE(templatePath); + //没保存过的模板获取到的templatePath所生成的FILE文件会不存在 + return tplFile == null || !tplFile.exists() || StringUtils.isEmpty(templatePath); + } + /** * 当前模板 停用失败 * @@ -1231,6 +1264,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta /** * 判断是否正在进行服务器配置 + * * @return boolean */ public boolean isServerConfig() { @@ -1239,6 +1273,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta /** * 设置是否正在进行服务器配置 + * * @param serverConfig */ public void setServerConfig(boolean serverConfig) { diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableButton.java b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableButton.java index 40e05e615d..35ebedc72a 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableButton.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableButton.java @@ -46,46 +46,13 @@ public class ITTableButton extends AbstractCellEditor implements TableCellEditor if (StringUtils.isNotEmpty(GeneralUtils.objectToString(content.getTrlString()))) { ITReplaceMainDialog.setITReplaceFlag(true); TRL trl = new TRL(GeneralUtils.objectToString(content.getTrlString())); - FILE tplFile = FILEFactory.createFILE(content.getTemplatePath()); - if (tplFile != null && tplFile.exists()) { - //模板已保存 - navigate2ExistedTemplate(tplFile, trl); - } else { - //模板未保存 - navigate2NotExistedTemplate(content, trl); - } + DesignerContext.getDesignerFrame().openOrActiveTemplate(content.getTemplatePath(), content.getTemplateName()); + HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().navigate(trl); } ITReplaceMainDialog.setITReplaceFlag(false); } - - /** - * 模板未保存的跳转逻辑 - * @param content 存储模板名称的数据结构 - * @param trl 跳转链接 - */ - private void navigate2NotExistedTemplate(ITContent content, TRL trl) { - java.util.List> openTemplates = HistoryTemplateListCache.getInstance().getHistoryList(); - for (int i = 0, len = openTemplates.size(); i < len; i++) { - if (StringUtils.equals(openTemplates.get(i).getTemplateName(), content.getTemplateName())) { - DesignerContext.getDesignerFrame().activateJTemplate(openTemplates.get(i)); - HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().navigate(trl); - break; - } - } - } - - /** - * 模板已保存的跳转逻辑 - * @param tplFile 模板的FILE文件 - * @param trl 跳转链接 - */ - private void navigate2ExistedTemplate(FILE tplFile, TRL trl) { - DesignerContext.getDesignerFrame().openTemplate(tplFile); - HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().navigate(trl); - } }); - } /**