From 5ee83b07ec87dbfea550a1fddaf1c20301989a7d Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Thu, 25 Jul 2019 09:27:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/itree/filetree/FileNodeConstants.java | 27 +++++++++++++++++++ .../gui/itree/filetree/TemplateFileTree.java | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java 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 new file mode 100644 index 0000000000..3bde026a25 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/FileNodeConstants.java @@ -0,0 +1,27 @@ +package com.fr.design.gui.itree.filetree; + +import com.fr.base.FRContext; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.mainframe.App; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +/** + * Created by alex sung on 2019/7/23. + */ +public class FileNodeConstants { + public static String[] SUPPORT_FILE_TYPES; + + static { + List supportFileType = new ArrayList<>(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); + //通过插件扩展的 + Set apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING); + for(App app: apps){ + supportFileType.addAll(Arrays.asList(app.defaultExtensions())); + } + SUPPORT_FILE_TYPES = supportFileType.toArray(new String[0]); + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java index 51af636aa2..b722cd44a4 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java @@ -228,7 +228,7 @@ public class TemplateFileTree extends EnvFileTree { if (fileNodes == null) { fileNodes = new FileNode[0]; } - Arrays.sort(fileNodes, new FileNodeComparator(FRContext.getFileNodes().getSupportedTypes())); + Arrays.sort(fileNodes, new FileNodeComparator(FileNodeConstants.SUPPORT_FILE_TYPES)); return fileNodes; } From 47d7d62edea64d275cadfed132610f73365dba25 Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Thu, 25 Jul 2019 13:55:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../itree/filetree/FileNodeConstantsTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 designer-base/src/test/java/com/fr/design/gui/itree/filetree/FileNodeConstantsTest.java 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 new file mode 100644 index 0000000000..67f0824567 --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/gui/itree/filetree/FileNodeConstantsTest.java @@ -0,0 +1,51 @@ +package com.fr.design.gui.itree.filetree; + +import com.fr.base.extension.FileExtension; +import com.fr.base.io.BaseBook; +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.stable.fun.mark.Mutable; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +/** + * Created by alex sung on 2019/7/25. + */ +public class FileNodeConstantsTest { + @Test + public void supportFileTypesTest(){ + ExtraDesignClassManager extra = EasyMock.mock(ExtraDesignClassManager.class); + Set apps = new HashSet(){{add(new MockCptxApp());}}; + EasyMock.expect(extra.getArray(App.MARK_STRING)).andReturn(apps).anyTimes(); + EasyMock.replay(extra); + + 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]); + } + + private class MockCptxApp extends AbstractAppProvider{ + @Override + public String[] defaultExtensions() { + return new String[] {FileExtension.CPTX.getExtension()}; + } + + @Override + public JTemplate openTemplate(FILE tplFile) { + return null; + } + + @Override + public BaseBook asIOFile(FILE tplFile) { + return null; + } + } + +}