From 965baddd46a1a5f7d322d4d3598b1ad3196342dd Mon Sep 17 00:00:00 2001 From: roger Date: Fri, 22 Dec 2023 09:57:29 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-111690=20A=E7=94=A8=E6=88=B7=E6=96=AD?= =?UTF-8?q?=E7=BD=91=EF=BC=8CB=E7=94=A8=E6=88=B7=E6=89=93=E5=BC=80?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=EF=BC=8CA=E7=94=A8=E6=88=B7=E8=81=94?= =?UTF-8?q?=E7=BD=91=E4=BF=9D=E5=AD=98=EF=BC=8C=E5=89=AF=E6=9C=AC=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/lock/LockFileReSaveEnum.java | 64 +++++++++++++++++++ .../com/fr/design/lock/LockInfoDialog.java | 46 +++++++------ .../worker/save/SaveFailureHandler.java | 32 ++-------- 3 files changed, 95 insertions(+), 47 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/lock/LockFileReSaveEnum.java diff --git a/designer-base/src/main/java/com/fr/design/lock/LockFileReSaveEnum.java b/designer-base/src/main/java/com/fr/design/lock/LockFileReSaveEnum.java new file mode 100644 index 0000000000..3feeb0a0b5 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/lock/LockFileReSaveEnum.java @@ -0,0 +1,64 @@ +package com.fr.design.lock; + +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.file.TemplateTreePane; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.utils.TemplateUtils; +import com.fr.file.FileNodeFILE; +import com.fr.file.filetree.FileNode; +import com.fr.stable.StableUtils; +import com.fr.stable.project.ProjectConstants; + +/** + * 被锁住的文件重新保存副本时的处理枚举类 + * + * @author Roger + * @since 11.0 + * Created on 2023/12/21 + */ +public enum LockFileReSaveEnum { + + /** + * 保存目录树里面的模板副本 + */ + TEMPLATE_TREE() { + @Override + public void action() { + FileNode node = TemplateTreePane.getInstance().getFileNode(); + if (node == null) { + return; + } + final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, TemplateTreePane.getInstance().getFilePath()); + TemplateUtils.createAndReOpenTemplate( + Toolkit.i18nText("Fine_Design_Template_Lock_Copy"), + new FileNodeFILE(new FileNode(selectedFilePath, false)), + false, + true); + } + }, + + /** + * 保存设计器里面已经打开的模板副本 + */ + HISTORY_TEMPLATE_CACHE() { + @Override + public void action() { + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (JTemplate.isValid(template)) { + TemplateUtils.createAndOpenTemplate( + Toolkit.i18nText("Fine_Design_Template_Backup"), + new FileNodeFILE(new FileNode(template.getPath(), false)), + true, + true, + //另存之后需要关闭的模板 + template); + } + } + }; + + /** + * 如何保存模板副本 + */ + public abstract void action(); +} diff --git a/designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java b/designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java index 44c95c44c2..c183dac2e9 100644 --- a/designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java +++ b/designer-base/src/main/java/com/fr/design/lock/LockInfoDialog.java @@ -8,15 +8,14 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; -import com.fr.design.utils.TemplateUtils; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.file.FileNodeFILE; -import com.fr.file.filetree.FileNode; import com.fr.general.IOUtils; -import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; -import com.fr.stable.project.ProjectConstants; import com.fr.workspace.base.UserInfo; + +import javax.swing.BorderFactory; +import javax.swing.JDialog; +import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; @@ -24,9 +23,6 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import javax.swing.BorderFactory; -import javax.swing.JDialog; -import javax.swing.JPanel; /** * @author hades @@ -37,8 +33,11 @@ public class LockInfoDialog extends JDialog { private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"); - public LockInfoDialog(UserInfo userInfo) { + private final LockFileReSaveEnum saveEnum; + + public LockInfoDialog(UserInfo userInfo, LockFileReSaveEnum saveEnum) { super(DesignerContext.getDesignerFrame()); + this.saveEnum = saveEnum; JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); panel.add(createContentPane(userInfo), BorderLayout.CENTER); @@ -94,16 +93,7 @@ public class LockInfoDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { dispose(); - FileNode node = TemplateTreePane.getInstance().getFileNode(); - if (node == null) { - return; - } - final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, TemplateTreePane.getInstance().getFilePath()); - TemplateUtils.createAndReOpenTemplate( - Toolkit.i18nText("Fine_Design_Template_Lock_Copy"), - new FileNodeFILE(new FileNode(selectedFilePath, false)), - false, - true); + saveEnum.action(); } }); cancelButton.addActionListener(new ActionListener() { @@ -118,9 +108,25 @@ public class LockInfoDialog extends JDialog { } + /** + * 显示模板被人锁住了的弹窗信息 + * + * @param userInfo 拥有锁的用户信息 + */ public static void show(UserInfo userInfo) { DesignerFrameFileDealerPane.getInstance().refreshRightToolBarBy(TemplateTreePane.getInstance().getFileNode()); - new LockInfoDialog(userInfo); + new LockInfoDialog(userInfo, LockFileReSaveEnum.TEMPLATE_TREE); + } + + /** + * 显示模板被人锁住了的弹窗信息,并以指定方式保存副本模板 + * + * @param userInfo 拥有锁的用户信息 + * @param saveEnum 指定保存副本模板的处理方式 + */ + public static void show(UserInfo userInfo, LockFileReSaveEnum saveEnum) { + DesignerFrameFileDealerPane.getInstance().refreshRightToolBarBy(TemplateTreePane.getInstance().getFileNode()); + new LockInfoDialog(userInfo, saveEnum); } } diff --git a/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java b/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java index 458ead48a1..bf6209cf6b 100644 --- a/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java +++ b/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java @@ -2,21 +2,17 @@ package com.fr.design.worker.save; import com.fr.common.exception.ThrowableHandler; import com.fr.design.dialog.FineJOptionPane; -import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.i18n.Toolkit; +import com.fr.design.lock.LockFileReSaveEnum; import com.fr.design.lock.LockInfoDialog; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.JTemplate; import com.fr.design.ui.util.UIUtil; -import com.fr.design.utils.TemplateUtils; -import com.fr.file.FileNodeFILE; -import com.fr.file.filetree.FileNode; import com.fr.general.IOUtils; +import com.fr.report.InconsistentLockException; import com.fr.report.LockedException; import com.fr.report.UnLockedException; import com.fr.workspace.base.UserInfo; import com.fr.workspace.exception.DiskSpaceFullException; -import com.fr.report.InconsistentLockException; import java.awt.Frame; import javax.swing.JOptionPane; @@ -104,7 +100,7 @@ public class SaveFailureHandler implements ThrowableHandler { } if (exception != null) { UserInfo userInfo = exception.getUserInfo(); - LockInfoDialog.show(userInfo); + LockInfoDialog.show(userInfo, LockFileReSaveEnum.HISTORY_TEMPLATE_CACHE); return true; } return false; @@ -134,16 +130,7 @@ public class SaveFailureHandler implements ThrowableHandler { IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png"), new Object[] {Toolkit.i18nText("Fine_Design_Template_SaveAs_Backup"), Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")}, null); if (option == JOptionPane.YES_OPTION) { - JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (JTemplate.isValid(template)) { - TemplateUtils.createAndOpenTemplate( - Toolkit.i18nText("Fine_Design_Template_Backup"), - new FileNodeFILE(new FileNode(template.getPath(), false)), - true, - true, - //另存之后需要关闭的模板 - template); - } + LockFileReSaveEnum.HISTORY_TEMPLATE_CACHE.action(); } } @@ -156,16 +143,7 @@ public class SaveFailureHandler implements ThrowableHandler { IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png"), new Object[] {Toolkit.i18nText("Fine_Design_Template_SaveAs_Backup"), Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")}, null); if (option == JOptionPane.YES_OPTION) { - JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (JTemplate.isValid(template)) { - TemplateUtils.createAndOpenTemplate( - Toolkit.i18nText("Fine_Design_Template_Backup"), - new FileNodeFILE(new FileNode(template.getPath(), false)), - true, - true, - //另存之后需要关闭的模板 - template); - } + LockFileReSaveEnum.HISTORY_TEMPLATE_CACHE.action(); } }