Browse Source

REPORT-2354 将平台的插件管理和设计器的插件管理统一起来

master
kerry 8 years ago
parent
commit
3a18665323
  1. 13
      designer_base/src/com/fr/design/extra/PluginOperateUtils.java
  2. 4
      designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java
  3. 5
      designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java
  4. 6
      designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java
  5. 38
      designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java
  6. 5
      designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java
  7. 8
      designer_base/src/com/fr/design/extra/exe/callback/UninstallPluginCallback.java
  8. 7
      designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java
  9. 5
      designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java

13
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.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskCallback; import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.view.PluginView; import com.fr.plugin.view.PluginView;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import netscape.javascript.JSObject;
import org.json.JSONArray; import org.json.JSONArray;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -79,7 +76,7 @@ public class PluginOperateUtils {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
PluginContext plugin = PluginManager.getContext(pluginMarker); PluginContext plugin = PluginManager.getContext(pluginMarker);
boolean active = plugin.isActive(); boolean active = plugin.isActive();
PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active); PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active, jsCallback);
if (active) { if (active) {
PluginManager.getController().forbid(pluginMarker, modifyStatusCallback); PluginManager.getController().forbid(pluginMarker, modifyStatusCallback);
} else { } else {
@ -89,7 +86,7 @@ public class PluginOperateUtils {
public static void uninstallPlugin(final String pluginInfo, final boolean isForce, JSCallback jsCallback) { public static void uninstallPlugin(final String pluginInfo, final boolean isForce, JSCallback jsCallback) {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); 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) { public static void readUpdateOnline(JSCallback jsCallback) {
@ -120,6 +117,9 @@ public class PluginOperateUtils {
} }
public static void getPluginFromStore(String category, String seller, String fee, JSCallback jsCallback) { public static void getPluginFromStore(String category, String seller, String fee, JSCallback jsCallback) {
new Thread(new Runnable() {
@Override
public void run() {
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist"); String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist");
if (StringUtils.isNotBlank(plistUrl)) { if (StringUtils.isNotBlank(plistUrl)) {
StringBuilder url = new StringBuilder(); StringBuilder url = new StringBuilder();
@ -145,6 +145,9 @@ public class PluginOperateUtils {
jsCallback.execute(result); jsCallback.execute(result);
} }
} }
}).start();
}
public static void getPluginCategories(JSCallback jsCallback) { public static void getPluginCategories(JSCallback jsCallback) {
String result; String result;

4
designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java

@ -12,6 +12,7 @@ import javax.swing.*;
public class DownloadCallback extends AbstractPluginTaskCallback { public class DownloadCallback extends AbstractPluginTaskCallback {
private ExtraPluginTask extraPluginTask; private ExtraPluginTask extraPluginTask;
private JSCallback jsCallback; private JSCallback jsCallback;
private static int HUNDRED_PERCENT = 100;
public DownloadCallback(final ExtraPluginTask extraPluginTask, final JSCallback jsCallback) { public DownloadCallback(final ExtraPluginTask extraPluginTask, final JSCallback jsCallback) {
this.extraPluginTask = extraPluginTask; this.extraPluginTask = extraPluginTask;
@ -20,12 +21,11 @@ public class DownloadCallback extends AbstractPluginTaskCallback {
@Override @Override
public void updateProgress(String description, double aProgress) { public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress)); jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%"));
} }
@Override @Override
public void done(PluginTaskResult result) { public void done(PluginTaskResult result) {
jsCallback.execute("done");
if (result.isSuccess()) { if (result.isSuccess()) {
extraPluginTask.doExtraPluginTask(); extraPluginTask.doExtraPluginTask();
} else { } else {

5
designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java

@ -15,6 +15,7 @@ import java.io.File;
public class InstallFromDiskCallback extends AbstractPluginTaskCallback { public class InstallFromDiskCallback extends AbstractPluginTaskCallback {
private File zipFile; private File zipFile;
private JSCallback jsCallback; private JSCallback jsCallback;
private static int HUNDRED_PERCENT = 100;
public InstallFromDiskCallback(final File zipFile, final JSCallback jsCallback) { public InstallFromDiskCallback(final File zipFile, final JSCallback jsCallback) {
this.zipFile = zipFile; this.zipFile = zipFile;
@ -23,13 +24,13 @@ public class InstallFromDiskCallback extends AbstractPluginTaskCallback {
@Override @Override
public void updateProgress(String description, double aProgress) { public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress)); jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%"));
} }
@Override @Override
public void done(PluginTaskResult result) { public void done(PluginTaskResult result) {
jsCallback.execute("done"); jsCallback.execute("success");
if (result.isSuccess()) { if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));

6
designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java

@ -14,7 +14,7 @@ import javax.swing.*;
*/ */
public class InstallOnlineCallback extends AbstractPluginTaskCallback { public class InstallOnlineCallback extends AbstractPluginTaskCallback {
protected JSCallback jsCallback; protected JSCallback jsCallback;
private static int HUNDRED_PERCENT = 100;
public InstallOnlineCallback(PluginMarker pluginMarker, JSCallback jsCallback){ public InstallOnlineCallback(PluginMarker pluginMarker, JSCallback jsCallback){
this.pluginMarker = pluginMarker; this.pluginMarker = pluginMarker;
@ -23,13 +23,13 @@ public class InstallOnlineCallback extends AbstractPluginTaskCallback {
@Override @Override
public void updateProgress(String description, double aProgress) { public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress)); jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%"));
} }
@Override @Override
public void done(PluginTaskResult result) { public void done(PluginTaskResult result) {
jsCallback.execute("done"); jsCallback.execute("success");
if (result.isSuccess()) { if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));

38
designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java

@ -1,22 +1,30 @@
package com.fr.design.extra.exe.callback; package com.fr.design.extra.exe.callback;
import com.fr.stable.StringUtils; 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 javafx.scene.web.WebEngine;
import netscape.javascript.JSObject; import netscape.javascript.JSObject;
/** /**
* Created by ibm on 2017/5/27. * Created by ibm on 2017/5/27.
*/ */
public class JSCallback { public class JSCallback<T> extends Task<T> {
private WebEngine webEngine;
private JSObject callback;
public JSCallback(final WebEngine webEngine, final JSObject callback) { public JSCallback(final WebEngine webEngine, final JSObject callback) {
this.webEngine = webEngine; init(webEngine, callback);
this.callback = callback;
} }
public void execute(String newValue) { public void init(final WebEngine webEngine, final JSObject callback){
messageProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
Platform.runLater(new Runnable() {
@Override
public void run() {
String fun = "(" + callback + ")(\"" + trimText(newValue) + "\")"; String fun = "(" + callback + ")(\"" + trimText(newValue) + "\")";
try { try {
webEngine.executeScript(fun); webEngine.executeScript(fun);
@ -24,16 +32,20 @@ public class JSCallback {
webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); webEngine.executeScript("alert(\"" + e.getMessage() + "\")");
} }
} }
});
public void execute(double progress) { }
String fun = "(" + callback + ")(\"" + trimText(String.valueOf(progress)) + "\")"; });
try { }
webEngine.executeScript(fun); @Override
} catch (Exception e) { protected T call() throws Exception {
webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); return null;
} }
public void execute(String newValue) {
updateMessage(newValue);
} }
/** /**
* vito:由于使用webEngine.executeScript("(" + callback + ")(\"" + newValue + "\")") * vito:由于使用webEngine.executeScript("(" + callback + ")(\"" + newValue + "\")")
* 执行脚本所以原来规范的json格式也会在拼接字符串后可能抛出参数异常需要转换掉一些会造成错误的特殊字符 * 执行脚本所以原来规范的json格式也会在拼接字符串后可能抛出参数异常需要转换掉一些会造成错误的特殊字符

5
designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java

@ -11,13 +11,16 @@ import javax.swing.*;
*/ */
public class ModifyStatusCallback implements PluginTaskCallback{ public class ModifyStatusCallback implements PluginTaskCallback{
private boolean isActive; private boolean isActive;
private JSCallback jsCallback;
public ModifyStatusCallback (boolean isActive){ public ModifyStatusCallback (boolean isActive, JSCallback jsCallback){
this.isActive = isActive; this.isActive = isActive;
this.jsCallback = jsCallback;
} }
@Override @Override
public void done(PluginTaskResult result) { public void done(PluginTaskResult result) {
if (result.isSuccess()) { 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"); String modifyMessage = isActive ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled");
JOptionPane.showMessageDialog(null, modifyMessage); JOptionPane.showMessageDialog(null, modifyMessage);
} else { } else {

8
designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java → 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. * 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 @Override
public void done(PluginTaskResult result) { public void done(PluginTaskResult result) {
if (result.isSuccess()) { if (result.isSuccess()) {
jsCallback.execute("success");
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Success")); FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else { } else {

7
designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java

@ -14,7 +14,8 @@ import java.io.File;
*/ */
public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { public class UpdateFromDiskCallback extends AbstractPluginTaskCallback {
private File zipFile; private File zipFile;
protected JSCallback jsCallback; private JSCallback jsCallback;
private static int HUNDRED_PERCENT = 100;
public UpdateFromDiskCallback(File zipFile, JSCallback jsCallback) { public UpdateFromDiskCallback(File zipFile, JSCallback jsCallback) {
this.zipFile = zipFile; this.zipFile = zipFile;
@ -23,13 +24,13 @@ public class UpdateFromDiskCallback extends AbstractPluginTaskCallback {
@Override @Override
public void updateProgress(String description, double aProgress) { public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress)); jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%"));
} }
@Override @Override
public void done(PluginTaskResult result) { public void done(PluginTaskResult result) {
jsCallback.execute("done"); jsCallback.execute("success");
if (result.isSuccess()) { if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));

5
designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java

@ -15,6 +15,7 @@ import javax.swing.*;
public class UpdateOnlineCallback extends AbstractPluginTaskCallback { public class UpdateOnlineCallback extends AbstractPluginTaskCallback {
public PluginMarker toPluginMarker; public PluginMarker toPluginMarker;
protected JSCallback jsCallback; protected JSCallback jsCallback;
private static int HUNDRED_PERCENT = 100;
public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) { public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) {
this.pluginMarker = pluginMarker; this.pluginMarker = pluginMarker;
@ -24,12 +25,12 @@ public class UpdateOnlineCallback extends AbstractPluginTaskCallback {
@Override @Override
public void updateProgress(String description, double aProgress) { public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress)); jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%"));
} }
@Override @Override
public void done(PluginTaskResult result) { public void done(PluginTaskResult result) {
jsCallback.execute("done"); jsCallback.execute("success");
if (result.isSuccess()) { if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success")); FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));

Loading…
Cancel
Save