forked from fanruan/design
hades
4 years ago
9 changed files with 193 additions and 54 deletions
@ -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; |
||||
} |
||||
|
||||
} |
@ -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); |
||||
|
||||
|
||||
} |
@ -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); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue