From 60303b727245db6017172cc80dfdb8f6f762531e Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Mon, 29 Jul 2019 19:53:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=AF=BB=E5=86=99=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/itree/filetree/FileNodeConstants.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) 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 f9870e3c35..88a4634403 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; } }