rinoux
2 years ago
3 changed files with 67 additions and 12 deletions
@ -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<Class<? extends TableData>, 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<PluginContext> listener = new Listener<PluginContext>() { |
||||||
|
@Override |
||||||
|
public void on(Event event, PluginContext param) { |
||||||
|
TABLE_DATA_ICON_PATHS.clear(); |
||||||
|
} |
||||||
|
}; |
||||||
|
Filter<PluginContext> 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<? extends TableData> 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); |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue