diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java index 610aac3c58..b527503799 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java @@ -68,12 +68,7 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { @Override public Icon getIcon() { - for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { - if (creator.createObject().getClass().isAssignableFrom(this.tableData.getClass())) { - return IOUtils.readIcon(creator.getIconPath()); - } - } - return IOUtils.readIcon("/com/fr/design/images/data/multi.png"); + return MultiResultTableDataWrapperHelper.getIcon(this.tableData.getClass()); } private void createResult(boolean needLoadingBar) { diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java index 58521283e6..662b47ba8c 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java @@ -10,13 +10,21 @@ import com.fr.design.data.datapane.TableDataCreatorProducer; import com.fr.design.data.datapane.TableDataNameObjectCreator; import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.fun.ServerTableDataDefineProvider; +import com.fr.design.fun.TableDataDefineProvider; import com.fr.design.gui.iprogressbar.AutoProgressBar; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.observer.PluginEventType; +import com.fr.stable.Filter; import javax.swing.Icon; import javax.swing.JFrame; @@ -24,7 +32,9 @@ import javax.swing.SwingWorker; import java.awt.Component; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.CancellationException; /** @@ -163,12 +173,7 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { @Override public Icon getIcon() { - for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { - if (creator.createObject().getClass().isAssignableFrom(this.tableData.getClass())) { - return IOUtils.readIcon(creator.getIconPath()); - } - } - return IOUtils.readIcon("/com/fr/design/images/data/multi.png"); + return MultiResultTableDataWrapperHelper.getIcon(this.tableData.getClass()); } /** @@ -303,6 +308,7 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { /** * 获取当前节点所属可编辑的数据集名称 + * * @return */ public String getMultiResultTableDataName() { diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapperHelper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapperHelper.java new file mode 100644 index 0000000000..91ca35d7fb --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapperHelper.java @@ -0,0 +1,54 @@ +package com.fr.design.data.tabledata.wrapper; + +import com.fr.base.TableData; +import com.fr.design.data.datapane.TableDataCreatorProducer; +import com.fr.design.data.datapane.TableDataNameObjectCreator; +import com.fr.design.fun.ServerTableDataDefineProvider; +import com.fr.design.fun.TableDataDefineProvider; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.general.IOUtils; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.observer.PluginEventType; +import com.fr.stable.Filter; +import org.jetbrains.annotations.NotNull; + +import javax.swing.Icon; +import java.util.HashMap; +import java.util.Map; + +/** + * @author rinoux + * @version 11.0 + * Created by rinoux on 2022/9/7 + */ +class MultiResultTableDataWrapperHelper { + private static final Map, Icon> TABLE_DATA_ICON_PATHS = new HashMap<>(); + private static final String DEFAULT_MULTI_RESULT_TD_ICON = "/com/fr/design/images/data/multi.png"; + + + static { + Listener listener = new Listener() { + @Override + public void on(Event event, PluginContext param) { + TABLE_DATA_ICON_PATHS.clear(); + } + }; + Filter filter = pluginContext -> pluginContext.contain(TableDataDefineProvider.XML_TAG) || pluginContext.contain(ServerTableDataDefineProvider.XML_TAG); + EventDispatcher.listen(PluginEventType.AfterRun, listener, filter); + EventDispatcher.listen(PluginEventType.BeforeStop, listener, filter); + } + + + public static @NotNull Icon getIcon(@NotNull Class tableDataClass) { + return TABLE_DATA_ICON_PATHS.computeIfAbsent(tableDataClass, cls -> { + for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { + if (creator.createObject().getClass().isAssignableFrom(tableDataClass)) { + return IOUtils.readIcon(creator.getIconPath()); + } + } + return IOUtils.readIcon(DEFAULT_MULTI_RESULT_TD_ICON); + }); + } +}