From b48bf4fb84682061a4338ab8239bc29ede0178d3 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 23 Dec 2020 17:04:32 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-44644=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=BC=80=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/file/MutilTempalteTabPane.java | 4 +- .../com/fr/design/file/ResourceManager.java | 67 +++++++++++++++++++ .../com/fr/design/file/ResourceOperation.java | 62 +++++++++++++++++ .../com/fr/design/file/TemplateTreePane.java | 6 +- .../file/impl/DefaultResourceOperation.java | 48 +++++++++++++ .../fr/design/fun/LocalResourceProvider.java | 17 ++--- .../DesignerFrameFileDealerPane.java | 24 ------- .../com/fr/design/mainframe/JTemplate.java | 3 +- .../main/java/com/fr/file/FileNodeFILE.java | 16 ++--- 9 files changed, 193 insertions(+), 54 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/file/ResourceManager.java create mode 100644 designer-base/src/main/java/com/fr/design/file/ResourceOperation.java create mode 100644 designer-base/src/main/java/com/fr/design/file/impl/DefaultResourceOperation.java 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 69aee1b50e..4a4a4f734b 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 @@ -18,8 +18,6 @@ import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.Constants; import com.fr.third.javax.annotation.Nonnull; -import com.fr.workspace.WorkContext; -import com.fr.workspace.server.lock.TplOperator; import javax.swing.BorderFactory; import javax.swing.ButtonModel; @@ -707,7 +705,7 @@ public class MutilTempalteTabPane extends JComponent { // 只有是环境内的文件,才执行释放锁 if (file != null && file.isEnvFile()) { // release lock - WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath()); + ResourceManager.getInstance().getOperation().closeTpl(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/ResourceManager.java new file mode 100644 index 0000000000..5fe6896e91 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/file/ResourceManager.java @@ -0,0 +1,67 @@ +package com.fr.design.file; + +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.file.impl.DefaultResourceOperation; +import com.fr.design.fun.LocalResourceProvider; +import com.fr.design.mainframe.DesignerFrameFileDealerPane; +import com.fr.design.ui.util.UIUtil; +import com.fr.file.filetree.FileNodes; +import com.fr.file.filetree.LocalFileNodes; +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.workspace.WorkContext; +import com.fr.workspace.engine.base.FineObjectPool; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/12/23 + */ +public class ResourceManager { + + private static final ResourceManager INSTANCE = new ResourceManager(); + + private ResourceOperation operation = new DefaultResourceOperation(); + + private ResourceManager() { + 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()); + FineObjectPool.getInstance().getLocalPool().put(FileNodes.class, new LocalFileNodes()); + UIUtil.invokeLaterIfNeeded(() -> DesignerFrameFileDealerPane.getInstance().refresh()); + } + }, filter); + + PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, new PluginEventListener() { + @Override + public void on(PluginEvent event) { + LocalResourceProvider provider = ExtraDesignClassManager.getInstance().getSingle(LocalResourceProvider.XML_TAG); + if (provider != null && WorkContext.getCurrent().isLocal()) { + registerOperation(provider.createResourceOperation()); + FineObjectPool.getInstance().getLocalPool().put(FileNodes.class, provider.createFileNodes()); + UIUtil.invokeLaterIfNeeded(() -> DesignerFrameFileDealerPane.getInstance().refresh()); + } + } + }, filter); + } + + public static ResourceManager getInstance() { + return INSTANCE; + } + + private void registerOperation(ResourceOperation operation) { + this.operation = operation; + } + + public ResourceOperation getOperation() { + return this.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/ResourceOperation.java new file mode 100644 index 0000000000..29834cf60c --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/file/ResourceOperation.java @@ -0,0 +1,62 @@ +package com.fr.design.file; + +import com.fr.common.annotations.Open; +import com.fr.file.FILE; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/12/23 + */ +@Open +public interface ResourceOperation { + + /** + * 读取模板 + * @param path + * @return + * @throws Exception + */ + InputStream readTpl(String path) throws Exception; + + /** + * 保存模板 + * @param file + * @return + * @throws Exception + */ + OutputStream saveTpl(FILE file) throws Exception; + + /** + * 删除某个目录/某个模板 + * @param file + * @return + */ + boolean delete(FILE file); + + /** + * 关闭模板 + * @param path + * @return + */ + boolean closeTpl(String path); + + /** + * 重命名模板/路径 + * @param from + * @param to + * @return + */ + boolean rename(String from, String to); + + /** + * 创建工作目录 + * @param path + * @return + */ + boolean mkdir(String path); + + +} 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 8c731e1f0b..d6b50ab7c2 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 @@ -194,7 +194,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { @Override public boolean mkdir(String path) { - return WorkContext.getWorkResource().createDirectory(path); + return ResourceManager.getInstance().getOperation().mkdir(path); } /** @@ -337,7 +337,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { if (node instanceof FileNode) { FileNodeFILE nodeFILE = new FileNodeFILE((FileNode) node); if (nodeFILE.exists()) { - if (WorkContext.getCurrent().get(TplOperator.class).delete(nodeFILE.getPath())) { + if (ResourceManager.getInstance().getOperation().delete(nodeFILE)) { HistoryTemplateListCache.getInstance().deleteFile(nodeFILE); } else { success = false; @@ -439,7 +439,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { try { // 接收的是WEB-INF下的路径 - return WorkContext.getCurrent().get(TplOperator.class).rename(from, to); + return ResourceManager.getInstance().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/DefaultResourceOperation.java new file mode 100644 index 0000000000..b065203195 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/file/impl/DefaultResourceOperation.java @@ -0,0 +1,48 @@ +package com.fr.design.file.impl; + +import com.fr.design.file.ResourceOperation; +import com.fr.file.FILE; +import com.fr.workspace.WorkContext; +import com.fr.workspace.server.lock.TplOperator; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/12/23 + */ +public class DefaultResourceOperation implements ResourceOperation { + + @Override + public InputStream readTpl(String path) throws Exception { + return new ByteArrayInputStream(WorkContext.getCurrent().get(TplOperator.class).readAndLockFile(path)); + } + + @Override + public OutputStream saveTpl(FILE file) throws Exception { + return file.asOutputStream(); + } + + @Override + public boolean closeTpl(String path) { + return WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(path); + } + + @Override + public boolean delete(FILE file) { + return WorkContext.getCurrent().get(TplOperator.class).delete(file.getPath()); + } + + @Override + public boolean rename(String from, String to) { + return WorkContext.getCurrent().get(TplOperator.class).rename(from, to); + } + + @Override + public boolean mkdir(String path) { + return WorkContext.getWorkResource().createDirectory(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 482acd941f..afc8ad545b 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,9 +1,8 @@ package com.fr.design.fun; +import com.fr.design.file.ResourceOperation; import com.fr.file.filetree.FileNodes; import com.fr.stable.fun.mark.Immutable; -import com.fr.workspace.resource.WorkResource; -import com.fr.workspace.server.lock.TplOperator; /** * 本地资源操作插件接口 @@ -19,12 +18,11 @@ public interface LocalResourceProvider extends Immutable { int CURRENT_LEVEL = 1; /** - * eg: FineWorkResource + * eg: DefaultResourceOperation * - * @return 目录/文件的操作方式 + * @return 目录/模板的各种操作 */ - WorkResource createResource(); - + ResourceOperation createResourceOperation(); /** * eg: LocalFileNodes @@ -33,11 +31,4 @@ public interface LocalResourceProvider extends Immutable { */ FileNodes createFileNodes(); - /** - * eg:LocalTplOperator - * - * 模板操作 关闭/打开等操作 - */ - TplOperator createTplOperator(); - } 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 e019e31b4f..50c61cda26 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 @@ -108,30 +108,6 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt return context.contain(PluginModule.ExtraDesign, ShortCut.TEMPLATE_TREE); } }); - PluginFilter filter = pluginContext -> pluginContext.contain(PluginModule.ExtraDesign, LocalResourceProvider.XML_TAG); - - PluginListenerRegistration.getInstance().listen(PluginEventType.AfterStop, new PluginEventListener() { - @Override - public void on(PluginEvent event) { - FineObjectPool.getInstance().getLocalPool().put(WorkResource.class, FineWorkResource.getInstance()); - FineObjectPool.getInstance().getLocalPool().put(FileNodes.class, new LocalFileNodes()); - FineObjectPool.getInstance().getLocalPool().put(TplOperator.class, new LocalTplOperator()); - UIUtil.invokeLaterIfNeeded(() -> DesignerFrameFileDealerPane.getInstance().refresh()); - } - }, filter); - - PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, new PluginEventListener() { - @Override - public void on(PluginEvent event) { - LocalResourceProvider provider = ExtraDesignClassManager.getInstance().getSingle(LocalResourceProvider.XML_TAG); - if (provider != null) { - FineObjectPool.getInstance().getLocalPool().put(WorkResource.class, provider.createResource()); - FineObjectPool.getInstance().getLocalPool().put(FileNodes.class, provider.createFileNodes()); - FineObjectPool.getInstance().getLocalPool().put(TplOperator.class, provider.createTplOperator()); - UIUtil.invokeLaterIfNeeded(() -> DesignerFrameFileDealerPane.getInstance().refresh()); - } - } - }, filter); } private List otherToolbarStateChangeListeners = new ArrayList<>(); 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 eb191383f9..929519b184 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 @@ -24,6 +24,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.TemplateTreePane; import com.fr.design.fun.DesignerFrameUpButtonProvider; import com.fr.design.fun.MenuHandler; @@ -813,7 +814,7 @@ public abstract class JTemplate> return false; } try { - this.getTarget().export(editingFILE.asOutputStream()); + this.getTarget().export(ResourceManager.getInstance().getOperation().saveTpl(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 b033d229b9..4b388be365 100644 --- a/designer-base/src/main/java/com/fr/file/FileNodeFILE.java +++ b/designer-base/src/main/java/com/fr/file/FileNodeFILE.java @@ -2,6 +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.io.FineEncryptUtils; import com.fr.base.io.XMLEncryptUtils; import com.fr.design.file.NodeAuthProcessor; @@ -22,10 +23,8 @@ import com.fr.workspace.WorkContext; import com.fr.workspace.Workspace; import com.fr.workspace.WorkspaceEvent; import com.fr.workspace.resource.WorkResourceTempRenameStream; -import com.fr.workspace.server.lock.TplOperator; import javax.swing.*; -import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; @@ -379,14 +378,11 @@ public class FileNodeFILE implements FILE { if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { return null; } - InputStream in = new ByteArrayInputStream( - WorkContext.getCurrent().get(TplOperator.class).readAndLockFile( - StableUtils.pathJoin( - ProjectConstants.REPORTLETS_NAME, - envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1) - ) - ) - ); + InputStream in = ResourceManager.getInstance().getOperation().readTpl( + StableUtils.pathJoin( + ProjectConstants.REPORTLETS_NAME, + envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1) + )); return envPath.endsWith(".cpt") || envPath.endsWith(".frm") ? XMLEncryptUtils.decodeInputStream(EncryptUtils.decodeInputStream(FineEncryptUtils.decode(in))) : in;