forked from fanruan/design
Browse Source
Merge in DESIGN/design from ~HADES/design:REPORT-44644 to release/10.0 * commit 'd9a770f847fa6d88d350f870080fec6904f2e8d5': REPORT-44644 设计器接口开放 fix实现层级 REPORT-44644 fix无用import REPORT-44644 设计器接口开发 fix REPORT-44644 添加判断是否存在接口 REPORT-44644 fix调整名称 REPORT-44644 设计器接口开放 REPORT-44644 设计器接口开放feature/big-screen
ju|剧浩宇
4 years ago
14 changed files with 335 additions and 25 deletions
@ -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); |
||||
|
||||
|
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
@ -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 { |
||||
|
||||
} |
@ -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); |
||||
} |
||||
|
||||
} |
@ -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(); |
||||
|
||||
} |
@ -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); |
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue