Browse Source

保证获取不到已经禁用了的图表插件实例

master
juhaoyu 8 years ago
parent
commit
ea087d4845
  1. 96
      designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java

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

@ -22,11 +22,13 @@ import com.fr.design.module.DesignModuleFactory;
import com.fr.file.XMLFileManager;
import com.fr.form.ui.ChartEditor;
import com.fr.general.*;
import com.fr.plugin.*;
import com.fr.plugin.proxy.PluginInstanceProxyFactory;
import com.fr.plugin.PluginCollector;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.PluginMessage;
import com.fr.stable.ArrayUtils;
import com.fr.stable.EnvChangedListener;
import com.fr.stable.StringUtils;
import com.fr.stable.collections.map.CloseableContainedMap;
import com.fr.stable.fun.Authorize;
import com.fr.stable.plugin.ExtraChartDesignClassManagerProvider;
import com.fr.stable.plugin.PluginReadListener;
@ -45,7 +47,9 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
private static ClassLoader loader = Thread.currentThread().getContextClassLoader();
private static ChartTypeInterfaceManager classManager = null;
private static LinkedHashMap<String, LinkedHashMap<String, IndependentChartUIProvider>> chartTypeInterfaces = new LinkedHashMap<String, LinkedHashMap<String, IndependentChartUIProvider>>();
private static LinkedHashMap<String, CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap>> chartTypeInterfaces =
new LinkedHashMap<>();
public synchronized static ChartTypeInterfaceManager getInstance() {
if (classManager == null) {
@ -131,7 +135,8 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
if (chartTypeInterfaces.containsKey(ChartTypeManager.CHART_PRIORITY)){
return;
}
LinkedHashMap<String, IndependentChartUIProvider> chartUIList = new LinkedHashMap<String, IndependentChartUIProvider>();
CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap> chartUIList =
new CloseableContainedMap<>(LinkedHashMap.class);
chartUIList.put(ChartConstants.COLUMN_CHART, new ColumnIndependentChartInterface());
chartUIList.put(ChartConstants.LINE_CHART, new LineIndependentChartInterface());
chartUIList.put(ChartConstants.BAR_CHART, new BarIndependentChartInterface());
@ -170,28 +175,23 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
private String getIconPath(String priority, String plotID) {
if (containsPlot(priority, plotID)) {
if (chartTypeInterfaces.get(priority) != null && chartTypeInterfaces.get(priority).get(plotID) != null) {
return chartTypeInterfaces.get(priority).get(plotID).getIconPath();
}else {
return StringUtils.EMPTY;
}
}
private boolean containsPlot(String priority, String plotID) {
return chartTypeInterfaces.get(priority) != null && chartTypeInterfaces.get(priority).get(plotID) != null
&& !CloseableUtils.isClosed(chartTypeInterfaces.get(priority).get(plotID));
}
public static void addChartTypeInterface(IndependentChartUIProvider provider, String priority, String plotID) {
if (chartTypeInterfaces != null){
if (!chartTypeInterfaces.containsKey(priority)){
//新建一个具体图表列表
LinkedHashMap<String, IndependentChartUIProvider> chartUIList = new LinkedHashMap<String, IndependentChartUIProvider>();
CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap> chartUIList
= new CloseableContainedMap<>(LinkedHashMap.class);
chartUIList.put(plotID, provider);
chartTypeInterfaces.put(priority, chartUIList);
}else {
LinkedHashMap<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority);
CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap> chartUIList = chartTypeInterfaces.get(priority);
if (!chartUIList.containsKey(plotID)) {
chartUIList.put(plotID, provider);
}
@ -213,8 +213,8 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
if (authorize != null) {
PluginLicenseManager.getInstance().registerPaid(authorize, simplify);
}
IndependentChartUIProvider provider = (IndependentChartUIProvider) new PluginInstanceProxyFactory(clazz, simplify).addProxy(Closeable.MASK).getProxyObj();
if (PluginCollector.getCollector().isError(provider, IndependentChartUIProvider.CURRENT_API_LEVEL, simplify.getPluginName())) {
IndependentChartUIProvider provider = (IndependentChartUIProvider) clazz.newInstance();
if (PluginCollector.getCollector().isError(provider, IndependentChartUIProvider.CURRENT_API_LEVEL, simplify.getPluginName()) || !containsChart(plotID)) {
PluginMessage.remindUpdate(className);
} else {
ChartTypeInterfaceManager.getInstance().addChartTypeInterface(provider, priority, plotID);
@ -227,10 +227,11 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
}
}
// //UI对应的chart如果没有加载,UI也不必加进去了
// private boolean containsChart(String plotID) {
// return ChartTypeManager.getInstance().containsPlot(plotID);
// }
//UI对应的chart如果没有加载,UI也不必加进去了
private boolean containsChart(String plotID) {
return ChartTypeManager.getInstance().containsPlot(plotID);
}
/**
@ -246,9 +247,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
while (chartUIIterator.hasNext()) {
Map.Entry chartUIEntry = (Map.Entry) chartUIIterator.next();
IndependentChartUIProvider provider = (IndependentChartUIProvider) chartUIEntry.getValue();
if (!CloseableUtils.isClosed(provider)) {
paneList.add(provider.getPlotTypePane());
}
paneList.add(provider.getPlotTypePane());
}
}
}
@ -258,34 +257,20 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
return getTitle4PopupWindow();
}
String[] names = new String[getChartSize(priority)];
if (containsPriority(priority)) {
HashMap<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority);
if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority)) {
CloseableContainedMap<String, IndependentChartUIProvider, LinkedHashMap> chartUIList = chartTypeInterfaces.get(priority);
Iterator iterator = chartUIList.entrySet().iterator();
int i = 0;
while (iterator.hasNext()){
Map.Entry entry = (Map.Entry) iterator.next();
IndependentChartUIProvider provider = (IndependentChartUIProvider) entry.getValue();
if (!CloseableUtils.isClosed(provider)) {
names[i++] = provider.getPlotTypeTitle4PopupWindow();
}
names[i++] = provider.getPlotTypeTitle4PopupWindow();
}
return names;
}
return new String[0];
}
/**
* 判断是否包含某种优先级的图表provider--包含该级别的map并且map里面存在没有关闭的实例
*
* @param priority 优先级
* @return 是否包含
*/
private boolean containsPriority(String priority) {
return chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority)
&& !CloseableUtils.allClosed(chartTypeInterfaces.get(priority));
}
/**
* 获取指定图表的标题
* @param priority
@ -293,7 +278,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
*/
public String getTitle4PopupWindow(String priority, String plotID){
if (containsPlot(priority, plotID)) {
if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority) && chartTypeInterfaces.get(priority).containsKey(plotID)) {
IndependentChartUIProvider provider = chartTypeInterfaces.get(priority).get(plotID);
return provider.getPlotTypeTitle4PopupWindow();
}
@ -304,12 +289,12 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
String defaultPriority = (String) entry.getKey();
if (containsPlot(defaultPriority, plotID)) {
if (chartTypeInterfaces.get(defaultPriority).containsKey(plotID)) {
return chartTypeInterfaces.get(defaultPriority).get(plotID).getPlotTypeTitle4PopupWindow();
}
}
}
return StringUtils.EMPTY;
return new String();
}
private String[] getTitle4PopupWindow(){
@ -343,10 +328,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey();
//包含该优先级时
if (containsPriority(priority)) {
priorityList.add(Integer.valueOf(priority));
}
priorityList.add(Integer.valueOf(priority));
}
}
return ChartTypeManager.orderInPriority(priorityList);
@ -356,9 +338,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
while (chartUI.hasNext()) {
Map.Entry chartUIEntry = (Map.Entry) chartUI.next();
IndependentChartUIProvider provider = (IndependentChartUIProvider) chartUIEntry.getValue();
if (CloseableUtils.isClosed(provider)) {
names[index++] = provider.getPlotTypeTitle4PopupWindow();
}
names[index++] = provider.getPlotTypeTitle4PopupWindow();
}
return index;
}
@ -386,7 +366,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
*/
private int getChartSize(String key){
if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(key)){
return CloseableUtils.openingSize(chartTypeInterfaces.get(key));
return chartTypeInterfaces.get(key).size();
}
return 0;
}
@ -440,8 +420,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
private boolean plotInChart(String plotID, String priority) {
return chartTypeInterfaces != null
&& chartTypeInterfaces.containsKey(priority)
&& chartTypeInterfaces.get(priority).containsKey(plotID)
&& !CloseableUtils.isClosed(chartTypeInterfaces.get(priority).get(plotID));
&& chartTypeInterfaces.get(priority).containsKey(plotID);
}
private AbstractReportDataContentPane getReportDataSourcePane(String priority, Plot plot, ChartDataPane parent) {
@ -493,14 +472,23 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
while (iterator.hasNext()){
Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey();
if (containsPlot(priority, plotID)) {
return chartTypeInterfaces.get(priority).get(plotID).isUseDefaultPane();
if (chartTypeInterfaces.get(priority).containsKey(plotID)) {
return isUseDefaultPane(priority, plotID);
}
}
return true;
}
private boolean isUseDefaultPane(String priority, String plotID) {
if (chartTypeInterfaces.containsKey(priority) && chartTypeInterfaces.get(priority).containsKey(plotID)) {
return chartTypeInterfaces.get(priority).get(plotID).isUseDefaultPane();
}
return true;
}
public void readXML(XMLableReader reader) {
readXML(reader, null, PluginSimplify.NULL);
}

Loading…
Cancel
Save