Browse Source

REPORT-44644 设计器接口开放

feature/big-screen
hades 4 years ago
parent
commit
b48bf4fb84
  1. 4
      designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java
  2. 67
      designer-base/src/main/java/com/fr/design/file/ResourceManager.java
  3. 62
      designer-base/src/main/java/com/fr/design/file/ResourceOperation.java
  4. 6
      designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java
  5. 48
      designer-base/src/main/java/com/fr/design/file/impl/DefaultResourceOperation.java
  6. 17
      designer-base/src/main/java/com/fr/design/fun/LocalResourceProvider.java
  7. 24
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java
  8. 3
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  9. 16
      designer-base/src/main/java/com/fr/file/FileNodeFILE.java

4
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.log.FineLoggerFactory;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.third.javax.annotation.Nonnull; 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.BorderFactory;
import javax.swing.ButtonModel; import javax.swing.ButtonModel;
@ -707,7 +705,7 @@ public class MutilTempalteTabPane extends JComponent {
// 只有是环境内的文件,才执行释放锁 // 只有是环境内的文件,才执行释放锁
if (file != null && file.isEnvFile()) { if (file != null && file.isEnvFile()) {
// release lock // release lock
WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath()); ResourceManager.getInstance().getOperation().closeTpl(file.getPath());
} }
} }

67
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;
}
}

62
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);
}

6
designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java

@ -194,7 +194,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
@Override @Override
public boolean mkdir(String path) { 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) { if (node instanceof FileNode) {
FileNodeFILE nodeFILE = new FileNodeFILE((FileNode) node); FileNodeFILE nodeFILE = new FileNodeFILE((FileNode) node);
if (nodeFILE.exists()) { if (nodeFILE.exists()) {
if (WorkContext.getCurrent().get(TplOperator.class).delete(nodeFILE.getPath())) { if (ResourceManager.getInstance().getOperation().delete(nodeFILE)) {
HistoryTemplateListCache.getInstance().deleteFile(nodeFILE); HistoryTemplateListCache.getInstance().deleteFile(nodeFILE);
} else { } else {
success = false; success = false;
@ -439,7 +439,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
try { try {
// 接收的是WEB-INF下的路径 // 接收的是WEB-INF下的路径
return WorkContext.getCurrent().get(TplOperator.class).rename(from, to); return ResourceManager.getInstance().getOperation().rename(from, to);
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false; return false;

48
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);
}
}

17
designer-base/src/main/java/com/fr/design/fun/LocalResourceProvider.java

@ -1,9 +1,8 @@
package com.fr.design.fun; package com.fr.design.fun;
import com.fr.design.file.ResourceOperation;
import com.fr.file.filetree.FileNodes; import com.fr.file.filetree.FileNodes;
import com.fr.stable.fun.mark.Immutable; 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; int CURRENT_LEVEL = 1;
/** /**
* eg: FineWorkResource * eg: DefaultResourceOperation
* *
* @return 目录/文件的操作方式 * @return 目录/模板的各种操作
*/ */
WorkResource createResource(); ResourceOperation createResourceOperation();
/** /**
* eg: LocalFileNodes * eg: LocalFileNodes
@ -33,11 +31,4 @@ public interface LocalResourceProvider extends Immutable {
*/ */
FileNodes createFileNodes(); FileNodes createFileNodes();
/**
* eg:LocalTplOperator
*
* 模板操作 关闭/打开等操作
*/
TplOperator createTplOperator();
} }

24
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); 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<FileToolbarStateChangeListener> otherToolbarStateChangeListeners = new ArrayList<>(); private List<FileToolbarStateChangeListener> otherToolbarStateChangeListeners = new ArrayList<>();

3
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.FineJOptionPane;
import com.fr.design.dialog.InformationWarnPane; import com.fr.design.dialog.InformationWarnPane;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.ResourceManager;
import com.fr.design.file.TemplateTreePane; import com.fr.design.file.TemplateTreePane;
import com.fr.design.fun.DesignerFrameUpButtonProvider; import com.fr.design.fun.DesignerFrameUpButtonProvider;
import com.fr.design.fun.MenuHandler; import com.fr.design.fun.MenuHandler;
@ -813,7 +814,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
return false; return false;
} }
try { try {
this.getTarget().export(editingFILE.asOutputStream()); this.getTarget().export(ResourceManager.getInstance().getOperation().saveTpl(editingFILE));
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE);

16
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.BaseUtils;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.file.ResourceManager;
import com.fr.io.FineEncryptUtils; import com.fr.io.FineEncryptUtils;
import com.fr.base.io.XMLEncryptUtils; import com.fr.base.io.XMLEncryptUtils;
import com.fr.design.file.NodeAuthProcessor; import com.fr.design.file.NodeAuthProcessor;
@ -22,10 +23,8 @@ import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace; import com.fr.workspace.Workspace;
import com.fr.workspace.WorkspaceEvent; import com.fr.workspace.WorkspaceEvent;
import com.fr.workspace.resource.WorkResourceTempRenameStream; import com.fr.workspace.resource.WorkResourceTempRenameStream;
import com.fr.workspace.server.lock.TplOperator;
import javax.swing.*; import javax.swing.*;
import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays; import java.util.Arrays;
@ -379,14 +378,11 @@ public class FileNodeFILE implements FILE {
if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
return null; return null;
} }
InputStream in = new ByteArrayInputStream( InputStream in = ResourceManager.getInstance().getOperation().readTpl(
WorkContext.getCurrent().get(TplOperator.class).readAndLockFile( StableUtils.pathJoin(
StableUtils.pathJoin( ProjectConstants.REPORTLETS_NAME,
ProjectConstants.REPORTLETS_NAME, envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1) ));
)
)
);
return envPath.endsWith(".cpt") || envPath.endsWith(".frm") return envPath.endsWith(".cpt") || envPath.endsWith(".frm")
? XMLEncryptUtils.decodeInputStream(EncryptUtils.decodeInputStream(FineEncryptUtils.decode(in))) : in; ? XMLEncryptUtils.decodeInputStream(EncryptUtils.decodeInputStream(FineEncryptUtils.decode(in))) : in;

Loading…
Cancel
Save