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..7b13c94a07 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 @@ -2,7 +2,6 @@ package com.fr.design.file; import com.fr.base.chart.chartdata.CallbackEvent; import com.fr.base.io.BaseBook; -import com.fr.design.DesignModelAdapter; import com.fr.design.DesignerEnvManager; import com.fr.design.base.mode.DesignModeContext; import com.fr.design.data.DesignTableDataManager; @@ -23,7 +22,6 @@ import com.fr.stable.CoreConstants; import com.fr.stable.StringUtils; import com.fr.third.org.apache.commons.io.FilenameUtils; -import javax.swing.SwingUtilities; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Collections; @@ -441,4 +439,5 @@ public class HistoryTemplateListCache implements CallbackEvent { } }); } + } 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..269918448a 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()); + TemplateResourceManager.getResource().closeTemplate(file.getPath()); } } diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateResource.java b/designer-base/src/main/java/com/fr/design/file/TemplateResource.java new file mode 100644 index 0000000000..f394822d6b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/file/TemplateResource.java @@ -0,0 +1,71 @@ +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 TemplateResource { + + /** + * 读取模板 + * @param path + * @return + * @throws Exception + */ + InputStream readTemplate(String path) throws Exception; + + /** + * 保存模板 + * @param file + * @return + * @throws Exception + */ + OutputStream saveTemplate(FILE file) throws Exception; + + /** + * 删除某个目录/某个模板 + * @param file + * @return + */ + boolean delete(FILE file); + + /** + * 关闭模板 + * @param path + * @return + */ + boolean closeTemplate(String path); + + /** + * 重命名模板/目录 + * @param from + * @param to + * @return + */ + boolean rename(String from, String to); + + /** + * 模板/目录是否存在 + * @param path + * @return + */ + boolean exist(String path); + + /** + * 创建目录 + * @param path + * @return + */ + boolean mkdir(String path); + + +} diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateResourceManager.java b/designer-base/src/main/java/com/fr/design/file/TemplateResourceManager.java new file mode 100644 index 0000000000..384b1a3e1e --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/file/TemplateResourceManager.java @@ -0,0 +1,66 @@ +package com.fr.design.file; + +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.file.impl.DefaultTemplateResource; +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 TemplateResourceManager { + + private static final TemplateResource DEFAULT_OPERATION = new DefaultTemplateResource(); + + private static TemplateResource OPERATION = DEFAULT_OPERATION; + + static { + 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 DefaultTemplateResource()); + 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); + } + + private static void registerOperation(TemplateResource operation) { + OPERATION = operation; + } + + public static TemplateResource getResource() { + if (OPERATION == null) { + return DEFAULT_OPERATION; + } + return OPERATION; + } + +} 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 5041cc34a3..0fc3ca7281 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 @@ -4,7 +4,9 @@ package com.fr.design.file; import com.fr.base.FRContext; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.fun.TemplateTreeDefineProcessor; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; @@ -23,12 +25,11 @@ 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; +import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; -import javax.swing.UIManager; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; @@ -87,6 +88,16 @@ public class TemplateTreePane extends JPanel implements FileOperations { } } + @Override + public void mouseClicked(MouseEvent e) { + if (SwingUtilities.isRightMouseButton(e)) { + TemplateTreeDefineProcessor processor = ExtraDesignClassManager.getInstance().getSingle(TemplateTreeDefineProcessor.XML_TAG); + if (processor != null) { + processor.rightClickAction(e); + } + } + } + @Override public void mouseReleased(MouseEvent e) { if (toolBarStateChangeListener != null) { @@ -182,7 +193,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { @Override public boolean mkdir(String path) { - return WorkContext.getWorkResource().createDirectory(path); + return TemplateResourceManager.getResource().mkdir(path); } /** @@ -325,7 +336,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 (TemplateResourceManager.getResource().delete(nodeFILE)) { HistoryTemplateListCache.getInstance().deleteFile(nodeFILE); } else { success = false; @@ -427,7 +438,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { try { // 接收的是WEB-INF下的路径 - return WorkContext.getCurrent().get(TplOperator.class).rename(from, to); + return TemplateResourceManager.getResource().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/AbstractTemplateResource.java b/designer-base/src/main/java/com/fr/design/file/impl/AbstractTemplateResource.java new file mode 100644 index 0000000000..cb76792a13 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/file/impl/AbstractTemplateResource.java @@ -0,0 +1,19 @@ +package com.fr.design.file.impl; + + +import com.fr.design.file.TemplateResource; +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 abstract class AbstractTemplateResource implements TemplateResource { + +} diff --git a/designer-base/src/main/java/com/fr/design/file/impl/DefaultTemplateResource.java b/designer-base/src/main/java/com/fr/design/file/impl/DefaultTemplateResource.java new file mode 100644 index 0000000000..8c54cc8cc3 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/file/impl/DefaultTemplateResource.java @@ -0,0 +1,52 @@ +package com.fr.design.file.impl; + +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 DefaultTemplateResource extends AbstractTemplateResource { + + @Override + public InputStream readTemplate(String path) throws Exception { + return new ByteArrayInputStream(WorkContext.getCurrent().get(TplOperator.class).readAndLockFile(path)); + } + + @Override + public OutputStream saveTemplate(FILE file) throws Exception { + return file.asOutputStream(); + } + + @Override + public boolean closeTemplate(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 exist(String path) { + return WorkContext.getWorkResource().exist(path); + } + + @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 new file mode 100644 index 0000000000..56a98a2359 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/LocalResourceProvider.java @@ -0,0 +1,34 @@ +package com.fr.design.fun; + +import com.fr.design.file.TemplateResource; +import com.fr.file.filetree.FileNodes; +import com.fr.stable.fun.mark.Immutable; + +/** + * 本地资源操作插件接口 + * + * @author hades + * @version 10.0 + * Created by hades on 2020/12/22 + */ +public interface LocalResourceProvider extends Immutable { + + String XML_TAG = "LocalResourceProvider"; + + int CURRENT_LEVEL = 1; + + /** + * eg: DefaultResourceOperation + * + * @return 目录/模板的各种操作 + */ + TemplateResource createResourceOperation(); + + /** + * eg: LocalFileNodes + * + * @return 构建目录树的方式 + */ + FileNodes createFileNodes(); + +} diff --git a/designer-base/src/main/java/com/fr/design/fun/TemplateTreeDefineProcessor.java b/designer-base/src/main/java/com/fr/design/fun/TemplateTreeDefineProcessor.java new file mode 100644 index 0000000000..cfa5bcecbe --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/TemplateTreeDefineProcessor.java @@ -0,0 +1,19 @@ +package com.fr.design.fun; + +import com.fr.stable.fun.mark.Immutable; +import java.awt.event.MouseEvent; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/12/14 + */ +public interface TemplateTreeDefineProcessor extends Immutable { + + String XML_TAG = "TemplateTreeDefineProcessor"; + + int CURRENT_LEVEL = 1; + + void rightClickAction(MouseEvent mouseEvent); + +} diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractLocalResourceProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractLocalResourceProvider.java new file mode 100644 index 0000000000..ebefc2ba69 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractLocalResourceProvider.java @@ -0,0 +1,23 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.LocalResourceProvider; +import com.fr.stable.fun.mark.API; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/12/22 + */ +@API(level = LocalResourceProvider.CURRENT_LEVEL) +public abstract class AbstractLocalResourceProvider implements LocalResourceProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public int layerIndex() { + return DEFAULT_LAYER_INDEX; + } +} diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractTemplateTreeDefineProcessor.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractTemplateTreeDefineProcessor.java new file mode 100644 index 0000000000..eba101aada --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractTemplateTreeDefineProcessor.java @@ -0,0 +1,24 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.TemplateTreeDefineProcessor; +import com.fr.stable.fun.mark.API; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/12/21 + */ +@API(level = TemplateTreeDefineProcessor.CURRENT_LEVEL) +public abstract class AbstractTemplateTreeDefineProcessor implements TemplateTreeDefineProcessor { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public int layerIndex() { + return DEFAULT_LAYER_INDEX; + } + +} 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 4f59032dca..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 @@ -17,7 +17,6 @@ import com.fr.design.file.FileToolbarStateChangeListener; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.MutilTempalteTabPane; -import com.fr.design.file.SaveSomeTemplatePane; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; @@ -58,7 +57,6 @@ 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 eb191383f9..5cfd7a13d4 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,6 +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.TemplateResourceManager; import com.fr.design.file.TemplateTreePane; import com.fr.design.fun.DesignerFrameUpButtonProvider; import com.fr.design.fun.MenuHandler; @@ -813,7 +813,7 @@ public abstract class JTemplate> return false; } try { - this.getTarget().export(editingFILE.asOutputStream()); + this.getTarget().export(TemplateResourceManager.getResource().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 b033d229b9..d096faf8a7 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.TemplateResourceManager; 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; @@ -324,7 +323,7 @@ public class FileNodeFILE implements FILE { } try { - return WorkContext.getWorkResource().exist(node.getEnvPath()); + return TemplateResourceManager.getResource().exist(node.getEnvPath()); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); return false; @@ -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 = TemplateResourceManager.getResource().readTemplate( + 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;