diff --git a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java index 77c9d2eb8e..0cbbc4002b 100644 --- a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java @@ -173,41 +173,48 @@ public class TemplateUtils { }); } - private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, @Nullable JTemplate template) { - createTemplate(file, oldPath, createByEditingTemplate).thenApply((Function) aBoolean -> { - if (!aBoolean) { - //备份失败直接返回 - return null; + /** + * + * @param file 模板文件 + * @param openNewTemplate 是否需要打开新模板 + * @param template 需要关闭的模板 + */ + private static void openNewTemplate(FILE file, boolean openNewTemplate, @Nullable JTemplate template) { + new SwingWorker() { + @Override + protected Boolean doInBackground() throws Exception { + if (JTemplate.isValid(template)) { + //给要关闭的模板解锁 + WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(template.getPath()); + return true; + } + return false; } - new SwingWorker() { - @Override - protected Boolean doInBackground() throws Exception { - if (JTemplate.isValid(template)) { - //给要关闭的模板解锁 - WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(template.getPath()); - return true; + @Override + protected void done() { + try { + if (get()) { + // 创建备份成功后,关闭原模板 + HistoryTemplateListCache.getInstance().closeSelectedReport(template); } - return false; - } - - @Override - protected void done() { - try { - if (get()) { - // 创建备份成功后,关闭原模板 - HistoryTemplateListCache.getInstance().closeSelectedReport(template); - } - if (openNewTemplate) { - DesignerContext.getDesignerFrame().openTemplate(file); - } - // 备份成功刷新下目录树 展示出来备份的模板 - TemplateTreePane.getInstance().refresh(); - } catch (Exception e) { - SaveFailureHandler.getInstance().process(e); - FineLoggerFactory.getLogger().error(e.getMessage(), e); + if (openNewTemplate) { + DesignerContext.getDesignerFrame().openTemplate(file); } + // 备份成功刷新下目录树 展示出来备份的模板 + TemplateTreePane.getInstance().refresh(); + } catch (Exception e) { + SaveFailureHandler.getInstance().process(e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } - }.execute(); + } + }.execute(); + } + + private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, @Nullable JTemplate template) { + createTemplate(file, oldPath, createByEditingTemplate).thenApply((Function) aBoolean -> { + if (aBoolean) { + openNewTemplate(file, openNewTemplate, template); + } return null; }); }