Browse Source
* commit '68c33117566ef88ba9ff9c8f1d308c838cb57c1a': 修改PMD 修改PMD 避免魔术数 REPORT-235 report-2354 整合后台插件操作代码 REPORT-2354 设计器插件操作部分 REPORT-2354 设计器插件操作部分master
kerry
8 years ago
28 changed files with 1145 additions and 301 deletions
@ -0,0 +1,15 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/25. |
||||
*/ |
||||
public class PluginConstants { |
||||
public static final int BYTES_NUM = 1024; |
||||
private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp"; |
||||
public static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download"; |
||||
//插件依赖的下载位置
|
||||
public static final String DEPENDENCE_DOWNLOAD_PATH = System.getProperty("user.dir") + "/download/dependence"; |
||||
public static final String TEMP_FILE = "temp.zip"; |
||||
public static final String CONNECTION_404 = "404"; |
||||
|
||||
} |
@ -0,0 +1,192 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.DesignerEnvManager; |
||||
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.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
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 org.json.JSONArray; |
||||
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()); |
||||
} |
||||
|
||||
public static void readUpdateOnline(JSCallback jsCallback){ |
||||
try { |
||||
String [] plugins = PluginReaderForDesigner.readPluginsForUpdate(); |
||||
JSONArray jsonArray = new JSONArray(); |
||||
for (String plugin : plugins) { |
||||
org.json.JSONObject jsonObject = new org.json.JSONObject(); |
||||
jsonObject.put("pluginid", plugin); |
||||
jsonArray.put(jsonObject); |
||||
} |
||||
String result = jsonArray.toString(); |
||||
jsCallback.execute(result); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
|
||||
} |
||||
|
||||
public static void searchPlugin(String keyword, JSCallback jsCallback) { |
||||
try { |
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.plist") + "&keyword=" + keyword); |
||||
String result = httpClient.getResponseText(); |
||||
jsCallback.execute(result); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
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()); |
||||
} |
||||
} else { |
||||
String result = PluginConstants.CONNECTION_404; |
||||
jsCallback.execute(result); |
||||
} |
||||
} |
||||
|
||||
public static void getPluginCategories(JSCallback jsCallback){ |
||||
String result; |
||||
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category"); |
||||
if (url != null) { |
||||
HttpClient httpClient = new HttpClient(url); |
||||
result = httpClient.getResponseText(); |
||||
} else { |
||||
result = PluginConstants.CONNECTION_404; |
||||
} |
||||
jsCallback.execute(result); |
||||
} |
||||
|
||||
public static void getLoginInfo(JSCallback jsCallback){ |
||||
String username = BBSPluginLogin.getInstance().getUserInfo().getUserName(); |
||||
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName(); |
||||
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) { |
||||
return; |
||||
}else { |
||||
String result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername; |
||||
jsCallback.execute(result); |
||||
} |
||||
} |
||||
|
||||
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,60 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.general.GeneralUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.manage.PluginManager; |
||||
import com.fr.stable.EncodeConstants; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.net.URLDecoder; |
||||
import java.util.HashMap; |
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/25. |
||||
*/ |
||||
public class PluginReaderForDesigner { |
||||
private static Set<String> pluginsToUpdate = new HashSet<String>(); |
||||
|
||||
/** |
||||
* 从插件商店服务器读取插件信息,以JSON形式返回 |
||||
* |
||||
* @return 插件信息 |
||||
*/ |
||||
public static String[] readPluginsForUpdate() throws Exception { |
||||
String resText = null; |
||||
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.update"); |
||||
if (StringUtils.isNotEmpty(url)) { |
||||
HashMap<String, String> para = new HashMap<String, String>(); |
||||
para.put("plugins", PluginUtils.transPluginsToString(PluginManager.getContexts())); |
||||
//只有当前设计器的jar高于插件新版本需要的jarTime时, 才提示更新该插件.
|
||||
para.put("jarTime", GeneralUtils.readBuildNO()); |
||||
HttpClient httpClient = new HttpClient(url, para); |
||||
resText = httpClient.getResponseText(); |
||||
String charSet = EncodeConstants.ENCODING_UTF_8; |
||||
resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); |
||||
} |
||||
if (StringUtils.isNotEmpty(resText)) { |
||||
try { |
||||
pluginsToUpdate.clear(); |
||||
JSONArray jsonArray = new JSONArray(resText); |
||||
for (int i = 0, size = jsonArray.length(); i < size; i++) { |
||||
JSONObject jo = jsonArray.optJSONObject(i); |
||||
String id = jo.optString("id"); |
||||
if(StringUtils.isNotEmpty(id)){ |
||||
pluginsToUpdate.add(jo.optString("id", "")); |
||||
} |
||||
} |
||||
} catch (JSONException e) { |
||||
throw new Exception(Inter.getLocText("FS-Web-Plugin_Read_Plugin_List_Error")); |
||||
} |
||||
} |
||||
return pluginsToUpdate.toArray(new String[pluginsToUpdate.size()]); |
||||
} |
||||
} |
@ -0,0 +1,107 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
|
||||
import com.fr.stable.EncodeConstants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.InputStream; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URLDecoder; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by ibm on 2017/5/25. |
||||
*/ |
||||
public class PluginUtils { |
||||
|
||||
|
||||
public static PluginMarker createPluginMarker(String pluginInfo) { |
||||
//todo 判空
|
||||
String[] plugin = pluginInfo.split("_"); |
||||
PluginMarker pluginMarker = PluginMarker.create(plugin[0], plugin[1]); |
||||
return pluginMarker; |
||||
} |
||||
|
||||
public static String getLatestPluginInfo(String pluginID){ |
||||
String result = ""; |
||||
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.searchAPI"); |
||||
if (StringUtils.isNotEmpty(plistUrl)) { |
||||
StringBuilder url = new StringBuilder(plistUrl); |
||||
if (StringUtils.isNotBlank(pluginID)) { |
||||
url.append("?keyword=").append(pluginID); |
||||
} |
||||
try { |
||||
HttpClient httpClient = new HttpClient(url.toString()); |
||||
result = httpClient.getResponseText(); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} else { |
||||
result = PluginConstants.CONNECTION_404; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
public static String transPluginsToString(List<PluginContext> plugins) throws Exception { |
||||
JSONArray jsonArray = new JSONArray(); |
||||
for (PluginContext plugin : plugins) { |
||||
JSONObject jo = new JSONObject(); |
||||
jo.put("id", plugin.getID()); |
||||
jo.put("version", plugin.getVersion()); |
||||
jsonArray.put(jo); |
||||
} |
||||
return jsonArray.toString(); |
||||
} |
||||
|
||||
public static void downloadShopScripts(String id, String username, String password, Process<Double> p) throws Exception{ |
||||
HttpClient httpClient = new HttpClient(getDownloadPath(id, username, password)); |
||||
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
||||
int totalSize = httpClient.getContentLength(); |
||||
InputStream reader = httpClient.getResponseStream(); |
||||
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); |
||||
StableUtils.makesureFileExist(new File(temp)); |
||||
FileOutputStream writer = new FileOutputStream(temp); |
||||
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; |
||||
int bytesRead = 0; |
||||
int totalBytesRead = 0; |
||||
|
||||
while ((bytesRead = reader.read(buffer)) > 0) { |
||||
writer.write(buffer, 0, bytesRead); |
||||
buffer = new byte[PluginConstants.BYTES_NUM]; |
||||
totalBytesRead += bytesRead; |
||||
p.process(totalBytesRead / (double) totalSize); |
||||
} |
||||
reader.close(); |
||||
writer.flush(); |
||||
writer.close(); |
||||
} else { |
||||
throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Connect_Server_Error")); |
||||
} |
||||
} |
||||
|
||||
private static String getDownloadPath(String id, String username, String password) throws Exception { |
||||
HashMap<String, String> map = new HashMap<String, String>(); |
||||
map.put("id", id); |
||||
map.put("username", username); |
||||
map.put("password", password); |
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.download"), map); |
||||
String resText = httpClient.getResponseText(); |
||||
String charSet = EncodeConstants.ENCODING_UTF_8; |
||||
resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); |
||||
|
||||
return resText; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.manage.control.ProgressCallback; |
||||
|
||||
|
||||
/** |
||||
* 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,33 @@
|
||||
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 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,53 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.plugin.error.PluginErrorCode; |
||||
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() == 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().install(zipFile, new InstallFromDiskCallback(zipFile, jsCallback)); |
||||
} 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.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 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() == 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; |
||||
} |
||||
//执行JS回调
|
||||
PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback)); |
||||
} 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,54 @@
|
||||
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.error.PluginErrorCode; |
||||
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() == 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(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(Inter.getLocText("FR-Designer-Plugin_Update_Success")); |
||||
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(Inter.getLocText("FR-Designer-Plugin_Delete_Failed")); |
||||
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