diff --git a/designer_base/src/com/fr/design/extra/PluginOperateUtils.java b/designer_base/src/com/fr/design/extra/PluginOperateUtils.java index 4f2a2e2043..f867574e66 100644 --- a/designer_base/src/com/fr/design/extra/PluginOperateUtils.java +++ b/designer_base/src/com/fr/design/extra/PluginOperateUtils.java @@ -16,14 +16,11 @@ import com.fr.plugin.manage.PluginManager; import com.fr.plugin.manage.bbs.BBSPluginLogin; import com.fr.plugin.manage.control.PluginTaskCallback; import com.fr.plugin.view.PluginView; -import com.fr.stable.ArrayUtils; import com.fr.stable.StringUtils; -import netscape.javascript.JSObject; import org.json.JSONArray; import javax.swing.*; import java.io.File; -import java.util.ArrayList; import java.util.List; @@ -79,7 +76,7 @@ public class PluginOperateUtils { PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); PluginContext plugin = PluginManager.getContext(pluginMarker); boolean active = plugin.isActive(); - PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active); + PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active, jsCallback); if (active) { PluginManager.getController().forbid(pluginMarker, modifyStatusCallback); } else { @@ -89,7 +86,7 @@ public class PluginOperateUtils { public static void uninstallPlugin(final String pluginInfo, final boolean isForce, JSCallback jsCallback) { PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); - PluginManager.getController().uninstall(pluginMarker, isForce, new UnistallPluginCallback()); + PluginManager.getController().uninstall(pluginMarker, isForce, new UninstallPluginCallback(jsCallback)); } public static void readUpdateOnline(JSCallback jsCallback) { @@ -120,30 +117,36 @@ public class PluginOperateUtils { } public static void getPluginFromStore(String category, String seller, String fee, JSCallback jsCallback) { - String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist"); - if (StringUtils.isNotBlank(plistUrl)) { - StringBuilder url = new StringBuilder(); - url.append(plistUrl); - if (StringUtils.isNotBlank(category)) { - url.append("&cid=").append(category.split("-")[1]); - } - if (StringUtils.isNotBlank(seller)) { - url.append("&seller=").append(seller.split("-")[1]); - } - if (StringUtils.isNotBlank(fee)) { - url.append("&fee=").append(fee.split("-")[1]); - } - try { - HttpClient httpClient = new HttpClient(url.toString()); - String result = httpClient.getResponseText(); - jsCallback.execute(result); - } catch (Exception e) { - FRLogger.getLogger().error(e.getMessage()); + new Thread(new Runnable() { + @Override + public void run() { + String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist"); + if (StringUtils.isNotBlank(plistUrl)) { + StringBuilder url = new StringBuilder(); + url.append(plistUrl); + if (StringUtils.isNotBlank(category)) { + url.append("&cid=").append(category.split("-")[1]); + } + if (StringUtils.isNotBlank(seller)) { + url.append("&seller=").append(seller.split("-")[1]); + } + if (StringUtils.isNotBlank(fee)) { + url.append("&fee=").append(fee.split("-")[1]); + } + try { + HttpClient httpClient = new HttpClient(url.toString()); + String result = httpClient.getResponseText(); + jsCallback.execute(result); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } else { + String result = PluginConstants.CONNECTION_404; + jsCallback.execute(result); + } } - } else { - String result = PluginConstants.CONNECTION_404; - jsCallback.execute(result); - } + }).start(); + } public static void getPluginCategories(JSCallback jsCallback) { @@ -176,4 +179,4 @@ public class PluginOperateUtils { && StringUtils.isNotEmpty(pluginView.getEnvVersion()); } -} + } 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 index 93ea0fe224..6c5e3eadf7 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java @@ -12,6 +12,7 @@ import javax.swing.*; public class DownloadCallback extends AbstractPluginTaskCallback { private ExtraPluginTask extraPluginTask; private JSCallback jsCallback; + private static int HUNDRED_PERCENT = 100; public DownloadCallback(final ExtraPluginTask extraPluginTask, final JSCallback jsCallback) { this.extraPluginTask = extraPluginTask; @@ -20,12 +21,11 @@ public class DownloadCallback extends AbstractPluginTaskCallback { @Override public void updateProgress(String description, double aProgress) { - jsCallback.execute(String.valueOf(aProgress)); + jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); } @Override public void done(PluginTaskResult result) { - jsCallback.execute("done"); if (result.isSuccess()) { extraPluginTask.doExtraPluginTask(); } else { 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 index aa74e9c02c..07bbf7a3f5 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java @@ -15,6 +15,7 @@ import java.io.File; public class InstallFromDiskCallback extends AbstractPluginTaskCallback { private File zipFile; private JSCallback jsCallback; + private static int HUNDRED_PERCENT = 100; public InstallFromDiskCallback(final File zipFile, final JSCallback jsCallback) { this.zipFile = zipFile; @@ -23,13 +24,13 @@ public class InstallFromDiskCallback extends AbstractPluginTaskCallback { @Override public void updateProgress(String description, double aProgress) { - jsCallback.execute(String.valueOf(aProgress)); + jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); } @Override public void done(PluginTaskResult result) { - jsCallback.execute("done"); + jsCallback.execute("success"); if (result.isSuccess()) { FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); 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 index a1ee0ee4c5..16fcae7430 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java @@ -14,7 +14,7 @@ import javax.swing.*; */ public class InstallOnlineCallback extends AbstractPluginTaskCallback { protected JSCallback jsCallback; - + private static int HUNDRED_PERCENT = 100; public InstallOnlineCallback(PluginMarker pluginMarker, JSCallback jsCallback){ this.pluginMarker = pluginMarker; @@ -23,13 +23,13 @@ public class InstallOnlineCallback extends AbstractPluginTaskCallback { @Override public void updateProgress(String description, double aProgress) { - jsCallback.execute(String.valueOf(aProgress)); + jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); } @Override public void done(PluginTaskResult result) { - jsCallback.execute("done"); + jsCallback.execute("success"); if (result.isSuccess()) { FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); 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 index 8204a88eb5..4d2fb7adec 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java @@ -1,39 +1,51 @@ package com.fr.design.extra.exe.callback; import com.fr.stable.StringUtils; +import javafx.application.Platform; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.concurrent.Task; 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 class JSCallback extends Task { + public JSCallback(final WebEngine webEngine, final JSObject callback) { - this.webEngine = webEngine; - this.callback = callback; + init(webEngine, callback); } - public void execute(String newValue) { - String fun = "(" + callback + ")(\"" + trimText(newValue) + "\")"; - try { - webEngine.executeScript(fun); - } catch (Exception e) { - webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); - } + public void init(final WebEngine webEngine, final JSObject callback){ + messageProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, String oldValue, String newValue) { + Platform.runLater(new Runnable() { + @Override + public void run() { + String fun = "(" + callback + ")(\"" + trimText(newValue) + "\")"; + try { + webEngine.executeScript(fun); + } catch (Exception e) { + webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); + } + } + }); + } + }); + } + @Override + protected T call() throws Exception { + return null; } - public void execute(double progress) { - String fun = "(" + callback + ")(\"" + trimText(String.valueOf(progress)) + "\")"; - try { - webEngine.executeScript(fun); - } catch (Exception e) { - webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); - } + public void execute(String newValue) { + updateMessage(newValue); } + /** * vito:由于使用webEngine.executeScript("(" + callback + ")(\"" + newValue + "\")") * 执行脚本,所以原来规范的json格式也会在拼接字符串后可能抛出参数异常,需要转换掉一些会造成错误的特殊字符, 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 index 2a22e0b907..a02f7628a7 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java @@ -11,13 +11,16 @@ import javax.swing.*; */ public class ModifyStatusCallback implements PluginTaskCallback{ private boolean isActive; + private JSCallback jsCallback; - public ModifyStatusCallback (boolean isActive){ + public ModifyStatusCallback (boolean isActive, JSCallback jsCallback){ this.isActive = isActive; + this.jsCallback = jsCallback; } @Override public void done(PluginTaskResult result) { if (result.isSuccess()) { + jsCallback.execute("success"); String modifyMessage = isActive ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"); JOptionPane.showMessageDialog(null, modifyMessage); } else { diff --git a/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/UninstallPluginCallback.java similarity index 77% rename from designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java rename to designer_base/src/com/fr/design/extra/exe/callback/UninstallPluginCallback.java index 851c9e4e44..983a2a0c5e 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/UninstallPluginCallback.java @@ -10,11 +10,17 @@ import javax.swing.*; /** * Created by ibm on 2017/5/27. */ -public class UnistallPluginCallback implements PluginTaskCallback { +public class UninstallPluginCallback implements PluginTaskCallback { + private JSCallback jsCallback; + + public UninstallPluginCallback(JSCallback jsCallback){ + this.jsCallback = jsCallback; + } @Override public void done(PluginTaskResult result) { if (result.isSuccess()) { + jsCallback.execute("success"); FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Success")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); } else { 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 index 0f79a16147..9a4e0d093b 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java @@ -14,7 +14,8 @@ import java.io.File; */ public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { private File zipFile; - protected JSCallback jsCallback; + private JSCallback jsCallback; + private static int HUNDRED_PERCENT = 100; public UpdateFromDiskCallback(File zipFile, JSCallback jsCallback) { this.zipFile = zipFile; @@ -23,13 +24,13 @@ public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { @Override public void updateProgress(String description, double aProgress) { - jsCallback.execute(String.valueOf(aProgress)); + jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); } @Override public void done(PluginTaskResult result) { - jsCallback.execute("done"); + jsCallback.execute("success"); if (result.isSuccess()) { FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); 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 index 65a71a80c5..c139cea2c4 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java @@ -15,6 +15,7 @@ import javax.swing.*; public class UpdateOnlineCallback extends AbstractPluginTaskCallback { public PluginMarker toPluginMarker; protected JSCallback jsCallback; + private static int HUNDRED_PERCENT = 100; public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) { this.pluginMarker = pluginMarker; @@ -24,12 +25,12 @@ public class UpdateOnlineCallback extends AbstractPluginTaskCallback { @Override public void updateProgress(String description, double aProgress) { - jsCallback.execute(String.valueOf(aProgress)); + jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%")); } @Override public void done(PluginTaskResult result) { - jsCallback.execute("done"); + jsCallback.execute("success"); if (result.isSuccess()) { FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));