From c9def50757e53e37103732e90de2d94b618d236d Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 23 Dec 2020 17:45:29 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-44644=20fix=E8=B0=83=E6=95=B4=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/file/HistoryTemplateListCache.java | 15 +++++++++++- .../fr/design/file/MutilTempalteTabPane.java | 2 +- ....java => TemplateFileResourceManager.java} | 24 +++++++------------ ...ava => TemplateFileResourceOperation.java} | 12 ++++++---- .../com/fr/design/file/TemplateTreePane.java | 7 +++--- ...DefaultTemplateFileResourceOperation.java} | 10 ++++---- .../fr/design/fun/LocalResourceProvider.java | 4 ++-- .../DesignerFrameFileDealerPane.java | 12 ---------- .../com/fr/design/mainframe/JTemplate.java | 5 ++-- .../main/java/com/fr/file/FileNodeFILE.java | 4 ++-- 10 files changed, 45 insertions(+), 50 deletions(-) rename designer-base/src/main/java/com/fr/design/file/{ResourceManager.java => TemplateFileResourceManager.java} (77%) rename designer-base/src/main/java/com/fr/design/file/{ResourceOperation.java => TemplateFileResourceOperation.java} (74%) rename designer-base/src/main/java/com/fr/design/file/impl/{DefaultResourceOperation.java => DefaultTemplateFileResourceOperation.java} (75%) 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 763ffcd1ff..154caa32be 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 @@ -23,6 +23,7 @@ import com.fr.stable.CoreConstants; import com.fr.stable.StringUtils; import com.fr.third.org.apache.commons.io.FilenameUtils; +import java.util.LinkedHashMap; import javax.swing.SwingUtilities; import java.io.ByteArrayOutputStream; import java.util.ArrayList; @@ -44,6 +45,9 @@ public class HistoryTemplateListCache implements CallbackEvent { private List> historyList; private JTemplate editingTemplate; + // 插件stop时的已经打开的模板xml byte缓存 插件重新run时 重新加载 + private final Map cacheMap = new LinkedHashMap<>(); + public static HistoryTemplateListCache getInstance() { return Holder.INSTANCE; } @@ -74,7 +78,11 @@ public class HistoryTemplateListCache implements CallbackEvent { selected.fireJTemplateClosed(); selected.stopEditing(); try { - historyList.remove(contains(selected)); + int index = contains(selected); + historyList.remove(index); + if (stashFILEMap != null) { + stashFILEMap.remove(index); + } selected.getEditingFILE().closeTemplate(); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName())); MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList); @@ -422,6 +430,7 @@ public class HistoryTemplateListCache implements CallbackEvent { /** * 重新载入当前模板,刷新数据/对象 */ + @Deprecated public void reloadCurrentTemplate() { JTemplate jt = getCurrentEditingTemplate(); boolean access = jt != null && jt.getEditingFILE() != null && jt.getEditingFILE().exists(); @@ -441,4 +450,8 @@ public class HistoryTemplateListCache implements CallbackEvent { } }); } + + public void stashByName() { + + } } diff --git a/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java b/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java index 4a4a4f734b..3ad4c401a1 100644 --- a/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java +++ b/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java @@ -705,7 +705,7 @@ public class MutilTempalteTabPane extends JComponent { // 只有是环境内的文件,才执行释放锁 if (file != null && file.isEnvFile()) { // release lock - ResourceManager.getInstance().getOperation().closeTpl(file.getPath()); + TemplateFileResourceManager.getOperation().closeTemplate(file.getPath()); } } diff --git a/designer-base/src/main/java/com/fr/design/file/ResourceManager.java b/designer-base/src/main/java/com/fr/design/file/TemplateFileResourceManager.java similarity index 77% rename from designer-base/src/main/java/com/fr/design/file/ResourceManager.java rename to designer-base/src/main/java/com/fr/design/file/TemplateFileResourceManager.java index 5fe6896e91..7755847324 100644 --- a/designer-base/src/main/java/com/fr/design/file/ResourceManager.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateFileResourceManager.java @@ -1,7 +1,7 @@ package com.fr.design.file; import com.fr.design.ExtraDesignClassManager; -import com.fr.design.file.impl.DefaultResourceOperation; +import com.fr.design.file.impl.DefaultTemplateFileResourceOperation; import com.fr.design.fun.LocalResourceProvider; import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.ui.util.UIUtil; @@ -21,19 +21,17 @@ import com.fr.workspace.engine.base.FineObjectPool; * @version 10.0 * Created by hades on 2020/12/23 */ -public class ResourceManager { +public class TemplateFileResourceManager { - private static final ResourceManager INSTANCE = new ResourceManager(); + private static TemplateFileResourceOperation OPERATION = new DefaultTemplateFileResourceOperation(); - private ResourceOperation operation = new DefaultResourceOperation(); - - private ResourceManager() { + private TemplateFileResourceManager() { PluginFilter filter = pluginContext -> pluginContext.contain(PluginModule.ExtraDesign, LocalResourceProvider.XML_TAG); PluginListenerRegistration.getInstance().listen(PluginEventType.AfterStop, new PluginEventListener() { @Override public void on(PluginEvent event) { - registerOperation(new DefaultResourceOperation()); + registerOperation(new DefaultTemplateFileResourceOperation()); FineObjectPool.getInstance().getLocalPool().put(FileNodes.class, new LocalFileNodes()); UIUtil.invokeLaterIfNeeded(() -> DesignerFrameFileDealerPane.getInstance().refresh()); } @@ -52,16 +50,12 @@ public class ResourceManager { }, filter); } - public static ResourceManager getInstance() { - return INSTANCE; - } - - private void registerOperation(ResourceOperation operation) { - this.operation = operation; + private static void registerOperation(TemplateFileResourceOperation operation) { + OPERATION = operation; } - public ResourceOperation getOperation() { - return this.operation; + public static TemplateFileResourceOperation getOperation() { + return OPERATION; } } diff --git a/designer-base/src/main/java/com/fr/design/file/ResourceOperation.java b/designer-base/src/main/java/com/fr/design/file/TemplateFileResourceOperation.java similarity index 74% rename from designer-base/src/main/java/com/fr/design/file/ResourceOperation.java rename to designer-base/src/main/java/com/fr/design/file/TemplateFileResourceOperation.java index 29834cf60c..5b1ba9c893 100644 --- a/designer-base/src/main/java/com/fr/design/file/ResourceOperation.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateFileResourceOperation.java @@ -6,12 +6,14 @@ import java.io.InputStream; import java.io.OutputStream; /** + * 模板资源操作,可操作模板及模板目录 + * * @author hades * @version 10.0 * Created by hades on 2020/12/23 */ @Open -public interface ResourceOperation { +public interface TemplateFileResourceOperation { /** * 读取模板 @@ -19,7 +21,7 @@ public interface ResourceOperation { * @return * @throws Exception */ - InputStream readTpl(String path) throws Exception; + InputStream readTemplate(String path) throws Exception; /** * 保存模板 @@ -27,7 +29,7 @@ public interface ResourceOperation { * @return * @throws Exception */ - OutputStream saveTpl(FILE file) throws Exception; + OutputStream saveTemplate(FILE file) throws Exception; /** * 删除某个目录/某个模板 @@ -41,7 +43,7 @@ public interface ResourceOperation { * @param path * @return */ - boolean closeTpl(String path); + boolean closeTemplate(String path); /** * 重命名模板/路径 @@ -52,7 +54,7 @@ public interface ResourceOperation { boolean rename(String from, String to); /** - * 创建工作目录 + * 创建目录 * @param path * @return */ diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java index d6b50ab7c2..f54fd8eeb4 100644 --- a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java @@ -25,7 +25,6 @@ import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.project.ProjectConstants; import com.fr.workspace.WorkContext; -import com.fr.workspace.server.lock.TplOperator; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -194,7 +193,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { @Override public boolean mkdir(String path) { - return ResourceManager.getInstance().getOperation().mkdir(path); + return TemplateFileResourceManager.getOperation().mkdir(path); } /** @@ -337,7 +336,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { if (node instanceof FileNode) { FileNodeFILE nodeFILE = new FileNodeFILE((FileNode) node); if (nodeFILE.exists()) { - if (ResourceManager.getInstance().getOperation().delete(nodeFILE)) { + if (TemplateFileResourceManager.getOperation().delete(nodeFILE)) { HistoryTemplateListCache.getInstance().deleteFile(nodeFILE); } else { success = false; @@ -439,7 +438,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { try { // 接收的是WEB-INF下的路径 - return ResourceManager.getInstance().getOperation().rename(from, to); + return TemplateFileResourceManager.getOperation().rename(from, to); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); return false; diff --git a/designer-base/src/main/java/com/fr/design/file/impl/DefaultResourceOperation.java b/designer-base/src/main/java/com/fr/design/file/impl/DefaultTemplateFileResourceOperation.java similarity index 75% rename from designer-base/src/main/java/com/fr/design/file/impl/DefaultResourceOperation.java rename to designer-base/src/main/java/com/fr/design/file/impl/DefaultTemplateFileResourceOperation.java index b065203195..e72d78fca0 100644 --- a/designer-base/src/main/java/com/fr/design/file/impl/DefaultResourceOperation.java +++ b/designer-base/src/main/java/com/fr/design/file/impl/DefaultTemplateFileResourceOperation.java @@ -1,6 +1,6 @@ package com.fr.design.file.impl; -import com.fr.design.file.ResourceOperation; +import com.fr.design.file.TemplateFileResourceOperation; import com.fr.file.FILE; import com.fr.workspace.WorkContext; import com.fr.workspace.server.lock.TplOperator; @@ -13,20 +13,20 @@ import java.io.OutputStream; * @version 10.0 * Created by hades on 2020/12/23 */ -public class DefaultResourceOperation implements ResourceOperation { +public class DefaultTemplateFileResourceOperation implements TemplateFileResourceOperation { @Override - public InputStream readTpl(String path) throws Exception { + public InputStream readTemplate(String path) throws Exception { return new ByteArrayInputStream(WorkContext.getCurrent().get(TplOperator.class).readAndLockFile(path)); } @Override - public OutputStream saveTpl(FILE file) throws Exception { + public OutputStream saveTemplate(FILE file) throws Exception { return file.asOutputStream(); } @Override - public boolean closeTpl(String path) { + public boolean closeTemplate(String path) { return WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(path); } diff --git a/designer-base/src/main/java/com/fr/design/fun/LocalResourceProvider.java b/designer-base/src/main/java/com/fr/design/fun/LocalResourceProvider.java index afc8ad545b..51b36d9161 100644 --- a/designer-base/src/main/java/com/fr/design/fun/LocalResourceProvider.java +++ b/designer-base/src/main/java/com/fr/design/fun/LocalResourceProvider.java @@ -1,6 +1,6 @@ package com.fr.design.fun; -import com.fr.design.file.ResourceOperation; +import com.fr.design.file.TemplateFileResourceOperation; import com.fr.file.filetree.FileNodes; import com.fr.stable.fun.mark.Immutable; @@ -22,7 +22,7 @@ public interface LocalResourceProvider extends Immutable { * * @return 目录/模板的各种操作 */ - ResourceOperation createResourceOperation(); + TemplateFileResourceOperation createResourceOperation(); /** * eg: LocalFileNodes diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java index 50c61cda26..83120e4fb0 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java @@ -18,7 +18,6 @@ import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.MutilTempalteTabPane; import com.fr.design.file.TemplateTreePane; -import com.fr.design.fun.LocalResourceProvider; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIMenuHighLight; @@ -34,13 +33,10 @@ import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.ShortCut; import com.fr.design.menu.ToolBarDef; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; -import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.file.FileNodeFILE; import com.fr.file.filetree.FileNode; -import com.fr.file.filetree.FileNodes; -import com.fr.file.filetree.LocalFileNodes; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.log.FineLoggerFactory; @@ -49,8 +45,6 @@ import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.manage.PluginFilter; import com.fr.plugin.observer.PluginEvent; import com.fr.plugin.observer.PluginEventListener; -import com.fr.plugin.observer.PluginEventType; -import com.fr.plugin.observer.PluginListenerRegistration; import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; @@ -58,17 +52,11 @@ import com.fr.stable.project.ProjectConstants; import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.workspace.WorkContext; -import com.fr.workspace.engine.base.FineObjectPool; -import com.fr.workspace.engine.resource.FineWorkResource; -import com.fr.workspace.resource.WorkResource; -import com.fr.workspace.server.lock.LocalTplOperator; -import com.fr.workspace.server.lock.TplOperator; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingConstants; -import javax.swing.UIManager; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import java.awt.BorderLayout; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 929519b184..dbf61e8b59 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -3,7 +3,6 @@ package com.fr.design.mainframe; import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.base.Parameter; -import com.fr.base.ScreenResolution; import com.fr.base.io.BaseBook; import com.fr.base.iofile.attr.DesignBanCopyAttrMark; import com.fr.base.iofile.attr.TemplateIdAttrMark; @@ -24,7 +23,7 @@ import com.fr.design.designer.TargetComponent; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.InformationWarnPane; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.file.ResourceManager; +import com.fr.design.file.TemplateFileResourceManager; import com.fr.design.file.TemplateTreePane; import com.fr.design.fun.DesignerFrameUpButtonProvider; import com.fr.design.fun.MenuHandler; @@ -814,7 +813,7 @@ public abstract class JTemplate> return false; } try { - this.getTarget().export(ResourceManager.getInstance().getOperation().saveTpl(editingFILE)); + this.getTarget().export(TemplateFileResourceManager.getOperation().saveTemplate(editingFILE)); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE); diff --git a/designer-base/src/main/java/com/fr/file/FileNodeFILE.java b/designer-base/src/main/java/com/fr/file/FileNodeFILE.java index 4b388be365..ac109606f9 100644 --- a/designer-base/src/main/java/com/fr/file/FileNodeFILE.java +++ b/designer-base/src/main/java/com/fr/file/FileNodeFILE.java @@ -2,7 +2,7 @@ package com.fr.file; import com.fr.base.BaseUtils; import com.fr.base.FRContext; -import com.fr.design.file.ResourceManager; +import com.fr.design.file.TemplateFileResourceManager; import com.fr.io.FineEncryptUtils; import com.fr.base.io.XMLEncryptUtils; import com.fr.design.file.NodeAuthProcessor; @@ -378,7 +378,7 @@ public class FileNodeFILE implements FILE { if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { return null; } - InputStream in = ResourceManager.getInstance().getOperation().readTpl( + InputStream in = TemplateFileResourceManager.getOperation().readTemplate( StableUtils.pathJoin( ProjectConstants.REPORTLETS_NAME, envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)