From 363138e5fc2283c6a1e3f4c678e30cedc4a089f5 Mon Sep 17 00:00:00 2001 From: kerry Date: Sat, 27 May 2017 13:46:21 +0800 Subject: [PATCH] =?UTF-8?q?report-2354=20=E6=95=B4=E5=90=88=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E6=8F=92=E4=BB=B6=E6=93=8D=E4=BD=9C=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/extra/PluginOperateUtils.java | 111 ++++++++++++++++++ .../com/fr/design/extra/PluginWebBridge.java | 25 ++-- .../callback/AbstractPluginTaskCallback.java | 21 ++++ .../extra/exe/callback/DownloadCallback.java | 34 ++++++ .../exe/callback/InstallFromDiskCallback.java | 52 ++++++++ .../exe/callback/InstallOnlineCallback.java | 53 +++++++++ .../design/extra/exe/callback/JSCallback.java | 29 +++++ .../exe/callback/ModifyStatusCallback.java | 28 +++++ .../exe/callback/UnistallPluginCallback.java | 26 ++++ .../exe/callback/UpdateFromDiskCallback.java | 53 +++++++++ .../exe/callback/UpdateOnlineCallback.java | 55 +++++++++ .../extra/exe/extratask/ExtraPluginTask.java | 10 ++ .../exe/extratask/InstallPluginTask.java | 25 ++++ .../extra/exe/extratask/UpdatePluginTask.java | 28 +++++ 14 files changed, 538 insertions(+), 12 deletions(-) create mode 100644 designer_base/src/com/fr/design/extra/PluginOperateUtils.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java create mode 100644 designer_base/src/com/fr/design/extra/exe/extratask/ExtraPluginTask.java create mode 100644 designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java create mode 100644 designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java diff --git a/designer_base/src/com/fr/design/extra/PluginOperateUtils.java b/designer_base/src/com/fr/design/extra/PluginOperateUtils.java new file mode 100644 index 000000000..beb84b9c6 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/PluginOperateUtils.java @@ -0,0 +1,111 @@ +package com.fr.design.extra; + +import com.fr.base.FRContext; +import com.fr.design.extra.exe.callback.*; +import com.fr.design.extra.exe.extratask.InstallPluginTask; +import com.fr.design.extra.exe.extratask.UpdatePluginTask; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.json.JSONObject; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.bbs.BBSPluginLogin; +import com.fr.plugin.manage.control.PluginTaskCallback; +import com.fr.plugin.manage.control.PluginTaskResult; +import com.fr.stable.ArrayUtils; +import com.fr.stable.StringUtils; +import javafx.scene.web.WebEngine; +import netscape.javascript.JSObject; +import sun.plugin2.main.server.Plugin; + +import javax.swing.*; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by ibm on 2017/5/26. + */ +public class PluginOperateUtils { + + public static void installPluginOnline(final String pluginInfo, JSCallback jsCallback) { + //下载插件 + if (!BBSPluginLogin.getInstance().hasLogin()) { + LoginCheckContext.fireLoginCheckListener(); + } + PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); + if (BBSPluginLogin.getInstance().hasLogin()) { + PluginManager.getController().download(pluginMarker, new DownloadCallback(new InstallPluginTask(pluginMarker, jsCallback), jsCallback)); + } + } + + public static void installPluginFromDisk(final String filePath, JSCallback jsCallback) { + PluginManager.getController().install(new File(filePath), new InstallFromDiskCallback(new File(filePath), jsCallback)); + } + + public static void updatePluginOnline(JSObject pluginIDs, JSCallback jsCallback) { + String[] pluginInfos = jsObjectToStringArray(pluginIDs); + if (!(BBSPluginLogin.getInstance().hasLogin())) { + LoginCheckContext.fireLoginCheckListener(); + } + if (BBSPluginLogin.getInstance().hasLogin()) { + List pluginMarkerList = new ArrayList(); + for (int i = 0; i < pluginInfos.length; i++) { + pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i])); + } + for (int i = 0; i < pluginMarkerList.size(); i++) { + try { + //todo check下此插件的最新版本 + String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarkerList.get(i).getPluginID()); + if (StringUtils.isEmpty(latestPluginInfo) || PluginConstants.CONNECTION_404.equals(latestPluginInfo)) { + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Connect_Failed"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + return; + } + JSONObject resultArr = new JSONObject(latestPluginInfo); + String latestPluginVersion = (String) resultArr.get("version"); + PluginMarker pluginMarker = pluginMarkerList.get(i); + PluginMarker toPluginMarker = PluginMarker.create(pluginMarkerList.get(i).getPluginID(), latestPluginVersion); + PluginManager.getController().download(pluginMarkerList.get(i), new DownloadCallback(new UpdatePluginTask(pluginMarker, toPluginMarker, jsCallback), jsCallback)); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + } + } + + public static void updatePluginFromDisk(final String filePath, JSCallback jsCallback) { + PluginManager.getController().update(new File(filePath), new UpdateFromDiskCallback(new File(filePath), jsCallback)); + } + + public static void setPluginActive(String pluginInfo, JSCallback jsCallback) { + PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); + PluginContext plugin = PluginManager.getContext(pluginMarker); + boolean active = !plugin.isActive(); + PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active); + if (active) { + PluginManager.getController().forbid(pluginMarker, modifyStatusCallback); + } else { + PluginManager.getController().enable(pluginMarker, modifyStatusCallback); + } + } + + public static void uninstallPlugin(final String pluginInfo, final boolean isForce, JSCallback jsCallback) { + PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); + PluginManager.getController().uninstall(pluginMarker, isForce, new UnistallPluginCallback()); + } + + private static String[] jsObjectToStringArray(JSObject obj) { + if (obj == null) { + return ArrayUtils.EMPTY_STRING_ARRAY; + } + int len = (int) obj.getMember("length"); + List list = new ArrayList<>(); + for (int i = 0; i < len; i++) { + list.add(obj.getSlot(i).toString()); + } + return list.toArray(new String[len]); + } + +} diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 8df0f7494..808eabfe1 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -5,6 +5,7 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.RestartHelper; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; +import com.fr.design.extra.exe.callback.JSCallback; import com.fr.design.gui.ilable.UILabel; import com.fr.general.FRLogger; import com.fr.general.Inter; @@ -147,8 +148,8 @@ public class PluginWebBridge { * @param callback 回调函数 */ public void installPluginOnline(final String pluginInfo, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new InstallOnlineExecutor(pluginInfo)); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.installPluginOnline(pluginInfo,jsCallback); } @@ -159,8 +160,8 @@ public class PluginWebBridge { * @param filePath 插件包的路径 */ public void installPluginFromDisk(final String filePath, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new InstallFromDiskExecutor(filePath)); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.installPluginFromDisk(filePath,jsCallback); } /** @@ -169,8 +170,8 @@ public class PluginWebBridge { * @param pluginInfo 插件信息 */ public void uninstallPlugin(final String pluginInfo, final boolean isForce, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new UninstallExecutor(pluginInfo, isForce)); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.uninstallPlugin(pluginInfo, isForce, jsCallback); } @@ -180,8 +181,8 @@ public class PluginWebBridge { * @param pluginIDs 插件集合 */ public void updatePluginOnline(JSObject pluginIDs, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new UpdateOnlineExecutor(jsObjectToStringArray(pluginIDs))); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.updatePluginOnline(pluginIDs, jsCallback); } /** @@ -190,8 +191,8 @@ public class PluginWebBridge { * @param filePath 插件包的路径 */ public void updatePluginFromDisk(String filePath, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new UpdateFromDiskExecutor(filePath)); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.updatePluginFromDisk(filePath, jsCallback); } /** @@ -200,8 +201,8 @@ public class PluginWebBridge { * @param pluginID 插件ID */ public void setPluginActive(String pluginID, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new ModifyStatusExecutor(pluginID)); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.setPluginActive(pluginID, jsCallback); } /** diff --git a/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java new file mode 100644 index 000000000..b0d4813cf --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java @@ -0,0 +1,21 @@ +package com.fr.design.extra.exe.callback; + +import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.manage.control.ProgressCallback; + +import java.io.File; + +/** + * Created by ibm on 2017/5/26. + */ +public abstract class AbstractPluginTaskCallback implements ProgressCallback{ + + protected PluginMarker pluginMarker; + protected JSCallback jsCallback; + + @Override + public void updateProgress(String description, double aProgress) { + } + + +} diff --git a/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java new file mode 100644 index 000000000..405a41528 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java @@ -0,0 +1,34 @@ +package com.fr.design.extra.exe.callback; + +import com.fr.design.extra.exe.extratask.ExtraPluginTask; +import com.fr.general.Inter; +import com.fr.plugin.manage.control.PluginTaskResult; +import com.fr.plugin.manage.control.ProgressCallback; + +import javax.swing.*; + +/** + * Created by ibm on 2017/5/26. + */ +public class DownloadCallback extends AbstractPluginTaskCallback { + private ExtraPluginTask extraPluginTask; + + public DownloadCallback(ExtraPluginTask extraPluginTask, JSCallback jsCallback) { + this.extraPluginTask = extraPluginTask; + this.jsCallback = jsCallback; + } + + @Override + public void updateProgress(String description, double aProgress) { + jsCallback.execute(String.valueOf(aProgress)); + } + + @Override + public void done(PluginTaskResult result) { + if (result.isSuccess()) { + extraPluginTask.doExtraPluginTask(); + } else { + JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java new file mode 100644 index 000000000..4c64d1426 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java @@ -0,0 +1,52 @@ +package com.fr.design.extra.exe.callback; + +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.control.PluginTaskResult; + +import javax.swing.*; +import java.io.File; + +/** + * Created by ibm on 2017/5/26. + */ +public class InstallFromDiskCallback extends AbstractPluginTaskCallback{ + private File zipFile; + public InstallFromDiskCallback(File zipFile, JSCallback jsCallback){ + this.zipFile = zipFile; + this.jsCallback = jsCallback; + } + + @Override + public void updateProgress(String description, double aProgress) { + jsCallback.execute(String.valueOf(aProgress)); + } + + + @Override + public void done(PluginTaskResult result) { + if (result.isSuccess()) { + FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); + } else if (result.errorCode() == 30) { + int rv = JOptionPane.showOptionDialog( + null, + Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")), + Inter.getLocText("FR-Designer-Plugin_Install_Dependence"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + null, + null + ); + if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { + return; + } + PluginManager.getController().install(zipFile, new InstallFromDiskCallback(zipFile, jsCallback)); +// jsCallback.execute("installDependence"); + } else { + JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java new file mode 100644 index 000000000..ef96acf72 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java @@ -0,0 +1,53 @@ +package com.fr.design.extra.exe.callback; + +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.control.PluginTaskResult; + +import javax.swing.*; + +/** + * Created by ibm on 2017/5/26. + */ +public class InstallOnlineCallback extends AbstractPluginTaskCallback { + + public InstallOnlineCallback(PluginMarker pluginMarker, JSCallback jsCallback){ + this.pluginMarker = pluginMarker; + this.jsCallback = jsCallback; + } + + @Override + public void updateProgress(String description, double aProgress) { + jsCallback.execute(String.valueOf(aProgress)); + } + + + @Override + public void done(PluginTaskResult result) { + if (result.isSuccess()) { + FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); + } else if (result.errorCode() == 30) { + int rv = JOptionPane.showOptionDialog( + null, + Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")), + Inter.getLocText("FR-Designer-Plugin_Install_Dependence"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + null, + null + ); + if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { + return; + } + //执行JS回调 + PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback)); +// jsCallback.execute("installDependence"); + } else { + JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java new file mode 100644 index 000000000..5ee99a69c --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java @@ -0,0 +1,29 @@ +package com.fr.design.extra.exe.callback; + +import javafx.scene.web.WebEngine; +import netscape.javascript.JSObject; + +/** + * Created by ibm on 2017/5/27. + */ +public class JSCallback { + private WebEngine webEngine; + private JSObject callback; + + public JSCallback(final WebEngine webEngine, final JSObject callback) { + this.webEngine = webEngine; + this.callback = callback; + } + + public void execute(String newValue) { + String fun = "(" + callback + ")(\"" + newValue + "\")"; + try { + webEngine.executeScript(fun); + } catch (Exception e) { + webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); + } + } + + +} + diff --git a/designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java new file mode 100644 index 000000000..2a22e0b90 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java @@ -0,0 +1,28 @@ +package com.fr.design.extra.exe.callback; + +import com.fr.general.Inter; +import com.fr.plugin.manage.control.PluginTaskCallback; +import com.fr.plugin.manage.control.PluginTaskResult; + +import javax.swing.*; + +/** + * Created by ibm on 2017/5/27. + */ +public class ModifyStatusCallback implements PluginTaskCallback{ + private boolean isActive; + + public ModifyStatusCallback (boolean isActive){ + this.isActive = isActive; + } + @Override + public void done(PluginTaskResult result) { + if (result.isSuccess()) { + String modifyMessage = isActive ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"); + JOptionPane.showMessageDialog(null, modifyMessage); + } else { + JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } + +} diff --git a/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java new file mode 100644 index 000000000..66282df9d --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java @@ -0,0 +1,26 @@ +package com.fr.design.extra.exe.callback; + +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.plugin.manage.control.PluginTaskCallback; +import com.fr.plugin.manage.control.PluginTaskResult; +import sun.plugin2.main.server.Plugin; + +import javax.swing.*; + +/** + * Created by ibm on 2017/5/27. + */ +public class UnistallPluginCallback implements PluginTaskCallback { + + @Override + public void done(PluginTaskResult result) { + if (result.isSuccess()) { + FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Success")); + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); + } else { + FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Failed")); + JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java new file mode 100644 index 000000000..e666c8e81 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java @@ -0,0 +1,53 @@ +package com.fr.design.extra.exe.callback; + +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.general.jsqlparser.expression.StringValue; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.control.PluginTaskResult; + +import javax.swing.*; +import java.io.File; + +/** + * Created by ibm on 2017/5/27. + */ +public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { + private File zipFile; + + public UpdateFromDiskCallback(File zipFile,JSCallback jsCallback) { + this.zipFile = zipFile; + this.jsCallback = jsCallback; + } + + @Override + public void updateProgress(String description, double aProgress) { + jsCallback.execute(String.valueOf(aProgress)); + } + + + @Override + public void done(PluginTaskResult result) { + if (result.isSuccess()) { + FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); + } else if (result.errorCode() == 30) { + int rv = JOptionPane.showOptionDialog( + null, + Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")), + Inter.getLocText("FR-Designer-Plugin_Install_Dependence"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + null, + null + ); + if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { + return; + } + PluginManager.getController().update(zipFile, new UpdateFromDiskCallback(zipFile, jsCallback)); + } else { + JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java new file mode 100644 index 000000000..7d709e935 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java @@ -0,0 +1,55 @@ +package com.fr.design.extra.exe.callback; + +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.error.PluginErrorCode; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.control.PluginTaskResult; + +import javax.swing.*; + +/** + * Created by ibm on 2017/5/26. + */ +public class UpdateOnlineCallback extends AbstractPluginTaskCallback { + public PluginMarker toPluginMarker; + + + public UpdateOnlineCallback(PluginMarker pluginMarker , PluginMarker toPluginMarker, JSCallback jsCallback) { + this.pluginMarker = pluginMarker; + this.toPluginMarker = toPluginMarker; + this.jsCallback = jsCallback; + } + + @Override + public void updateProgress(String description, double aProgress) { + jsCallback.execute(String.valueOf(aProgress)); + } + + @Override + public void done(PluginTaskResult result) { + if (result.isSuccess()) { + FRLogger.getLogger().info("更新成功"); + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); + } else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) { + int rv = JOptionPane.showOptionDialog( + null, + Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")), + Inter.getLocText("FR-Designer-Plugin_Install_Dependence"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + null, + null + ); + if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { + return; + } + PluginManager.getController().update(pluginMarker, toPluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, jsCallback)); + } else { + FRLogger.getLogger().info("更新失败"); + JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/extratask/ExtraPluginTask.java b/designer_base/src/com/fr/design/extra/exe/extratask/ExtraPluginTask.java new file mode 100644 index 000000000..834d59e38 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/extratask/ExtraPluginTask.java @@ -0,0 +1,10 @@ +package com.fr.design.extra.exe.extratask; + + +/** + * Created by ibm on 2017/5/27. + */ +public interface ExtraPluginTask { + + void doExtraPluginTask(); +} diff --git a/designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java b/designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java new file mode 100644 index 000000000..4ae1fe381 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java @@ -0,0 +1,25 @@ +package com.fr.design.extra.exe.extratask; + + +import com.fr.design.extra.exe.callback.InstallOnlineCallback; +import com.fr.design.extra.exe.callback.JSCallback; +import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.manage.PluginManager; + +import javax.swing.*; + +/** + * Created by ibm on 2017/5/27. + */ +public class InstallPluginTask implements ExtraPluginTask{ + public PluginMarker pluginMarker; + public JSCallback jsCallback; + public InstallPluginTask(PluginMarker pluginMarker, JSCallback jsCallback){ + this.pluginMarker = pluginMarker; + this.jsCallback = jsCallback; + } + @Override + public void doExtraPluginTask() { + PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback)); + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java b/designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java new file mode 100644 index 000000000..c79ea114a --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java @@ -0,0 +1,28 @@ +package com.fr.design.extra.exe.extratask; + +import com.fr.design.extra.exe.callback.JSCallback; +import com.fr.design.extra.exe.callback.UpdateOnlineCallback; +import com.fr.form.ui.WaterMark; +import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.manage.PluginManager; + +/** + * Created by ibm on 2017/5/27. + */ +public class UpdatePluginTask implements ExtraPluginTask { + + public PluginMarker pluginMarker; + public PluginMarker toPluginMarker; + public JSCallback jsCallback; + + public UpdatePluginTask(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback){ + this.pluginMarker = pluginMarker; + this.toPluginMarker = toPluginMarker; + this.jsCallback = jsCallback; + } + + @Override + public void doExtraPluginTask() { + PluginManager.getController().update(pluginMarker, toPluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, jsCallback)); + } +}