Browse Source

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

master
kerry 8 years ago
parent
commit
3a18665323
  1. 15
      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

15
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,6 +117,9 @@ public class PluginOperateUtils {
}
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");
if (StringUtils.isNotBlank(plistUrl)) {
StringBuilder url = new StringBuilder();
@ -145,6 +145,9 @@ public class PluginOperateUtils {
jsCallback.execute(result);
}
}
}).start();
}
public static void getPluginCategories(JSCallback jsCallback) {
String result;
@ -176,4 +179,4 @@ public class PluginOperateUtils {
&& StringUtils.isNotEmpty(pluginView.getEnvVersion());
}
}
}

4
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 {

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 {
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"));

6
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"));

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

@ -1,22 +1,30 @@
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<T> extends Task<T> {
public JSCallback(final WebEngine webEngine, final JSObject callback) {
this.webEngine = webEngine;
this.callback = callback;
init(webEngine, 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) + "\")";
try {
webEngine.executeScript(fun);
@ -24,16 +32,20 @@ public class JSCallback {
webEngine.executeScript("alert(\"" + e.getMessage() + "\")");
}
}
public void execute(double progress) {
String fun = "(" + callback + ")(\"" + trimText(String.valueOf(progress)) + "\")";
try {
webEngine.executeScript(fun);
} catch (Exception e) {
webEngine.executeScript("alert(\"" + e.getMessage() + "\")");
});
}
});
}
@Override
protected T call() throws Exception {
return null;
}
public void execute(String newValue) {
updateMessage(newValue);
}
/**
* vito:由于使用webEngine.executeScript("(" + callback + ")(\"" + newValue + "\")")
* 执行脚本所以原来规范的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{
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 {

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.
*/
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 {

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 {
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"));

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 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"));

Loading…
Cancel
Save