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 f9870e3c3..88a463440 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 @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; /** * Created by alex sung on 2019/7/23. @@ -21,8 +23,10 @@ import java.util.Set; public class FileNodeConstants { private static List supportFileType; + private static ReadWriteLock rwl = new ReentrantReadWriteLock(); - private FileNodeConstants(){} + private FileNodeConstants() { + } static { initSupportedTypes(); @@ -30,12 +34,7 @@ public class FileNodeConstants { GeneralContext.listenPluginRunningChanged(new PluginEventListener() { @Override public void on(PluginEvent pluginEvent) { - supportFileType = new ArrayList(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); - //通过插件扩展的 - Set apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING); - for (App app : apps) { - addAppExtensions(app.defaultExtensions()); - } + initSupportedTypes(); } }, new PluginFilter() { @Override @@ -54,15 +53,30 @@ public class FileNodeConstants { } private static void initSupportedTypes() { - supportFileType = new ArrayList(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); - //通过插件扩展的 - Set apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING); - for (App app : apps) { - addAppExtensions(app.defaultExtensions()); + try { + rwl.writeLock().lock(); + supportFileType = new ArrayList(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); + //通过插件扩展的 + Set apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING); + for (App app : apps) { + addAppExtensions(app.defaultExtensions()); + } + } catch (Exception ignored) { + //ignored + } finally { + rwl.writeLock().unlock(); } } public static String[] getSupportFileTypes() { - return supportFileType.toArray(new String[0]); + try { + rwl.readLock().lock(); + return supportFileType.toArray(new String[0]); + } catch (Exception ignored) { + //ignored + } finally { + rwl.readLock().unlock(); + } + return null; } }