diff --git a/designer-base/src/main/java/com/fr/design/fun/NewTemplateFileOptionProvider.java b/designer-base/src/main/java/com/fr/design/fun/NewTemplateFileOptionProvider.java new file mode 100644 index 000000000..feec821ba --- /dev/null +++ b/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); +} diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractNewTemplateFileOptionProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractNewTemplateFileOptionProvider.java new file mode 100644 index 000000000..931c4bc65 --- /dev/null +++ b/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(); + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java index 256fee21b..d0b14804a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java @@ -1,8 +1,9 @@ package com.fr.design.gui.itree.filetree; import com.fr.base.FRContext; +import com.fr.base.extension.FileExtension; 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.plugin.context.PluginContext; 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++) { - if (!supportFileType.contains(extensions[i])) { - supportFileType.add(extensions[i]); + if (!supportFileType.contains(extensions[i].getExtension())) { + supportFileType.add(extensions[i].getExtension()); } } } @@ -57,9 +58,9 @@ public class FileNodeConstants { rwl.writeLock().lock(); supportFileType = new ArrayList(); //通过插件扩展的 - Set apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING); - for (App app : apps) { - addAppExtensions(app.defaultExtensions()); + Set providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileOptionProvider.XML_TAG); + for (NewTemplateFileOptionProvider provider : providers) { + addAppExtensions(provider.getSupportedFile().getFileExtensions()); } supportFileType.addAll(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileTreeIcon.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileTreeIcon.java index a453d0a94..68c877fb6 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileTreeIcon.java +++ b/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.design.ExtraDesignClassManager; 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.general.ComparatorUtils; import com.fr.stable.StableUtils; @@ -160,25 +160,31 @@ public class FileTreeIcon { } private static Icon getLocalFileIcon(String path) { - Set providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileProvider.XML_TAG); - for (NewTemplateFileProvider provider : providers) { - if (provider.getLocalFileIcon(path) != null) { - return provider.getLocalFileIcon(path); - } + Icon icon = getExtraIcon(path, false); + if (icon != null) { + return icon; } return FileSystemView.getFileSystemView().getSystemIcon(new File(path)); } - private static Icon getRemoteFileIcon(FileNode node, boolean isShowLock){ - Set providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileProvider.XML_TAG); - for (NewTemplateFileProvider provider : providers) { - if (provider.getRemoteFileIcon(node, isShowLock) != null) { - return provider.getRemoteFileIcon(node, isShowLock); - } + private static Icon getRemoteFileIcon(FileNode node, boolean isShowLock) { + Icon icon = getExtraIcon(node.getName(), isShowLock); + if (icon != null) { + return icon; } return FileTreeIcon.getIcon(FileTreeIcon.getFileType(node.getName()), isShowLock); } + private static Icon getExtraIcon(String path, boolean isShowLock) { + Set 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) { if (fileType == JAVA_FILE) { if (isLocked) { 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 c862b0caa..85bd81a72 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 @@ -27,7 +27,7 @@ import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.TemplateTreePane; import com.fr.design.fun.DesignerFrameUpButtonProvider; 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.gui.frpane.HyperlinkGroupPane; import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; @@ -658,8 +658,8 @@ public abstract class JTemplate> protected boolean saveToNewFile(String oldName){ boolean result = false; - Set providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileProvider.XML_TAG); - for (NewTemplateFileProvider provider : providers) { + Set providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileOptionProvider.XML_TAG); + for (NewTemplateFileOptionProvider provider : providers) { result = result || provider.saveToNewFile(this.editingFILE.getPath(), this); } if(!result && FileExtension.CPT.matchExtension(this.editingFILE.getPath())){ diff --git a/designer-base/src/test/java/com/fr/design/gui/itree/filetree/FileNodeConstantsTest.java b/designer-base/src/test/java/com/fr/design/gui/itree/filetree/FileNodeConstantsTest.java index a12ae6c14..8431344ba 100644 --- a/designer-base/src/test/java/com/fr/design/gui/itree/filetree/FileNodeConstantsTest.java +++ b/designer-base/src/test/java/com/fr/design/gui/itree/filetree/FileNodeConstantsTest.java @@ -1,12 +1,10 @@ package com.fr.design.gui.itree.filetree; 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.mainframe.AbstractAppProvider; -import com.fr.design.mainframe.App; -import com.fr.design.mainframe.JTemplate; -import com.fr.file.FILE; +import com.fr.design.fun.NewTemplateFileOptionProvider; +import com.fr.design.fun.impl.AbstractNewTemplateFileOptionProvider; import com.fr.stable.fun.mark.Mutable; import org.easymock.EasyMock; import org.junit.Assert; @@ -15,7 +13,6 @@ import org.junit.runner.RunWith; import org.powermock.api.easymock.PowerMock; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - import java.util.HashSet; import java.util.Set; @@ -28,9 +25,9 @@ public class FileNodeConstantsTest { @Test public void supportFileTypesTest() { ExtraDesignClassManager extra = mockExtraDesignClassManager(); - Assert.assertEquals(1, extra.getArray(App.MARK_STRING).size()); - App app = (App) extra.getArray(App.MARK_STRING).iterator().next(); - Assert.assertEquals("cptx", app.defaultExtensions()[0]); + Assert.assertEquals(1, extra.getArray(NewTemplateFileOptionProvider.XML_TAG).size()); + NewTemplateFileOptionProvider option = (NewTemplateFileOptionProvider) extra.getArray(NewTemplateFileOptionProvider.XML_TAG).iterator().next(); + Assert.assertEquals(FileExtension.CPTX, option.getSupportedFile().getFileExtensions()[0]); } @Test @@ -46,29 +43,25 @@ public class FileNodeConstantsTest { private ExtraDesignClassManager mockExtraDesignClassManager() { ExtraDesignClassManager extra = EasyMock.mock(ExtraDesignClassManager.class); - Set apps = new HashSet() {{ - add(new MockCptxApp()); + Set options = new HashSet() {{ + 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); return extra; } - private class MockCptxApp extends AbstractAppProvider { - @Override - public String[] defaultExtensions() { - return new String[]{FileExtension.CPTX.getExtension()}; - } + private class MockNewTemplateFileOption extends AbstractNewTemplateFileOptionProvider { @Override - public JTemplate openTemplate(FILE tplFile) { - return null; + public ReportSupportedFileProvider getSupportedFile() { + 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; - } + } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java b/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java index 7822f7d85..4edae780b 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java +++ b/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.file.HistoryTemplateListPane; 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.gui.frpane.HyperlinkGroupPane; import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; @@ -1171,8 +1171,8 @@ public class JWorkBook extends JTemplate { protected void addChooseFILEFilter(FILEChooserPane fileChooser){ super.addChooseFILEFilter(fileChooser); - Set providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileProvider.XML_TAG); - for (NewTemplateFileProvider provider : providers) { + Set providers = ExtraDesignClassManager.getInstance().getArray(NewTemplateFileOptionProvider.XML_TAG); + for (NewTemplateFileOptionProvider provider : providers) { provider.addChooseFileFilter(fileChooser, this.suffix()); } }