Browse Source

Merge pull request #611 in BA/design from ~JU/1-ba-design:dev to dev

* commit '35782fcac18c1e3f7e19067447ee6a3fe0ff70c7':
  修改判断逻辑
  将Closeable的判断等事情放到专门的容器中
  将Closeable的判断等事情放到专门的容器中
  保证获取不到已经禁用了的图表插件实例
  保证获取不到已经禁用了的图表插件实例
  保证获取不到已经禁用了的图表插件实例
  保证获取不到已经禁用了的图表插件实例
master
superman 8 years ago
parent
commit
c69102453c
  1. 48
      designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java
  2. 31
      designer_chart/src/com/fr/design/extra/ChartTypeInterfaceCloseableHandler.java

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

@ -25,13 +25,18 @@ import com.fr.general.*;
import com.fr.plugin.PluginCollector;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.PluginMessage;
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.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;
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;
@ -43,13 +48,12 @@ import java.util.*;
*/
public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraChartDesignClassManagerProvider {
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) {
@ -135,7 +139,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());
@ -173,6 +178,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
}
private String getIconPath(String priority, String plotID) {
if (chartTypeInterfaces.get(priority) != null && chartTypeInterfaces.get(priority).get(plotID) != null) {
return chartTypeInterfaces.get(priority).get(plotID).getIconPath();
}else {
@ -184,11 +190,12 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
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);
Map<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority);
if (!chartUIList.containsKey(plotID)) {
chartUIList.put(plotID, provider);
}
@ -210,23 +217,27 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
if (authorize != null) {
PluginLicenseManager.getInstance().registerPaid(authorize, simplify);
}
IndependentChartUIProvider provider = (IndependentChartUIProvider) clazz.newInstance();
if (PluginCollector.getCollector().isError(provider, IndependentChartUIProvider.CURRENT_API_LEVEL, simplify.getPluginName()) || !containsChart(plotID)) {
IndependentChartUIProvider provider = getProxyObj(plotID, simplify, clazz);
if (PluginCollector.getCollector().isError(provider, IndependentChartUIProvider.CURRENT_API_LEVEL, simplify.getPluginName())) {
PluginMessage.remindUpdate(className);
} else {
ChartTypeInterfaceManager.getInstance().addChartTypeInterface(provider, priority, plotID);
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());
}
}
}
//UI对应的chart如果没有加载,UI也不必加进去了
private boolean containsChart(String plotID) {
return ChartTypeManager.getInstance().containsPlot(plotID);
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();
}
@ -253,8 +264,8 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
return getTitle4PopupWindow();
}
String[] names = new String[getChartSize(priority)];
if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority)){
HashMap<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority);
if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority)) {
Map<String, IndependentChartUIProvider> chartUIList = chartTypeInterfaces.get(priority);
Iterator iterator = chartUIList.entrySet().iterator();
int i = 0;
while (iterator.hasNext()){
@ -273,7 +284,8 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
* @return
*/
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);
return provider.getPlotTypeTitle4PopupWindow();
}
@ -467,7 +479,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
while (iterator.hasNext()){
Map.Entry entry = (Map.Entry) iterator.next();
String priority = (String) entry.getKey();
if (chartTypeInterfaces.get(priority).containsKey(plotID)){
if (chartTypeInterfaces.get(priority).containsKey(plotID)) {
return isUseDefaultPane(priority, plotID);
}
}
@ -475,7 +487,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
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.get(priority).get(plotID).isUseDefaultPane();

31
designer_chart/src/com/fr/design/extra/ChartTypeInterfaceCloseableHandler.java

@ -0,0 +1,31 @@
package com.fr.design.extra;
import com.fr.chart.charttypes.ChartTypeManager;
import com.fr.plugin.proxy.CloseableInvocationHandler;
/**
* Created by juhaoyu on 2016/12/27.
*/
public class ChartTypeInterfaceCloseableHandler extends CloseableInvocationHandler {
private final String plotID;
public ChartTypeInterfaceCloseableHandler(String plotID) throws NoSuchMethodException {
super();
this.plotID = plotID;
}
@Override
protected boolean invokeIsClosed() {
//UI对应的chart如果关闭或者不存在,则UI关闭
return super.invokeIsClosed() || !containsChart();
}
private boolean containsChart() {
return ChartTypeManager.getInstance().containsPlot(plotID);
}
}
Loading…
Cancel
Save