Browse Source

接口调整

feature/big-screen
kerry 5 years ago
parent
commit
987c17b553
  1. 47
      designer-base/src/main/java/com/fr/design/fun/NewTemplateFileOptionProvider.java
  2. 45
      designer-base/src/main/java/com/fr/design/fun/impl/AbstractNewTemplateFileOptionProvider.java
  3. 15
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java
  4. 30
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileTreeIcon.java
  5. 6
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  6. 39
      designer-base/src/test/java/com/fr/design/gui/itree/filetree/FileNodeConstantsTest.java
  7. 6
      designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java

47
designer-base/src/main/java/com/fr/design/fun/NewTemplateFileOptionProvider.java

@ -0,0 +1,47 @@
package com.fr.design.fun;
import com.fr.decision.extension.report.ReportSupportedFileProvider;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILEChooserPane;
import com.fr.stable.fun.mark.Mutable;
import javax.swing.Icon;
/**
* Created by kerry on 2019-10-11
*/
public interface NewTemplateFileOptionProvider extends Mutable {
int CURRENT_LEVEL = 1;
String XML_TAG = "NewTemplateFileOptionProvider";
/**
* 向文件选择器中添加指定文件类型过滤器
* @param fileChooser 文件选择器
* @param suffix 文件后缀
*/
void addChooseFileFilter(FILEChooserPane fileChooser, String suffix);
/**
* 获取对应的新增的支持文件类型
* @return ReportTemplateFileProvider
*/
ReportSupportedFileProvider getSupportedFile();
/**
* 获取文件关联的icon
* @param path 文件路径
* @param isShowLock 是否显示被锁住
* @return 对应的图标
*/
Icon getFileIcon(String path,boolean isShowLock);
/**
* 保存为新类型文件
* @param targetPath 目标路径
* @param jTemplate 模板对象
*/
boolean saveToNewFile(String targetPath, JTemplate jTemplate);
}

45
designer-base/src/main/java/com/fr/design/fun/impl/AbstractNewTemplateFileOptionProvider.java

@ -0,0 +1,45 @@
package com.fr.design.fun.impl;
import com.fr.decision.extension.report.ReportSupportedFileProvider;
import com.fr.design.fun.NewTemplateFileOptionProvider;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILEChooserPane;
import com.fr.stable.fun.mark.API;
import javax.swing.Icon;
/**
* Created by kerry on 2019-10-14
*/
@API(level = NewTemplateFileOptionProvider.CURRENT_LEVEL)
public abstract class AbstractNewTemplateFileOptionProvider implements NewTemplateFileOptionProvider {
@Override
public void addChooseFileFilter(FILEChooserPane fileChooser, String suffix) {
}
@Override
public ReportSupportedFileProvider getSupportedFile() {
return null;
}
@Override
public Icon getFileIcon(String path, boolean isShowLock) {
return null;
}
@Override
public boolean saveToNewFile(String targetPath, JTemplate jTemplate) {
return false;
}
@Override
public int currentAPILevel() {
return CURRENT_LEVEL;
}
@Override
public String mark4Provider() {
return getClass().getName();
}
}

15
designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java

@ -1,8 +1,9 @@
package com.fr.design.gui.itree.filetree; package com.fr.design.gui.itree.filetree;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.base.extension.FileExtension;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.mainframe.App; import com.fr.design.fun.NewTemplateFileOptionProvider;
import com.fr.general.GeneralContext; import com.fr.general.GeneralContext;
import com.fr.plugin.context.PluginContext; import com.fr.plugin.context.PluginContext;
import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.injectable.PluginModule;
@ -44,10 +45,10 @@ public class FileNodeConstants {
}); });
} }
private static void addAppExtensions(String[] extensions) { private static void addAppExtensions(FileExtension[] extensions) {
for (int i = 0, size = extensions.length; i < size; i++) { for (int i = 0, size = extensions.length; i < size; i++) {
if (!supportFileType.contains(extensions[i])) { if (!supportFileType.contains(extensions[i].getExtension())) {
supportFileType.add(extensions[i]); supportFileType.add(extensions[i].getExtension());
} }
} }
} }
@ -57,9 +58,9 @@ public class FileNodeConstants {
rwl.writeLock().lock(); rwl.writeLock().lock();
supportFileType = new ArrayList<String>(); supportFileType = new ArrayList<String>();
//通过插件扩展的 //通过插件扩展的
Set<App> apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING); Set<NewTemplateFileOptionProvider> providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileOptionProvider.XML_TAG);
for (App app : apps) { for (NewTemplateFileOptionProvider provider : providers) {
addAppExtensions(app.defaultExtensions()); addAppExtensions(provider.getSupportedFile().getFileExtensions());
} }
supportFileType.addAll(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); supportFileType.addAll(Arrays.asList(FRContext.getFileNodes().getSupportedTypes()));

30
designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileTreeIcon.java

@ -3,7 +3,7 @@ package com.fr.design.gui.itree.filetree;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.icon.LockIcon; import com.fr.design.icon.LockIcon;
import com.fr.design.fun.NewTemplateFileProvider; import com.fr.design.fun.NewTemplateFileOptionProvider;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
@ -160,25 +160,31 @@ public class FileTreeIcon {
} }
private static Icon getLocalFileIcon(String path) { private static Icon getLocalFileIcon(String path) {
Set<NewTemplateFileProvider> providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileProvider.XML_TAG); Icon icon = getExtraIcon(path, false);
for (NewTemplateFileProvider provider : providers) { if (icon != null) {
if (provider.getLocalFileIcon(path) != null) { return icon;
return provider.getLocalFileIcon(path);
}
} }
return FileSystemView.getFileSystemView().getSystemIcon(new File(path)); return FileSystemView.getFileSystemView().getSystemIcon(new File(path));
} }
private static Icon getRemoteFileIcon(FileNode node, boolean isShowLock){ private static Icon getRemoteFileIcon(FileNode node, boolean isShowLock) {
Set<NewTemplateFileProvider> providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileProvider.XML_TAG); Icon icon = getExtraIcon(node.getName(), isShowLock);
for (NewTemplateFileProvider provider : providers) { if (icon != null) {
if (provider.getRemoteFileIcon(node, isShowLock) != null) { return icon;
return provider.getRemoteFileIcon(node, isShowLock);
}
} }
return FileTreeIcon.getIcon(FileTreeIcon.getFileType(node.getName()), isShowLock); return FileTreeIcon.getIcon(FileTreeIcon.getFileType(node.getName()), isShowLock);
} }
private static Icon getExtraIcon(String path, boolean isShowLock) {
Set<NewTemplateFileOptionProvider> providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileOptionProvider.XML_TAG);
for (NewTemplateFileOptionProvider provider : providers) {
if (provider.getFileIcon(path, isShowLock) != null) {
return provider.getFileIcon(path, isShowLock);
}
}
return null;
}
private static Icon getIcon(int fileType, boolean isLocked) { private static Icon getIcon(int fileType, boolean isLocked) {
if (fileType == JAVA_FILE) { if (fileType == JAVA_FILE) {
if (isLocked) { if (isLocked) {

6
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -27,7 +27,7 @@ import com.fr.design.file.HistoryTemplateListPane;
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;
import com.fr.design.fun.NewTemplateFileProvider; import com.fr.design.fun.NewTemplateFileOptionProvider;
import com.fr.design.fun.PreviewProvider; import com.fr.design.fun.PreviewProvider;
import com.fr.design.gui.frpane.HyperlinkGroupPane; import com.fr.design.gui.frpane.HyperlinkGroupPane;
import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider;
@ -658,8 +658,8 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
protected boolean saveToNewFile(String oldName){ protected boolean saveToNewFile(String oldName){
boolean result = false; boolean result = false;
Set<NewTemplateFileProvider> providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileProvider.XML_TAG); Set<NewTemplateFileOptionProvider> providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileOptionProvider.XML_TAG);
for (NewTemplateFileProvider provider : providers) { for (NewTemplateFileOptionProvider provider : providers) {
result = result || provider.saveToNewFile(this.editingFILE.getPath(), this); result = result || provider.saveToNewFile(this.editingFILE.getPath(), this);
} }
if(!result && FileExtension.CPT.matchExtension(this.editingFILE.getPath())){ if(!result && FileExtension.CPT.matchExtension(this.editingFILE.getPath())){

39
designer-base/src/test/java/com/fr/design/gui/itree/filetree/FileNodeConstantsTest.java

@ -1,12 +1,10 @@
package com.fr.design.gui.itree.filetree; package com.fr.design.gui.itree.filetree;
import com.fr.base.extension.FileExtension; import com.fr.base.extension.FileExtension;
import com.fr.base.io.BaseBook; import com.fr.decision.extension.report.ReportSupportedFileProvider;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.mainframe.AbstractAppProvider; import com.fr.design.fun.NewTemplateFileOptionProvider;
import com.fr.design.mainframe.App; import com.fr.design.fun.impl.AbstractNewTemplateFileOptionProvider;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE;
import com.fr.stable.fun.mark.Mutable; import com.fr.stable.fun.mark.Mutable;
import org.easymock.EasyMock; import org.easymock.EasyMock;
import org.junit.Assert; import org.junit.Assert;
@ -15,7 +13,6 @@ import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock; import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -28,9 +25,9 @@ public class FileNodeConstantsTest {
@Test @Test
public void supportFileTypesTest() { public void supportFileTypesTest() {
ExtraDesignClassManager extra = mockExtraDesignClassManager(); ExtraDesignClassManager extra = mockExtraDesignClassManager();
Assert.assertEquals(1, extra.getArray(App.MARK_STRING).size()); Assert.assertEquals(1, extra.getArray(NewTemplateFileOptionProvider.XML_TAG).size());
App app = (App) extra.getArray(App.MARK_STRING).iterator().next(); NewTemplateFileOptionProvider option = (NewTemplateFileOptionProvider) extra.getArray(NewTemplateFileOptionProvider.XML_TAG).iterator().next();
Assert.assertEquals("cptx", app.defaultExtensions()[0]); Assert.assertEquals(FileExtension.CPTX, option.getSupportedFile().getFileExtensions()[0]);
} }
@Test @Test
@ -46,29 +43,25 @@ public class FileNodeConstantsTest {
private ExtraDesignClassManager mockExtraDesignClassManager() { private ExtraDesignClassManager mockExtraDesignClassManager() {
ExtraDesignClassManager extra = EasyMock.mock(ExtraDesignClassManager.class); ExtraDesignClassManager extra = EasyMock.mock(ExtraDesignClassManager.class);
Set<Mutable> apps = new HashSet<Mutable>() {{ Set<Mutable> options = new HashSet<Mutable>() {{
add(new MockCptxApp()); add(new MockNewTemplateFileOption());
}}; }};
EasyMock.expect(extra.getArray(App.MARK_STRING)).andReturn(apps).anyTimes(); EasyMock.expect(extra.getArray(NewTemplateFileOptionProvider.XML_TAG)).andReturn(options).anyTimes();
EasyMock.replay(extra); EasyMock.replay(extra);
return extra; return extra;
} }
private class MockCptxApp extends AbstractAppProvider { private class MockNewTemplateFileOption extends AbstractNewTemplateFileOptionProvider {
@Override
public String[] defaultExtensions() {
return new String[]{FileExtension.CPTX.getExtension()};
}
@Override @Override
public JTemplate openTemplate(FILE tplFile) { public ReportSupportedFileProvider getSupportedFile() {
return null; ReportSupportedFileProvider supportedFileProvider = EasyMock.mock(ReportSupportedFileProvider.class);
EasyMock.expect(supportedFileProvider.getFileExtensions()).andReturn(new FileExtension[]{FileExtension.CPTX}).anyTimes();
EasyMock.replay(supportedFileProvider);
return supportedFileProvider;
} }
@Override
public BaseBook asIOFile(FILE tplFile) {
return null;
}
} }
} }

6
designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java

@ -34,7 +34,7 @@ import com.fr.design.event.TargetModifiedEvent;
import com.fr.design.event.TargetModifiedListener; import com.fr.design.event.TargetModifiedListener;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MutilTempalteTabPane; import com.fr.design.file.MutilTempalteTabPane;
import com.fr.design.fun.NewTemplateFileProvider; import com.fr.design.fun.NewTemplateFileOptionProvider;
import com.fr.design.fun.PreviewProvider; import com.fr.design.fun.PreviewProvider;
import com.fr.design.gui.frpane.HyperlinkGroupPane; import com.fr.design.gui.frpane.HyperlinkGroupPane;
import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider;
@ -1171,8 +1171,8 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
protected void addChooseFILEFilter(FILEChooserPane fileChooser){ protected void addChooseFILEFilter(FILEChooserPane fileChooser){
super.addChooseFILEFilter(fileChooser); super.addChooseFILEFilter(fileChooser);
Set<NewTemplateFileProvider> providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileProvider.XML_TAG); Set<NewTemplateFileOptionProvider> providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileOptionProvider.XML_TAG);
for (NewTemplateFileProvider provider : providers) { for (NewTemplateFileOptionProvider provider : providers) {
provider.addChooseFileFilter(fileChooser, this.suffix()); provider.addChooseFileFilter(fileChooser, this.suffix());
} }
} }

Loading…
Cancel
Save