Browse Source

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

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

61
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,30 +117,36 @@ 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) {
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist"); new Thread(new Runnable() {
if (StringUtils.isNotBlank(plistUrl)) { @Override
StringBuilder url = new StringBuilder(); public void run() {
url.append(plistUrl); String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist");
if (StringUtils.isNotBlank(category)) { if (StringUtils.isNotBlank(plistUrl)) {
url.append("&cid=").append(category.split("-")[1]); StringBuilder url = new StringBuilder();
} url.append(plistUrl);
if (StringUtils.isNotBlank(seller)) { if (StringUtils.isNotBlank(category)) {
url.append("&seller=").append(seller.split("-")[1]); url.append("&cid=").append(category.split("-")[1]);
} }
if (StringUtils.isNotBlank(fee)) { if (StringUtils.isNotBlank(seller)) {
url.append("&fee=").append(fee.split("-")[1]); url.append("&seller=").append(seller.split("-")[1]);
} }
try { if (StringUtils.isNotBlank(fee)) {
HttpClient httpClient = new HttpClient(url.toString()); url.append("&fee=").append(fee.split("-")[1]);
String result = httpClient.getResponseText(); }
jsCallback.execute(result); try {
} catch (Exception e) { HttpClient httpClient = new HttpClient(url.toString());
FRLogger.getLogger().error(e.getMessage()); 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 { }).start();
String result = PluginConstants.CONNECTION_404;
jsCallback.execute(result);
}
} }
public static void getPluginCategories(JSCallback jsCallback) { public static void getPluginCategories(JSCallback jsCallback) {
@ -176,4 +179,4 @@ public class PluginOperateUtils {
&& StringUtils.isNotEmpty(pluginView.getEnvVersion()); && 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 { 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"));

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

@ -1,39 +1,51 @@
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){
String fun = "(" + callback + ")(\"" + trimText(newValue) + "\")"; messageProperty().addListener(new ChangeListener<String>() {
try { @Override
webEngine.executeScript(fun); public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
} catch (Exception e) { Platform.runLater(new Runnable() {
webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); @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) { public void execute(String newValue) {
String fun = "(" + callback + ")(\"" + trimText(String.valueOf(progress)) + "\")"; updateMessage(newValue);
try {
webEngine.executeScript(fun);
} catch (Exception e) {
webEngine.executeScript("alert(\"" + e.getMessage() + "\")");
}
} }
/** /**
* 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