forked from fanruan/design
kerry
8 years ago
14 changed files with 538 additions and 12 deletions
@ -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<PluginMarker> pluginMarkerList = new ArrayList<PluginMarker>(); |
||||
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<String> list = new ArrayList<>(); |
||||
for (int i = 0; i < len; i++) { |
||||
list.add(obj.getSlot(i).toString()); |
||||
} |
||||
return list.toArray(new String[len]); |
||||
} |
||||
|
||||
} |
@ -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) { |
||||
} |
||||
|
||||
|
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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() + "\")"); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
||||
|
@ -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); |
||||
} |
||||
} |
||||
|
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
package com.fr.design.extra.exe.extratask; |
||||
|
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/27. |
||||
*/ |
||||
public interface ExtraPluginTask { |
||||
|
||||
void doExtraPluginTask(); |
||||
} |
@ -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)); |
||||
} |
||||
} |
@ -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)); |
||||
} |
||||
} |
Loading…
Reference in new issue