From d9b634132b40f8906ca7d2665a0ab2d1bd0b7387 Mon Sep 17 00:00:00 2001 From: juhaoyu <2335173323@qq.com> Date: Tue, 27 Dec 2016 14:45:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E8=AF=81=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E5=B7=B2=E7=BB=8F=E7=A6=81=E7=94=A8=E4=BA=86=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E6=8F=92=E4=BB=B6=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/ChartTypeInterfaceManager.java | 19 +++++++---- .../ChartTypeInterfaceCloseableHandler.java | 32 +++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 designer_chart/src/com/fr/design/extra/ChartTypeInterfaceCloseableHandler.java diff --git a/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java b/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java index 4bfc6aed67..f7b5c2a49e 100644 --- a/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java +++ b/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java @@ -25,6 +25,9 @@ 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; @@ -33,6 +36,7 @@ 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; @@ -213,24 +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) { + private IndependentChartUIProvider getProxyObj(String plotID, PluginSimplify simplify, Class clazz) throws IllegalAccessException, InstantiationException, NoSuchMethodException { - return ChartTypeManager.getInstance().containsPlot(plotID); + PluginInstanceProxyFactory factory = new PluginInstanceProxyFactory(clazz, simplify); + PluginInvocationHandler handler = new ChartTypeInterfaceCloseableHandler(plotID); + return (IndependentChartUIProvider) factory.addProxy(Closeable.class, handler).getProxyObj(); } diff --git a/designer_chart/src/com/fr/design/extra/ChartTypeInterfaceCloseableHandler.java b/designer_chart/src/com/fr/design/extra/ChartTypeInterfaceCloseableHandler.java new file mode 100644 index 0000000000..6dd65ff38b --- /dev/null +++ b/designer_chart/src/com/fr/design/extra/ChartTypeInterfaceCloseableHandler.java @@ -0,0 +1,32 @@ +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() { + + //找不到Plugin对象时,默认是关闭的 + return super.invokeIsClosed() && containsChart(); + } + + //UI对应的chart如果没有关闭或者不存在,则UI关闭 + private boolean containsChart() { + + return ChartTypeManager.getInstance().containsPlot(plotID); + } +}