juhaoyu 7 years ago
parent
commit
5d264469f7
  1. 174
      designer_base/src/com/fr/design/ExtraDesignClassManager.java
  2. 374
      designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java

174
designer_base/src/com/fr/design/ExtraDesignClassManager.java

@ -9,18 +9,18 @@ import com.fr.design.data.datapane.TableDataNameObjectCreator;
import com.fr.design.fun.*; import com.fr.design.fun.*;
import com.fr.design.gui.core.WidgetOption; import com.fr.design.gui.core.WidgetOption;
import com.fr.design.gui.core.WidgetOptionFactory; import com.fr.design.gui.core.WidgetOptionFactory;
import com.fr.design.menu.ShortCut;
import com.fr.design.widget.Appearance; import com.fr.design.widget.Appearance;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.GeneralContext;
import com.fr.general.GeneralUtils; import com.fr.general.GeneralUtils;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.plugin.ExtraXMLFileManager; import com.fr.plugin.AbstractExtraClassManager;
import com.fr.stable.EnvChangedListener; import com.fr.plugin.injectable.CompatibleInjectionContainer;
import com.fr.plugin.injectable.PluginModule;
import com.fr.plugin.injectable.PluginSingleInjection;
import com.fr.stable.bridge.StableFactory;
import com.fr.stable.plugin.ExtraDesignClassManagerProvider; import com.fr.stable.plugin.ExtraDesignClassManagerProvider;
import com.fr.stable.plugin.PluginSimplify;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import java.util.*; import java.util.*;
@ -29,42 +29,25 @@ import java.util.*;
* @since : 8.0 * @since : 8.0
* 用于设计器扩展的管理类 * 用于设计器扩展的管理类
*/ */
public class ExtraDesignClassManager extends ExtraXMLFileManager implements ExtraDesignClassManagerProvider { public class ExtraDesignClassManager extends AbstractExtraClassManager implements ExtraDesignClassManagerProvider {
private static final String XML_TAG = "ExtraDesignClassManager"; private static ExtraDesignClassManager classManager = new ExtraDesignClassManager();
private static ExtraDesignClassManager classManager; private CompatibleInjectionContainer<ShortCut> shortCuts = new CompatibleInjectionContainer<>();
public synchronized static ExtraDesignClassManager getInstance() { public synchronized static ExtraDesignClassManager getInstance() {
if (classManager == null) {
classManager = new ExtraDesignClassManager();
classManager.readXMLFile();
}
return classManager; return classManager;
} }
static { static {
GeneralContext.addEnvChangedListener(new EnvChangedListener() { StableFactory.registerMarkedObject(PluginModule.EXTRA_DESIGN.getAgentName(), classManager);
public void envChanged() {
ExtraDesignClassManager.envChanged();
}
});
} }
private synchronized static void envChanged() {
classManager = null;
}
public TableDataNameObjectCreator[] getReportTableDataCreators() { public TableDataNameObjectCreator[] getReportTableDataCreators() {
return getKindsOfTableDataCreators(TableDataDefineProvider.XML_TAG); return getKindsOfTableDataCreators(TableDataDefineProvider.XML_TAG);
} }
/** /**
* 添加serverTDCreators * 添加serverTDCreators
* *
@ -73,7 +56,7 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
public TableDataNameObjectCreator[] getServerTableDataCreators() { public TableDataNameObjectCreator[] getServerTableDataCreators() {
return getKindsOfTableDataCreators(ServerTableDataDefineProvider.XML_TAG); return getKindsOfTableDataCreators(ServerTableDataDefineProvider.XML_TAG);
} }
private TableDataNameObjectCreator[] getKindsOfTableDataCreators(String tag) { private TableDataNameObjectCreator[] getKindsOfTableDataCreators(String tag) {
Set<TableDataDefineProvider> set = getArray(tag); Set<TableDataDefineProvider> set = getArray(tag);
if (set.isEmpty()) { if (set.isEmpty()) {
@ -82,19 +65,19 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
List<TableDataNameObjectCreator> creators = new ArrayList<>(); List<TableDataNameObjectCreator> creators = new ArrayList<>();
for (TableDataDefineProvider provider : set) { for (TableDataDefineProvider provider : set) {
TableDataNameObjectCreator creator = new TableDataNameObjectCreator( TableDataNameObjectCreator creator = new TableDataNameObjectCreator(
provider.nameForTableData(), provider.nameForTableData(),
provider.prefixForTableData(), provider.prefixForTableData(),
provider.iconPathForTableData(), provider.iconPathForTableData(),
provider.classForTableData(), provider.classForTableData(),
provider.classForInitTableData(), provider.classForInitTableData(),
provider.appearanceForTableData() provider.appearanceForTableData()
); );
creators.add(creator); creators.add(creator);
} }
return creators.toArray(new TableDataNameObjectCreator[creators.size()]); return creators.toArray(new TableDataNameObjectCreator[creators.size()]);
} }
public Map<Class<? extends Widget>, Class<?>> getParameterWidgetOptionsMap() { public Map<Class<? extends Widget>, Class<?>> getParameterWidgetOptionsMap() {
Map<Class<? extends Widget>, Class<?>> map = new HashMap<>(); Map<Class<? extends Widget>, Class<?>> map = new HashMap<>();
Set<ParameterWidgetOptionProvider> set = getArray(ParameterWidgetOptionProvider.XML_TAG); Set<ParameterWidgetOptionProvider> set = getArray(ParameterWidgetOptionProvider.XML_TAG);
@ -103,7 +86,7 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
} }
return map; return map;
} }
public WidgetOption[] getParameterWidgetOptions() { public WidgetOption[] getParameterWidgetOptions() {
Set<ParameterWidgetOptionProvider> set = getArray(ParameterWidgetOptionProvider.XML_TAG); Set<ParameterWidgetOptionProvider> set = getArray(ParameterWidgetOptionProvider.XML_TAG);
if (set.isEmpty()) { if (set.isEmpty()) {
@ -112,16 +95,16 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
Set<WidgetOption> result = new HashSet<>(); Set<WidgetOption> result = new HashSet<>();
for (ParameterWidgetOptionProvider provider : set) { for (ParameterWidgetOptionProvider provider : set) {
WidgetOption option = WidgetOptionFactory.createByWidgetClass( WidgetOption option = WidgetOptionFactory.createByWidgetClass(
provider.nameForWidget(), provider.nameForWidget(),
IOUtils.readIcon(provider.iconPathForWidget()), IOUtils.readIcon(provider.iconPathForWidget()),
provider.classForWidget() provider.classForWidget()
); );
result.add(option); result.add(option);
} }
return result.toArray(new WidgetOption[result.size()]); return result.toArray(new WidgetOption[result.size()]);
} }
public WidgetOption[] getWebWidgetOptions() { public WidgetOption[] getWebWidgetOptions() {
Set<ToolbarItemProvider> set = getArray(ToolbarItemProvider.XML_TAG); Set<ToolbarItemProvider> set = getArray(ToolbarItemProvider.XML_TAG);
if (set.isEmpty()) { if (set.isEmpty()) {
@ -130,17 +113,17 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
List<WidgetOption> list = new ArrayList<>(); List<WidgetOption> list = new ArrayList<>();
for (ToolbarItemProvider provider : set) { for (ToolbarItemProvider provider : set) {
WidgetOption option = WidgetOptionFactory.createByWidgetClass( WidgetOption option = WidgetOptionFactory.createByWidgetClass(
provider.nameForWidget(), provider.nameForWidget(),
IOUtils.readIcon(provider.iconPathForWidget()), IOUtils.readIcon(provider.iconPathForWidget()),
provider.classForWidget() provider.classForWidget()
); );
list.add(option); list.add(option);
} }
return list.toArray(new WidgetOption[list.size()]); return list.toArray(new WidgetOption[list.size()]);
} }
public Map<Class<? extends Widget>, Class<?>> getFormWidgetOptionsMap() { public Map<Class<? extends Widget>, Class<?>> getFormWidgetOptionsMap() {
Set<FormWidgetOptionProvider> set = getArray(FormWidgetOptionProvider.XML_TAG); Set<FormWidgetOptionProvider> set = getArray(FormWidgetOptionProvider.XML_TAG);
Map<Class<? extends Widget>, Class<?>> map = new HashMap<>(); Map<Class<? extends Widget>, Class<?>> map = new HashMap<>();
@ -149,15 +132,15 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
} }
return map; return map;
} }
public WidgetOption[] getFormWidgetOptions() { public WidgetOption[] getFormWidgetOptions() {
return getFormUnits(false); return getFormUnits(false);
} }
public WidgetOption[] getFormWidgetContainerOptions() { public WidgetOption[] getFormWidgetContainerOptions() {
return getFormUnits(true); return getFormUnits(true);
} }
private WidgetOption[] getFormUnits(boolean isContainer) { private WidgetOption[] getFormUnits(boolean isContainer) {
Set<FormWidgetOptionProvider> set = getArray(FormWidgetOptionProvider.XML_TAG); Set<FormWidgetOptionProvider> set = getArray(FormWidgetOptionProvider.XML_TAG);
if (set.isEmpty()) { if (set.isEmpty()) {
@ -167,18 +150,18 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
for (FormWidgetOptionProvider provider : set) { for (FormWidgetOptionProvider provider : set) {
if (provider.isContainer() == isContainer) { if (provider.isContainer() == isContainer) {
WidgetOption option = WidgetOptionFactory.createByWidgetClass( WidgetOption option = WidgetOptionFactory.createByWidgetClass(
provider.nameForWidget(), provider.nameForWidget(),
BaseUtils.readIcon(provider.iconPathForWidget()), BaseUtils.readIcon(provider.iconPathForWidget()),
provider.classForWidget() provider.classForWidget()
); );
result.add(option); result.add(option);
} }
} }
return result.toArray(new WidgetOption[result.size()]); return result.toArray(new WidgetOption[result.size()]);
} }
public WidgetOption[] getCellWidgetOptions() { public WidgetOption[] getCellWidgetOptions() {
Set<CellWidgetOptionProvider> set = getArray(CellWidgetOptionProvider.XML_TAG); Set<CellWidgetOptionProvider> set = getArray(CellWidgetOptionProvider.XML_TAG);
if (set.isEmpty()) { if (set.isEmpty()) {
@ -187,16 +170,16 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
Set<WidgetOption> result = new HashSet<>(); Set<WidgetOption> result = new HashSet<>();
for (CellWidgetOptionProvider provider : set) { for (CellWidgetOptionProvider provider : set) {
WidgetOption option = WidgetOptionFactory.createByWidgetClass( WidgetOption option = WidgetOptionFactory.createByWidgetClass(
provider.nameForWidget(), provider.nameForWidget(),
IOUtils.readIcon(provider.iconPathForWidget()), IOUtils.readIcon(provider.iconPathForWidget()),
provider.classForWidget() provider.classForWidget()
); );
result.add(option); result.add(option);
} }
return result.toArray(new WidgetOption[result.size()]); return result.toArray(new WidgetOption[result.size()]);
} }
public Map<Class<? extends Widget>, Appearance> getCellWidgetOptionsMap() { public Map<Class<? extends Widget>, Appearance> getCellWidgetOptionsMap() {
Set<CellWidgetOptionProvider> set = getArray(CellWidgetOptionProvider.XML_TAG); Set<CellWidgetOptionProvider> set = getArray(CellWidgetOptionProvider.XML_TAG);
Map<Class<? extends Widget>, Appearance> map = new HashMap<>(); Map<Class<? extends Widget>, Appearance> map = new HashMap<>();
@ -205,8 +188,8 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
} }
return map; return map;
} }
public Feedback getFeedback() { public Feedback getFeedback() {
try { try {
Class clazz = GeneralUtils.classForName("com.fr.design.feedback.CurrentFeedback"); Class clazz = GeneralUtils.classForName("com.fr.design.feedback.CurrentFeedback");
@ -218,34 +201,29 @@ public class ExtraDesignClassManager extends ExtraXMLFileManager implements Extr
} }
return Feedback.EMPTY; return Feedback.EMPTY;
} }
/**
* 文件名
*
* @return 文件名
*/
@Override @Override
public String fileName() { protected boolean demountSpecific(PluginSingleInjection injection) {
return "designer.xml";
if (ShortCut.TEMPLATE_TREE.equals(injection.getName()) && injection.getOriginalObject() instanceof ShortCut) {
shortCuts.remove(injection.getObject());
return true;
}
return false;
} }
/** @Override
* 读xml protected boolean mountSpecific(PluginSingleInjection injection) {
*
* @param reader xml对象 if (ShortCut.TEMPLATE_TREE.equals(injection.getName()) && injection.getOriginalObject() instanceof ShortCut) {
*/ shortCuts.put(injection.getObject(), (ShortCut) injection.getOriginalObject());
public void readXML(XMLableReader reader) { return true;
readXML(reader, null, PluginSimplify.NULL); }
return false;
} }
public Set<ShortCut> getExtraShortCuts() {
/**
* 写xml return shortCuts.getSet();
*
* @param writer xml对象
*/
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_TAG);
writer.end();
} }
} }

374
designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java

@ -19,128 +19,113 @@ import com.fr.design.mainframe.chart.gui.ChartStylePane;
import com.fr.design.mainframe.chart.gui.data.report.AbstractReportDataContentPane; import com.fr.design.mainframe.chart.gui.data.report.AbstractReportDataContentPane;
import com.fr.design.mainframe.chart.gui.data.table.AbstractTableDataContentPane; import com.fr.design.mainframe.chart.gui.data.table.AbstractTableDataContentPane;
import com.fr.design.module.DesignModuleFactory; import com.fr.design.module.DesignModuleFactory;
import com.fr.file.XMLFileManager;
import com.fr.form.ui.ChartEditor; import com.fr.form.ui.ChartEditor;
import com.fr.general.*; import com.fr.general.GeneralContext;
import com.fr.plugin.PluginCollector; import com.fr.general.IOUtils;
import com.fr.plugin.PluginLicenseManager; import com.fr.general.Inter;
import com.fr.plugin.PluginMessage; import com.fr.plugin.injectable.PluginSingleInjection;
import com.fr.design.extra.ChartTypeInterfaceCloseableHandler;
import com.fr.plugin.proxy.PluginInstanceProxyFactory;
import com.fr.plugin.proxy.PluginInvocationHandler;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.EnvChangedListener;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.bridge.StableFactory;
import com.fr.stable.collections.map.CloseableContainedMap; import com.fr.stable.collections.map.CloseableContainedMap;
import com.fr.stable.fun.Authorize;
import com.fr.stable.plugin.ExtraChartDesignClassManagerProvider; import com.fr.stable.plugin.ExtraChartDesignClassManagerProvider;
import com.fr.stable.plugin.PluginReadListener; import com.fr.stable.plugin.PluginReadListener;
import com.fr.stable.plugin.PluginSimplify;
import com.fr.stable.plugin.closeable.Closeable;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import javax.swing.*; import javax.swing.*;
import java.util.*; import java.util.*;
/** /**
* Created by eason on 14/12/29. * Created by eason on 14/12/29.
*/ */
public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraChartDesignClassManagerProvider { public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerProvider {
private static ClassLoader loader = Thread.currentThread().getContextClassLoader();
private static ChartTypeInterfaceManager classManager = new ChartTypeInterfaceManager();
private static ChartTypeInterfaceManager classManager = null;
private static LinkedHashMap<String, CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap>> chartTypeInterfaces = private static LinkedHashMap<String, CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap>> chartTypeInterfaces =
new LinkedHashMap<>(); new LinkedHashMap<String, CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap>>();
public synchronized static ChartTypeInterfaceManager getInstance() { public synchronized static ChartTypeInterfaceManager getInstance() {
if (classManager == null) {
classManager = new ChartTypeInterfaceManager();
chartTypeInterfaces.clear();
classManager.readDefault();
}
return classManager; return classManager;
} }
static { static {
GeneralContext.addEnvChangedListener(new EnvChangedListener() { readDefault();
public void envChanged() { StableFactory.registerMarkedObject(XML_TAG, classManager);
ChartTypeInterfaceManager.envChanged();
}
});
} }
// TODO: 2017/3/8
static { static {
GeneralContext.addPluginReadListener(new PluginReadListener() { GeneralContext.addPluginReadListener(new PluginReadListener() {
@Override @Override
public void success(Status status) { public void success() {
//重新注册designModuleFactory //重新注册designModuleFactory
DesignModuleFactory.registerExtraWidgetOptions(initWidgetOption()); DesignModuleFactory.registerExtraWidgetOptions(initWidgetOption());
} }
}); });
} }
public static WidgetOption[] initWidgetOption(){ private static WidgetOption[] initWidgetOption() {
ChartInternationalNameContentBean[] typeName = ChartTypeManager.getInstance().getAllChartBaseNames(); ChartInternationalNameContentBean[] typeName = ChartTypeManager.getInstance().getAllChartBaseNames();
ChartWidgetOption[] child = new ChartWidgetOption[typeName.length]; ChartWidgetOption[] child = new ChartWidgetOption[typeName.length];
final Chart[][] allCharts = new Chart[typeName.length][]; final Chart[][] allCharts = new Chart[typeName.length][];
for (int i = 0; i < typeName.length; i++) { for (int i = 0; i < typeName.length; i++) {
String plotID = typeName[i].getPlotID(); String plotID = typeName[i].getPlotID();
Chart[] rowChart = ChartTypeManager.getInstance().getChartTypes(plotID); Chart[] rowChart = ChartTypeManager.getInstance().getChartTypes(plotID);
if(ArrayUtils.isEmpty(rowChart)) { if (ArrayUtils.isEmpty(rowChart)) {
continue; continue;
} }
String iconPath = ChartTypeInterfaceManager.getInstance().getIconPath(plotID); String iconPath = ChartTypeInterfaceManager.getInstance().getIconPath(plotID);
Icon icon = IOUtils.readIcon(iconPath); Icon icon = IOUtils.readIcon(iconPath);
child[i] = new ChartWidgetOption(Inter.getLocText(typeName[i].getName()), icon, ChartEditor.class, rowChart[0]); child[i] = new ChartWidgetOption(Inter.getLocText(typeName[i].getName()), icon, ChartEditor.class, rowChart[0]);
allCharts[i] = rowChart; allCharts[i] = rowChart;
} }
//异步加载图片 //异步加载图片
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
initAllChartsDemoImage(allCharts); initAllChartsDemoImage(allCharts);
} }
}).start(); }).start();
return child; return child;
} }
//加载所有图表图片 //加载所有图表图片
private static void initAllChartsDemoImage(Chart[][] allCharts){ private static void initAllChartsDemoImage(Chart[][] allCharts) {
for (int i = 0; i < allCharts.length; i++) {
Chart[] rowChart = allCharts[i]; for (Chart[] rowChart : allCharts) {
if(rowChart == null) { if (rowChart == null) {
continue; continue;
} }
//加载初始化图表模型图片 //加载初始化图表模型图片
initChartsDemoImage(rowChart); initChartsDemoImage(rowChart);
} }
} }
private static void initChartsDemoImage(Chart[] rowChart) { private static void initChartsDemoImage(Chart[] rowChart) {
int rowChartsCount = rowChart.length;
for (int j = 0; j < rowChartsCount; j++) { for (Chart aRowChart : rowChart) {
//此时,为图片生成模型数据 //此时,为图片生成模型数据
rowChart[j].createSlotImage(); aRowChart.createSlotImage();
} }
} }
private synchronized static void envChanged() {
classManager = null;
}
private static void readDefault() { private static void readDefault() {
if (chartTypeInterfaces.containsKey(ChartTypeManager.CHART_PRIORITY)){
if (chartTypeInterfaces.containsKey(ChartTypeManager.CHART_PRIORITY)) {
return; return;
} }
CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap> chartUIList = CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap> chartUIList =
new CloseableContainedMap<>(LinkedHashMap.class); new CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap>(LinkedHashMap.class);
chartUIList.put(ChartConstants.COLUMN_CHART, new ColumnIndependentChartInterface()); chartUIList.put(ChartConstants.COLUMN_CHART, new ColumnIndependentChartInterface());
chartUIList.put(ChartConstants.LINE_CHART, new LineIndependentChartInterface()); chartUIList.put(ChartConstants.LINE_CHART, new LineIndependentChartInterface());
chartUIList.put(ChartConstants.BAR_CHART, new BarIndependentChartInterface()); chartUIList.put(ChartConstants.BAR_CHART, new BarIndependentChartInterface());
@ -158,16 +143,16 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
chartUIList.put(ChartConstants.MAP_CHART, new MapIndependentChartInterface()); chartUIList.put(ChartConstants.MAP_CHART, new MapIndependentChartInterface());
chartUIList.put(ChartConstants.GIS_CHAER, new GisMapIndependentChartInterface()); chartUIList.put(ChartConstants.GIS_CHAER, new GisMapIndependentChartInterface());
chartUIList.put(ChartConstants.FUNNEL_CHART, new FunnelIndependentChartInterface()); chartUIList.put(ChartConstants.FUNNEL_CHART, new FunnelIndependentChartInterface());
chartTypeInterfaces.put(ChartTypeManager.CHART_PRIORITY, chartUIList); chartTypeInterfaces.put(ChartTypeManager.CHART_PRIORITY, chartUIList);
} }
public String getIconPath(String plotID) { public String getIconPath(String plotID) {
if (chartTypeInterfaces != null) { if (chartTypeInterfaces != null) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); for (Map.Entry<String, CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap>> entry : chartTypeInterfaces.entrySet()) {
while (iterator.hasNext()) { String priority = entry.getKey();
Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey();
String imagePath = getIconPath(priority, plotID); String imagePath = getIconPath(priority, plotID);
if (StringUtils.isNotEmpty(imagePath)) { if (StringUtils.isNotEmpty(imagePath)) {
return imagePath; return imagePath;
@ -176,25 +161,26 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
private String getIconPath(String priority, String plotID) { private String getIconPath(String priority, String plotID) {
if (chartTypeInterfaces.get(priority) != null && chartTypeInterfaces.get(priority).get(plotID) != null) { if (chartTypeInterfaces.get(priority) != null && chartTypeInterfaces.get(priority).get(plotID) != null) {
return chartTypeInterfaces.get(priority).get(plotID).getIconPath(); return chartTypeInterfaces.get(priority).get(plotID).getIconPath();
}else { } else {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
} }
public static void addChartTypeInterface(IndependentChartUIProvider provider, String priority, String plotID) { private static void addChartTypeInterface(IndependentChartUIProvider provider, String priority, String plotID) {
if (chartTypeInterfaces != null){
if (!chartTypeInterfaces.containsKey(priority)){ if (chartTypeInterfaces != null) {
if (!chartTypeInterfaces.containsKey(priority)) {
//新建一个具体图表列表 //新建一个具体图表列表
CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap> chartUIList CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap> chartUIList
= new CloseableContainedMap<>(LinkedHashMap.class); = new CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap>(LinkedHashMap.class);
chartUIList.put(plotID, provider); chartUIList.put(plotID, provider);
chartTypeInterfaces.put(priority, chartUIList); chartTypeInterfaces.put(priority, chartUIList);
}else { } else {
Map<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority); Map<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority);
if (!chartUIList.containsKey(plotID)) { if (!chartUIList.containsKey(plotID)) {
chartUIList.put(plotID, provider); chartUIList.put(plotID, provider);
@ -202,54 +188,18 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
} }
} }
/**
* 增加界面接口定义
*
* @param className 类名
* @param plotID 标志ID
*/
public void addChartInterface(String className, String priority, String plotID, PluginSimplify simplify) {
if (StringUtils.isNotBlank(className)) {
try {
Class<?> clazz = Class.forName(className);
Authorize authorize = clazz.getAnnotation(Authorize.class);
if (authorize != null) {
PluginLicenseManager.getInstance().registerPaid(authorize, simplify);
}
IndependentChartUIProvider provider = getProxyObj(plotID, simplify, clazz);
if (PluginCollector.getCollector().isError(provider, IndependentChartUIProvider.CURRENT_API_LEVEL, simplify.getPluginName())) {
PluginMessage.remindUpdate(className);
} else {
addChartTypeInterface(provider, priority, plotID);
}
} catch (ClassNotFoundException e) {
FRLogger.getLogger().error("class not found:" + e.getMessage());
} catch (IllegalAccessException | InstantiationException e) {
FRLogger.getLogger().error("object create error:" + e.getMessage());
} catch (NoSuchMethodException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
}
private IndependentChartUIProvider getProxyObj(String plotID, PluginSimplify simplify, Class<?> clazz) throws IllegalAccessException, InstantiationException, NoSuchMethodException {
PluginInstanceProxyFactory factory = new PluginInstanceProxyFactory(clazz, simplify);
PluginInvocationHandler handler = new ChartTypeInterfaceCloseableHandler(plotID);
return (IndependentChartUIProvider) factory.addProxy(Closeable.class, handler).getProxyObj();
}
/** /**
* 把所有的pane加到list里 * 把所有的pane加到list里
* *
* @param paneList pane容器 * @param paneList pane容器
*/ */
public void addPlotTypePaneList(List<FurtherBasicBeanPane<? extends Chart>> paneList) { public void addPlotTypePaneList(List<FurtherBasicBeanPane<? extends Chart>> paneList) {
List<Integer> priorityList = getPriorityInOrder(); List<Integer> priorityList = getPriorityInOrder();
for (int i = 0; i < priorityList.size(); i++){ for (Integer aPriorityList : priorityList) {
String priority = String.valueOf(priorityList.get(i)); String priority = String.valueOf(aPriorityList);
Iterator chartUIIterator = chartTypeInterfaces.get(priority).entrySet().iterator(); Iterator chartUIIterator = chartTypeInterfaces.get(priority).entrySet().iterator();
while (chartUIIterator.hasNext()) { while (chartUIIterator.hasNext()) {
Map.Entry chartUIEntry = (Map.Entry) chartUIIterator.next(); Map.Entry chartUIEntry = (Map.Entry) chartUIIterator.next();
@ -258,9 +208,10 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
} }
} }
public String[] getTitle4PopupWindow(String priority){ public String[] getTitle4PopupWindow(String priority) {
if (priority.isEmpty()){
if (priority.isEmpty()) {
return getTitle4PopupWindow(); return getTitle4PopupWindow();
} }
String[] names = new String[getChartSize(priority)]; String[] names = new String[getChartSize(priority)];
@ -268,7 +219,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
Map<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority); Map<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority);
Iterator iterator = chartUIList.entrySet().iterator(); Iterator iterator = chartUIList.entrySet().iterator();
int i = 0; int i = 0;
while (iterator.hasNext()){ while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next(); Map.Entry entry = (Map.Entry) iterator.next();
IndependentChartUIProvider provider = (IndependentChartUIProvider) entry.getValue(); IndependentChartUIProvider provider = (IndependentChartUIProvider) entry.getValue();
names[i++] = provider.getPlotTypeTitle4PopupWindow(); names[i++] = provider.getPlotTypeTitle4PopupWindow();
@ -277,19 +228,17 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return new String[0]; return new String[0];
} }
/** /**
* 获取指定图表的标题 * 获取指定图表的标题
* @param priority
* @return
*/ */
public String getTitle4PopupWindow(String priority, String plotID){ public String getTitle4PopupWindow(String priority, String plotID) {
if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority) && chartTypeInterfaces.get(priority).containsKey(plotID)) { if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority) && chartTypeInterfaces.get(priority).containsKey(plotID)) {
IndependentChartUIProvider provider = chartTypeInterfaces.get(priority).get(plotID); IndependentChartUIProvider provider = chartTypeInterfaces.get(priority).get(plotID);
return provider.getPlotTypeTitle4PopupWindow(); return provider.getPlotTypeTitle4PopupWindow();
} }
//兼容老的插件 //兼容老的插件
if (chartTypeInterfaces != null) { if (chartTypeInterfaces != null) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
@ -301,34 +250,36 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
} }
} }
return new String(); return StringUtils.EMPTY;
} }
private String[] getTitle4PopupWindow(){ private String[] getTitle4PopupWindow() {
List<Integer> priorityList = getPriorityInOrder(); List<Integer> priorityList = getPriorityInOrder();
if (priorityList.size() == 0){ if (priorityList.size() == 0) {
return new String[0]; return new String[0];
} }
int size = 0; int size = 0;
//获取总得图表格式 //获取总得图表格式
for (int i = 0; i < priorityList.size(); i++) { for (Integer aPriorityList : priorityList) {
size += getChartSize(String.valueOf(priorityList.get(i))); size += getChartSize(String.valueOf(aPriorityList));
} }
String[] names = new String[size]; String[] names = new String[size];
int index = 0; int index = 0;
for (int i = 0; i < priorityList.size(); i++){ for (Integer aPriorityList : priorityList) {
String priority = String.valueOf(priorityList.get(i)); String priority = String.valueOf(aPriorityList);
Iterator chartUI = chartTypeInterfaces.get(priority).entrySet().iterator(); Iterator chartUI = chartTypeInterfaces.get(priority).entrySet().iterator();
index = fetchNames(chartUI, names, index); index = fetchNames(chartUI, names, index);
} }
return names; return names;
} }
private List<Integer> getPriorityInOrder() { private List<Integer> getPriorityInOrder() {
List<Integer> priorityList = new ArrayList<Integer>(); List<Integer> priorityList = new ArrayList<Integer>();
if (chartTypeInterfaces != null) { if (chartTypeInterfaces != null) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
@ -340,8 +291,9 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return ChartTypeManager.orderInPriority(priorityList); return ChartTypeManager.orderInPriority(priorityList);
} }
private int fetchNames(Iterator chartUI, String[] names, int index) { private int fetchNames(Iterator chartUI, String[] names, int index) {
while (chartUI.hasNext()) { while (chartUI.hasNext()) {
Map.Entry chartUIEntry = (Map.Entry) chartUI.next(); Map.Entry chartUIEntry = (Map.Entry) chartUI.next();
IndependentChartUIProvider provider = (IndependentChartUIProvider) chartUIEntry.getValue(); IndependentChartUIProvider provider = (IndependentChartUIProvider) chartUIEntry.getValue();
@ -349,10 +301,11 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return index; return index;
} }
public ChartDataPane getChartDataPane(String plotID, AttributeChangeListener listener) { public ChartDataPane getChartDataPane(String plotID, AttributeChangeListener listener) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next(); Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey(); String priority = (String) entry.getKey();
if (plotInChart(plotID, priority)) { if (plotInChart(plotID, priority)) {
@ -361,26 +314,28 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return getChartDataPane(ChartTypeManager.CHART_PRIORITY, plotID, listener); return getChartDataPane(ChartTypeManager.CHART_PRIORITY, plotID, listener);
} }
private ChartDataPane getChartDataPane(String priority, String plotID, AttributeChangeListener listener) { private ChartDataPane getChartDataPane(String priority, String plotID, AttributeChangeListener listener) {
return chartTypeInterfaces.get(priority).get(plotID).getChartDataPane(listener); return chartTypeInterfaces.get(priority).get(plotID).getChartDataPane(listener);
} }
/** /**
* 获取对应ID的图表数量 * 获取对应ID的图表数量
* @param key *
* @return
*/ */
private int getChartSize(String key){ private int getChartSize(String key) {
if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(key)){
if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(key)) {
return chartTypeInterfaces.get(key).size(); return chartTypeInterfaces.get(key).size();
} }
return 0; return 0;
} }
public AbstractChartAttrPane[] getAttrPaneArray(String plotID, AttributeChangeListener listener) { public AbstractChartAttrPane[] getAttrPaneArray(String plotID, AttributeChangeListener listener) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next(); Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey(); String priority = (String) entry.getKey();
if (plotInChart(plotID, priority)) { if (plotInChart(plotID, priority)) {
@ -389,14 +344,16 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return getAttrPaneArray(ChartTypeManager.CHART_PRIORITY, plotID, listener); return getAttrPaneArray(ChartTypeManager.CHART_PRIORITY, plotID, listener);
} }
private AbstractChartAttrPane[] getAttrPaneArray(String priority, String plotID, AttributeChangeListener listener) { private AbstractChartAttrPane[] getAttrPaneArray(String priority, String plotID, AttributeChangeListener listener) {
return chartTypeInterfaces.get(priority).get(plotID).getAttrPaneArray(listener); return chartTypeInterfaces.get(priority).get(plotID).getAttrPaneArray(listener);
} }
public AbstractTableDataContentPane getTableDataSourcePane(Plot plot, ChartDataPane parent) { public AbstractTableDataContentPane getTableDataSourcePane(Plot plot, ChartDataPane parent) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next(); Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey(); String priority = (String) entry.getKey();
if (plotInChart(plot.getPlotID(), priority)) { if (plotInChart(plot.getPlotID(), priority)) {
@ -405,15 +362,17 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return getTableDataSourcePane(ChartTypeManager.CHART_PRIORITY, plot, parent); return getTableDataSourcePane(ChartTypeManager.CHART_PRIORITY, plot, parent);
} }
private AbstractTableDataContentPane getTableDataSourcePane(String priority, Plot plot, ChartDataPane parent) { private AbstractTableDataContentPane getTableDataSourcePane(String priority, Plot plot, ChartDataPane parent) {
return chartTypeInterfaces.get(priority).get(plot.getPlotID()).getTableDataSourcePane(plot, parent); return chartTypeInterfaces.get(priority).get(plot.getPlotID()).getTableDataSourcePane(plot, parent);
} }
public AbstractReportDataContentPane getReportDataSourcePane(Plot plot, ChartDataPane parent) { public AbstractReportDataContentPane getReportDataSourcePane(Plot plot, ChartDataPane parent) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next(); Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey(); String priority = (String) entry.getKey();
String plotID = plot.getPlotID(); String plotID = plot.getPlotID();
@ -423,21 +382,24 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return getReportDataSourcePane(ChartTypeManager.CHART_PRIORITY, plot, parent); return getReportDataSourcePane(ChartTypeManager.CHART_PRIORITY, plot, parent);
} }
private boolean plotInChart(String plotID, String priority) { private boolean plotInChart(String plotID, String priority) {
return chartTypeInterfaces != null return chartTypeInterfaces != null
&& chartTypeInterfaces.containsKey(priority) && chartTypeInterfaces.containsKey(priority)
&& chartTypeInterfaces.get(priority).containsKey(plotID); && chartTypeInterfaces.get(priority).containsKey(plotID);
} }
private AbstractReportDataContentPane getReportDataSourcePane(String priority, Plot plot, ChartDataPane parent) { private AbstractReportDataContentPane getReportDataSourcePane(String priority, Plot plot, ChartDataPane parent) {
return chartTypeInterfaces.get(priority).get(plot.getPlotID()).getReportDataSourcePane(plot, parent); return chartTypeInterfaces.get(priority).get(plot.getPlotID()).getReportDataSourcePane(plot, parent);
} }
public ConditionAttributesPane getPlotConditionPane(Plot plot) { public ConditionAttributesPane getPlotConditionPane(Plot plot) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next(); Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey(); String priority = (String) entry.getKey();
if (plotInChart(plot.getPlotID(), priority)) { if (plotInChart(plot.getPlotID(), priority)) {
@ -446,15 +408,17 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return getPlotConditionPane(ChartTypeManager.CHART_PRIORITY, plot); return getPlotConditionPane(ChartTypeManager.CHART_PRIORITY, plot);
} }
private ConditionAttributesPane getPlotConditionPane(String priority, Plot plot) { private ConditionAttributesPane getPlotConditionPane(String priority, Plot plot) {
return chartTypeInterfaces.get(priority).get(plot.getPlotID()).getPlotConditionPane(plot); return chartTypeInterfaces.get(priority).get(plot.getPlotID()).getPlotConditionPane(plot);
} }
public BasicBeanPane<Plot> getPlotSeriesPane(ChartStylePane parent, Plot plot) { public BasicBeanPane<Plot> getPlotSeriesPane(ChartStylePane parent, Plot plot) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next(); Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey(); String priority = (String) entry.getKey();
if (plotInChart(plot.getPlotID(), priority)) { if (plotInChart(plot.getPlotID(), priority)) {
@ -463,11 +427,12 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
} }
return getPlotSeriesPane(ChartTypeManager.CHART_PRIORITY, parent, plot); return getPlotSeriesPane(ChartTypeManager.CHART_PRIORITY, parent, plot);
} }
private BasicBeanPane<Plot> getPlotSeriesPane(String priority, ChartStylePane parent, Plot plot) { private BasicBeanPane<Plot> getPlotSeriesPane(String priority, ChartStylePane parent, Plot plot) {
return chartTypeInterfaces.get(priority).get(plot.getPlotID()).getPlotSeriesPane(parent, plot); return chartTypeInterfaces.get(priority).get(plot.getPlotID()).getPlotSeriesPane(parent, plot);
} }
/** /**
* 是否使用默认的界面为了避免界面来回切换 * 是否使用默认的界面为了避免界面来回切换
* *
@ -475,55 +440,60 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
* @return 是否使用默认的界面 * @return 是否使用默认的界面
*/ */
public boolean isUseDefaultPane(String plotID) { public boolean isUseDefaultPane(String plotID) {
Iterator iterator = chartTypeInterfaces.entrySet().iterator(); Iterator iterator = chartTypeInterfaces.entrySet().iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next(); Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey(); String priority = (String) entry.getKey();
if (chartTypeInterfaces.get(priority).containsKey(plotID)) { if (chartTypeInterfaces.get(priority).containsKey(plotID)) {
return isUseDefaultPane(priority, plotID); return isUseDefaultPane(priority, plotID);
} }
} }
return true; return true;
} }
private boolean isUseDefaultPane(String priority, String plotID) { private boolean isUseDefaultPane(String priority, String plotID) {
if (chartTypeInterfaces.containsKey(priority) && chartTypeInterfaces.get(priority).containsKey(plotID)) { return !(chartTypeInterfaces.containsKey(priority) && chartTypeInterfaces.get(priority).containsKey(plotID)) || chartTypeInterfaces.get(priority).get(plotID).isUseDefaultPane();
return chartTypeInterfaces.get(priority).get(plotID).isUseDefaultPane();
}
return true;
} }
public void readXML(XMLableReader reader) { @Override
readXML(reader, null, PluginSimplify.NULL); public void mount(PluginSingleInjection injection) {
if (isIndependentChartUIProvider(injection)) {
String priority = injection.getAttribute("priority");
String plotID = injection.getAttribute("plotID");
IndependentChartUIProvider instance = (IndependentChartUIProvider) injection.getObject();
addChartTypeInterface(instance, priority, plotID);
}
} }
@Override @Override
public void readXML(XMLableReader reader, List<String> extraChartDesignInterfaceList, PluginSimplify simplify) { public void demount(PluginSingleInjection injection) {
if (reader.isChildNode()) {
String tagName = reader.getTagName(); if (isIndependentChartUIProvider(injection)) {
if (extraChartDesignInterfaceList != null) { String priority = injection.getAttribute("priority");
extraChartDesignInterfaceList.add(tagName); String plotID = injection.getAttribute("plotID");
} removeChartTypeInterface(priority, plotID);
if (IndependentChartUIProvider.XML_TAG.equals(tagName)) {
addChartInterface(reader.getAttrAsString("class", ""), reader.getAttrAsString("priority", ChartTypeManager.CHART_PRIORITY),reader.getAttrAsString("plotID", ""), simplify);
}
} }
} }
/** private void removeChartTypeInterface(String priority, String plotID) {
* 文件名
* if (chartTypeInterfaces != null) {
* @return 文件名 if (chartTypeInterfaces.containsKey(priority)) {
*/ Map<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority);
public String fileName() { chartUIList.remove(plotID);
return "chart.xml"; }
}
} }
@Override
public void writeXML(XMLPrintWriter writer) { private boolean isIndependentChartUIProvider(PluginSingleInjection injection) {
return !(injection == null || injection.getObject() == null) && IndependentChartUIProvider.XML_TAG.equals(injection.getName()) && injection.getObject() instanceof IndependentChartUIProvider;
} }
} }
Loading…
Cancel
Save