From a042152f1bf8655c4468fbe0479f9686cc6e3dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=2EYing-=E5=BA=94=E5=BF=97=E6=B5=A9?= Date: Thu, 6 Apr 2023 15:29:32 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-92893=20=E9=94=81=E5=AE=9A=E7=9A=84?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=EF=BC=8C=E9=87=8D=E5=A4=8D=E5=8F=A6=E5=AD=98?= =?UTF-8?q?=E5=89=AF=E6=9C=AC=EF=BC=8C=E8=AE=BE=E8=AE=A1=E5=99=A8=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=A8=A1=E6=9D=BF=E5=86=85=E5=AE=B9=E4=B8=8D=E6=9B=B4?= =?UTF-8?q?=E6=96=B0--=E6=96=B9=E6=B3=95=E6=8B=86=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/utils/TemplateUtils.java | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) 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; }); }