From 8bc49176faf18091fceae120b86d9a8581861930 Mon Sep 17 00:00:00 2001 From: kerry Date: Wed, 31 May 2017 15:48:29 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-2354=20=20=E5=85=BC=E5=AE=B9=E4=BC=A0?= =?UTF-8?q?=E7=BB=9F=E6=8F=92=E4=BB=B6=E5=95=86=E5=9F=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/extra/PluginControlPane.java | 43 +++--- .../com/fr/design/extra/PluginDetailPane.java | 6 +- .../fr/design/extra/PluginFromStorePane.java | 125 +++++++----------- .../fr/design/extra/PluginInstalledPane.java | 83 +++++++----- .../fr/design/extra/PluginOperateUtils.java | 53 +++----- .../design/extra/PluginReaderForDesigner.java | 60 --------- .../fr/design/extra/PluginSelectListener.java | 5 +- .../com/fr/design/extra/PluginUpdatePane.java | 125 +++++------------- .../src/com/fr/design/extra/PluginUtils.java | 49 +++++++ .../com/fr/design/extra/PluginWebBridge.java | 18 ++- .../design/extra/PluginsReaderFromStore.java | 52 +++----- .../extra/exe/GetLoginInfoExecutor.java | 41 ------ .../exe/GetPluginCategoriesExecutor.java | 41 ------ .../extra/exe/GetPluginFromStoreExecutor.java | 68 ---------- .../extra/exe/InstallFromDiskExecutor.java | 103 --------------- .../extra/exe/InstallOnlineExecutor.java | 124 ----------------- .../extra/exe/ModifyStatusExecutor.java | 74 ----------- .../design/extra/exe/PluginLoginExecutor.java | 49 ------- .../extra/exe/ReadUpdateOnlineExecutor.java | 49 ------- .../extra/exe/SearchOnlineExecutor.java | 47 ------- .../design/extra/exe/UninstallExecutor.java | 62 --------- .../extra/exe/UpdateFromDiskExecutor.java | 81 ------------ .../extra/exe/UpdateOnlineExecutor.java | 118 ----------------- .../callback/AbstractPluginTaskCallback.java | 1 - .../extra/exe/callback/DownloadCallback.java | 2 + .../exe/callback/InstallFromDiskCallback.java | 6 +- .../exe/callback/InstallOnlineCallback.java | 7 +- .../design/extra/exe/callback/JSCallback.java | 31 ++++- .../exe/callback/UnistallPluginCallback.java | 1 - .../exe/callback/UpdateFromDiskCallback.java | 9 +- .../exe/callback/UpdateOnlineCallback.java | 9 +- .../extratask/AbstractExtraPluginTask.java | 11 ++ .../exe/extratask/InstallPluginTask.java | 11 +- .../extra/exe/extratask/UpdatePluginTask.java | 8 +- .../callback/UpdateOnlineCallback.java | 55 ++++++++ 35 files changed, 393 insertions(+), 1234 deletions(-) delete mode 100644 designer_base/src/com/fr/design/extra/PluginReaderForDesigner.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/PluginLoginExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java delete mode 100644 designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java create mode 100644 designer_base/src/com/fr/design/extra/exe/extratask/AbstractExtraPluginTask.java create mode 100644 designer_base/src/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java diff --git a/designer_base/src/com/fr/design/extra/PluginControlPane.java b/designer_base/src/com/fr/design/extra/PluginControlPane.java index 82657904f..ac63ae7f4 100644 --- a/designer_base/src/com/fr/design/extra/PluginControlPane.java +++ b/designer_base/src/com/fr/design/extra/PluginControlPane.java @@ -8,10 +8,13 @@ import com.fr.design.gui.itextfield.UITextField; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.IOUtils; import com.fr.general.Inter; -import com.fr.plugin.Plugin; import com.fr.plugin.PluginLicense; import com.fr.plugin.PluginLicenseManager; -import com.fr.plugin.PluginLoader; +import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.control.PluginTaskCallback; +import com.fr.plugin.manage.control.PluginTaskResult; +import com.fr.plugin.view.PluginView; import com.fr.stable.StringUtils; import javax.swing.*; @@ -20,7 +23,8 @@ import javax.swing.event.DocumentListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; -import java.util.ArrayList; +import java.util.*; +import java.util.List; /** * @author richie @@ -32,7 +36,7 @@ public class PluginControlPane extends BasicPane { private DefaultListModel listModel; private PluginDetailPane detailPane; private java.util.List listeners = new ArrayList(); - private Plugin[] plugins; + private List plugins; private UITextField searchTextField; public PluginControlPane() { @@ -63,8 +67,8 @@ public class PluginControlPane extends BasicPane { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof Plugin) { - PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(((Plugin) value).getId()); + if (value instanceof PluginView) { + PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(((PluginView) value).getID()); String extraInfo = ""; if (pluginLicense.isJarDamage()) { extraInfo = "(" + Inter.getLocText("FR-Plugin-Plugin_Damaged") + ")"; @@ -75,7 +79,7 @@ public class PluginControlPane extends BasicPane { extraInfo = "(" + (pluginLicense.isTrial() ? Inter.getLocText("FR-Plugin-Designer_Trial") : Inter.getLocText("FR-Plugin-Designer_Authorized")) + Inter.getLocText("FR-Plugin-Designer_Expired") + ")"; } } - setText(((Plugin) value).getName() + extraInfo); + setText(((PluginView) value).getName() + extraInfo); setIcon(IOUtils.readIcon("/com/fr/design/images/server/plugin.png")); } return this; @@ -101,7 +105,7 @@ public class PluginControlPane extends BasicPane { pluginList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { - Plugin plugin = (Plugin) pluginList.getSelectedValue(); + PluginView plugin = (PluginView) pluginList.getSelectedValue(); if (plugin != null) { detailPane.populate(plugin); for (PluginSelectListener l : listeners) { @@ -118,9 +122,9 @@ public class PluginControlPane extends BasicPane { listeners.add(l); } - public void loadPlugins(Plugin[] plugins) { + public void loadPlugins(java.util.List plugins) { this.plugins = plugins; - for (Plugin plugin : plugins) { + for (PluginView plugin : plugins) { listModel.addElement(plugin); } } @@ -128,21 +132,28 @@ public class PluginControlPane extends BasicPane { private void doSearch(String text) { if (StringUtils.isNotBlank(text)) { listModel.clear(); - for (Plugin plugin : plugins) { - if (plugin.match(text)) { + for (PluginView plugin : plugins) { + if (PluginUtils.isPluginMatch(plugin, text)) { listModel.addElement(plugin); } } } } - public Plugin getSelectedPlugin() { - return (Plugin) pluginList.getSelectedValue(); + public PluginView getSelectedPlugin() { + return (PluginView) pluginList.getSelectedValue(); } - public void deletePlugin(Plugin plugin) { + public void deletePlugin(PluginView plugin) { listModel.removeElement(plugin); - PluginLoader.getLoader().deletePlugin(plugin); + String id = plugin.getID(); + String version = plugin.getVersion(); + PluginManager.getController().uninstall(PluginMarker.create(id, version), true, new PluginTaskCallback() { + @Override + public void done(PluginTaskResult result) { + + } + }); } @Override diff --git a/designer_base/src/com/fr/design/extra/PluginDetailPane.java b/designer_base/src/com/fr/design/extra/PluginDetailPane.java index 4edfb934f..a5d44a614 100644 --- a/designer_base/src/com/fr/design/extra/PluginDetailPane.java +++ b/designer_base/src/com/fr/design/extra/PluginDetailPane.java @@ -3,7 +3,7 @@ package com.fr.design.extra; import com.fr.design.dialog.BasicPane; import com.fr.general.FRLogger; import com.fr.general.Inter; -import com.fr.plugin.Plugin; +import com.fr.plugin.view.PluginView; import com.fr.stable.StringUtils; import javax.swing.*; @@ -56,8 +56,8 @@ public class PluginDetailPane extends BasicPane { } - public void populate(Plugin plugin) { - textPane.setText(plugin.toHTML()); + public void populate(PluginView plugin) { + textPane.setText(PluginUtils.pluginToHtml(plugin)); } public void reset() { diff --git a/designer_base/src/com/fr/design/extra/PluginFromStorePane.java b/designer_base/src/com/fr/design/extra/PluginFromStorePane.java index e40f5a2bf..0b8393ccf 100644 --- a/designer_base/src/com/fr/design/extra/PluginFromStorePane.java +++ b/designer_base/src/com/fr/design/extra/PluginFromStorePane.java @@ -1,26 +1,29 @@ package com.fr.design.extra; import com.fr.base.FRContext; -import com.fr.design.DesignerEnvManager; -import com.fr.design.RestartHelper; +import com.fr.design.extra.tradition.callback.UpdateOnlineCallback; import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.gui.ilable.UILabel; +import com.fr.general.FRLogger; import com.fr.general.Inter; -import com.fr.plugin.Plugin; -import com.fr.stable.StringUtils; +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.PluginTaskResult; +import com.fr.plugin.manage.control.ProgressCallback; +import com.fr.plugin.view.PluginView; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.File; import java.util.List; -import java.util.concurrent.ExecutionException; /** * @author richie * @date 2015-03-10 * @since 8.0 */ -public class PluginFromStorePane extends PluginAbstractLoadingViewPane { +public class PluginFromStorePane extends PluginAbstractLoadingViewPane, Void> { private UILabel errorMsgLabel; private UITabbedPane tabbedPane; private PluginControlPane controlPane; @@ -29,7 +32,6 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane loadData() throws Exception { //Thread.sleep(3000); return PluginsReaderFromStore.readPlugins(); } /** * 加载成功处理 + * * @param plugins 插件 */ - public void loadOnSuccess(Plugin[] plugins) { + public void loadOnSuccess(List plugins) { controlPane.loadPlugins(plugins); - tabbedPane.setTitleAt(2, Inter.getLocText("FR-Designer-Plugin_All_Plugins") + "(" + plugins.length + ")"); + tabbedPane.setTitleAt(2, Inter.getLocText("FR-Designer-Plugin_All_Plugins") + "(" + plugins.size() + ")"); } /** * 加载失败 + * * @param e 异常消息 */ public void loadOnFailed(Exception e) { @@ -159,85 +166,52 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane(){ - - @Override - protected Void doInBackground() throws Exception { - Plugin plugin = controlPane.getSelectedPlugin(); - String id = null; - if (plugin != null) { - id = plugin.getId(); - } - String username = DesignerEnvManager.getEnvManager().getBBSName(); - String password = DesignerEnvManager.getEnvManager().getBBSPassword(); - try { - PluginHelper.downloadPluginFile(id,username,password, new Process() { - @Override - public void process(Double integer) { - publish(integer); - } - }); - Thread.sleep(2000); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } - return null; - } + if (BBSPluginLogin.getInstance().hasLogin()) { + PluginView plugin = controlPane.getSelectedPlugin(); + String id = null; + if (plugin != null) { + id = plugin.getID(); + } - public void process(List list) { - pane.setProgress(list.get(list.size() - LISTNUM1) * LISTNUM100); - } + try { + PluginMarker pluginMarker = PluginMarker.create(id, plugin.getVersion()); + String latestPluginInfo = PluginUtils.getLatestPluginInfo(id); + PluginMarker toPluginMarker = PluginMarker.create(id, latestPluginInfo); + PluginManager.getController().download(pluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane)); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } - public void done() { - //下载完成,开始执行安装 - try { - get(); - pane.didTaskFinished(); - installFromDiskZipFile(PluginHelper.getDownloadTempFile()); - } catch (InterruptedException e) { - FRContext.getLogger().error(e.getMessage(), e); - } catch (ExecutionException e) { - FRContext.getLogger().error(e.getMessage(), e); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - }.execute(); } - } /** * 正在加载页的标题 + * * @return 标题字符串 */ public String textForLoadingLabel() { @@ -246,11 +220,12 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane plugins = PluginManager.getContexts(); + List pluginViews = new ArrayList<>(); + for (PluginContext plugin : plugins) { + pluginViews.add((PluginView) plugin); + } + controlPane.loadPlugins(pluginViews); + num = plugins.size(); } /** * tab标题 + * * @return 同上 */ public String tabTitle() { return Inter.getLocText("FR-Designer-Plugin_Installed") + "(" + num + ")"; } - private void doDelete(Plugin plugin) { + private void doDelete(PluginView plugin) { int rv = JOptionPane.showOptionDialog( PluginInstalledPane.this, Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"), @@ -114,21 +131,19 @@ public class PluginInstalledPane extends PluginAbstractViewPane { if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { return; } - + try { - String[] filesToBeDelete = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), plugin); controlPane.deletePlugin(plugin); - RestartHelper.saveFilesWhichToDelete(filesToBeDelete); } catch (Exception e) { JOptionPane.showMessageDialog(PluginInstalledPane.this, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); } - + if (rv == JOptionPane.OK_OPTION) { RestartHelper.restart(); } } - private void changeTextForButton(Plugin plugin) { + private void changeTextForButton(PluginView plugin) { if (plugin.isActive()) { disableButton.setText(Inter.getLocText("FR-Designer-Plugin_Disable")); } else { diff --git a/designer_base/src/com/fr/design/extra/PluginOperateUtils.java b/designer_base/src/com/fr/design/extra/PluginOperateUtils.java index 00e610eb0..4f2a2e204 100644 --- a/designer_base/src/com/fr/design/extra/PluginOperateUtils.java +++ b/designer_base/src/com/fr/design/extra/PluginOperateUtils.java @@ -15,13 +15,11 @@ 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.plugin.view.PluginView; 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; @@ -45,23 +43,17 @@ public class PluginOperateUtils { } } - public static void installPluginFromDisk(final String filePath, JSCallback jsCallback) { - PluginManager.getController().install(new File(filePath), new InstallFromDiskCallback(new File(filePath), jsCallback)); + public static void installPluginFromDisk(File zipFile, JSCallback jsCallback) { + PluginManager.getController().install(zipFile, new InstallFromDiskCallback(zipFile, jsCallback)); } - public static void updatePluginOnline(JSObject pluginIDs, JSCallback jsCallback) { - String[] pluginInfos = jsObjectToStringArray(pluginIDs); + public static void updatePluginOnline(List pluginMarkerList, JSCallback jsCallback) { if (!(BBSPluginLogin.getInstance().hasLogin())) { LoginCheckContext.fireLoginCheckListener(); } if (BBSPluginLogin.getInstance().hasLogin()) { - List pluginMarkerList = new ArrayList(); - 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); @@ -86,7 +78,7 @@ public class PluginOperateUtils { public static void setPluginActive(String pluginInfo, JSCallback jsCallback) { PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); PluginContext plugin = PluginManager.getContext(pluginMarker); - boolean active = !plugin.isActive(); + boolean active = plugin.isActive(); PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active); if (active) { PluginManager.getController().forbid(pluginMarker, modifyStatusCallback); @@ -100,13 +92,13 @@ public class PluginOperateUtils { PluginManager.getController().uninstall(pluginMarker, isForce, new UnistallPluginCallback()); } - public static void readUpdateOnline(JSCallback jsCallback){ + public static void readUpdateOnline(JSCallback jsCallback) { try { - String [] plugins = PluginReaderForDesigner.readPluginsForUpdate(); + List plugins = PluginsReaderFromStore.readPluginsForUpdate(); JSONArray jsonArray = new JSONArray(); - for (String plugin : plugins) { + for (PluginView plugin : plugins) { org.json.JSONObject jsonObject = new org.json.JSONObject(); - jsonObject.put("pluginid", plugin); + jsonObject.put("pluginid", plugin.getID()); jsonArray.put(jsonObject); } String result = jsonArray.toString(); @@ -127,7 +119,7 @@ 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"); if (StringUtils.isNotBlank(plistUrl)) { StringBuilder url = new StringBuilder(); @@ -154,7 +146,7 @@ public class PluginOperateUtils { } } - public static void getPluginCategories(JSCallback jsCallback){ + public static void getPluginCategories(JSCallback jsCallback) { String result; String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category"); if (url != null) { @@ -166,27 +158,22 @@ public class PluginOperateUtils { jsCallback.execute(result); } - public static void getLoginInfo(JSCallback jsCallback){ + 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); + } 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 list = new ArrayList<>(); - for (int i = 0; i < len; i++) { - list.add(obj.getSlot(i).toString()); - } - return list.toArray(new String[len]); + public static boolean pluginValidate(PluginView pluginView){ + return StringUtils.isNotEmpty(pluginView.getID()) + && StringUtils.isNotEmpty(pluginView.getName()) + && StringUtils.isNotEmpty(pluginView.getVersion()) + && StringUtils.isNotEmpty(pluginView.getEnvVersion()); } } diff --git a/designer_base/src/com/fr/design/extra/PluginReaderForDesigner.java b/designer_base/src/com/fr/design/extra/PluginReaderForDesigner.java deleted file mode 100644 index 5fbb410fd..000000000 --- a/designer_base/src/com/fr/design/extra/PluginReaderForDesigner.java +++ /dev/null @@ -1,60 +0,0 @@ -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 pluginsToUpdate = new HashSet(); - - /** - * 从插件商店服务器读取插件信息,以JSON形式返回 - * - * @return 插件信息 - */ - public static String[] readPluginsForUpdate() throws Exception { - String resText = null; - String url = SiteCenter.getInstance().acquireUrlByKind("plugin.update"); - if (StringUtils.isNotEmpty(url)) { - HashMap para = new HashMap(); - 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()]); - } -} diff --git a/designer_base/src/com/fr/design/extra/PluginSelectListener.java b/designer_base/src/com/fr/design/extra/PluginSelectListener.java index b1962335b..4f82886f6 100644 --- a/designer_base/src/com/fr/design/extra/PluginSelectListener.java +++ b/designer_base/src/com/fr/design/extra/PluginSelectListener.java @@ -1,6 +1,7 @@ package com.fr.design.extra; -import com.fr.plugin.Plugin; + +import com.fr.plugin.view.PluginView; /** * @author richie @@ -9,5 +10,5 @@ import com.fr.plugin.Plugin; */ public interface PluginSelectListener { - public void valueChanged(Plugin plugin); + public void valueChanged(PluginView plugin); } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/PluginUpdatePane.java b/designer_base/src/com/fr/design/extra/PluginUpdatePane.java index e0b3ada35..5506b5dc4 100644 --- a/designer_base/src/com/fr/design/extra/PluginUpdatePane.java +++ b/designer_base/src/com/fr/design/extra/PluginUpdatePane.java @@ -3,12 +3,20 @@ package com.fr.design.extra; import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; import com.fr.design.RestartHelper; +import com.fr.design.extra.tradition.callback.UpdateOnlineCallback; import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.gui.ilable.UILabel; +import com.fr.general.FRLogger; import com.fr.general.Inter; -import com.fr.plugin.Plugin; -import com.fr.plugin.PluginLoader; +import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.error.PluginErrorCode; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.manage.bbs.BBSPluginLogin; +import com.fr.plugin.manage.control.PluginTaskResult; +import com.fr.plugin.manage.control.ProgressCallback; +import com.fr.plugin.view.PluginView; import com.fr.stable.StringUtils; +import sun.plugin2.main.server.Plugin; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; @@ -20,7 +28,7 @@ import java.util.List; * @date 2015-03-10 * @since 8.0 */ -public class PluginUpdatePane extends PluginAbstractLoadingViewPane { +public class PluginUpdatePane extends PluginAbstractLoadingViewPane, Void> { private PluginControlPane controlPane; private JLabel errorMsgLabel; @@ -68,7 +76,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane loadData() throws Exception { return PluginsReaderFromStore.readPluginsForUpdate(); } @@ -131,9 +139,9 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane plugins) { controlPane.loadPlugins(plugins); - tabbedPane.setTitleAt(1, Inter.getLocText("FR-Designer-Plugin_Update") + "(" + plugins.length + ")"); + tabbedPane.setTitleAt(1, Inter.getLocText("FR-Designer-Plugin_Update") + "(" + plugins.size() + ")"); } /** @@ -167,101 +175,36 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane() { - - @Override - protected Void doInBackground() throws Exception { - Plugin plugin = controlPane.getSelectedPlugin(); - String id = null; - if (plugin != null) { - id = plugin.getId(); - } - String username = DesignerEnvManager.getEnvManager().getBBSName(); - String password = DesignerEnvManager.getEnvManager().getBBSPassword(); - try { - PluginHelper.downloadPluginFile(id, username, password, new Process() { - @Override - public void process(Double integer) { - publish(integer); - } - }); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } - return null; - } - - public void process(List list) { - pane.setProgress(list.get(list.size() - 1) * PERSENT); - } - - public void done() { - //下载完成,开始执行安装 - try { - get(); - pane.didTaskFinished(); - doUpdateFromFile(PluginHelper.getDownloadTempFile()); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - }.execute(); + if (BBSPluginLogin.getInstance().hasLogin()) { + PluginView plugin = controlPane.getSelectedPlugin(); + PluginMarker pluginMarker = PluginMarker.create(plugin.getID(), plugin.getVersion()); + String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarker.getPluginID()); + PluginMarker toPluginMarker = PluginMarker.create(pluginMarker.getPluginID(), latestPluginInfo); + PluginManager.getController().download(pluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane)); } } private void doUpdateFromFile(File chosenFile) { - try { - Plugin plugin = PluginHelper.readPlugin(chosenFile); - if (plugin == null) { - JOptionPane.showMessageDialog(PluginUpdatePane.this, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - return; + PluginManager.getController().update(chosenFile, new ProgressCallback() { + @Override + public void updateProgress(String description, double progress) { + } - Plugin oldPlugin = PluginLoader.getLoader().getPluginById(plugin.getId()); - if (oldPlugin != null) { - // 说明安装了同ID的插件,再比较两个插件的版本 - if (PluginHelper.isNewThan(plugin, oldPlugin)) { - // 说明是新的插件,删除老的然后安装新的 - final String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin); - PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() { - @Override - public void done() { - int rv = JOptionPane.showOptionDialog( - PluginUpdatePane.this, - Inter.getLocText("FR-Designer-Plugin_Update_Successful"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.YES_NO_OPTION, - JOptionPane.INFORMATION_MESSAGE, - null, - new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), - Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later") - }, - null - ); - - if (rv == JOptionPane.OK_OPTION) { - RestartHelper.restart(); - } - - // 如果不是立即重启,就把要删除的文件存放起来 - if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { - RestartHelper.saveFilesWhichToDelete(files); - } - } - }); + + @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 { - JOptionPane.showMessageDialog(PluginUpdatePane.this, Inter.getLocText("FR-Designer-Plugin_Version_Is_Lower_Than_Current"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); } - } else { - JOptionPane.showMessageDialog(PluginUpdatePane.this, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); } - } catch (Exception e1) { - JOptionPane.showMessageDialog(PluginUpdatePane.this, e1.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } + }); } /** diff --git a/designer_base/src/com/fr/design/extra/PluginUtils.java b/designer_base/src/com/fr/design/extra/PluginUtils.java index 31a1ff203..4871f5546 100644 --- a/designer_base/src/com/fr/design/extra/PluginUtils.java +++ b/designer_base/src/com/fr/design/extra/PluginUtils.java @@ -1,5 +1,6 @@ package com.fr.design.extra; +import com.fr.base.TemplateUtils; import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.general.SiteCenter; @@ -9,17 +10,20 @@ import com.fr.json.JSONObject; import com.fr.plugin.context.PluginContext; import com.fr.plugin.context.PluginMarker; +import com.fr.plugin.view.PluginView; 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.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URLDecoder; import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Created by ibm on 2017/5/25. @@ -104,4 +108,49 @@ public class PluginUtils { return resText; } + public static boolean isPluginMatch(PluginView pluginView, String text){ + return StringUtils.contains(pluginView.getID(), text) + || StringUtils.contains(pluginView.getName(), text) + || StringUtils.contains(pluginView.getVersion(), text) + || StringUtils.contains(pluginView.getEnvVersion(), text) + || StringUtils.contains(pluginView.getVendor(), text) + || StringUtils.contains(pluginView.getDescription(), text) + || StringUtils.contains(pluginView.getChangeNotes(), text); + + } + + public static String pluginToHtml(PluginView pluginView){ + String pluginName = Inter.getLocText("FR-Plugin-Plugin_Name"); + String pluginVersion = Inter.getLocText("FR-Plugin-Plugin_Version"); + String startVersion = Inter.getLocText("FR-Plugin-Start_Version"); + String developer = Inter.getLocText("FR-Plugin_Developer"); + String desc = Inter.getLocText("FR-Plugin-Function_Description"); + String updateLog = Inter.getLocText("FR-Plugin-Update_Log"); + Map map = new HashMap(); + + map.put("name", pluginName); + map.put("name_value", pluginView.getName()); + + map.put("version", pluginVersion); + map.put("version_value", pluginView.getVersion()); + + map.put("env", startVersion); + map.put("env_value", pluginView.getEnvVersion()); + + map.put("dev", developer); + map.put("dev_value", pluginView.getVendor()); + + map.put("fun", desc); + map.put("fun_value", pluginView.getDescription()); + + map.put("update", updateLog); + map.put("update_value", pluginView.getDescription()); + + try { + return TemplateUtils.renderTemplate("/com/fr/plugin/plugin.html", map); + } catch (IOException e) { + return StringUtils.EMPTY; + } + } + } diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 5f5caac5d..5c8a45587 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -6,6 +6,8 @@ import com.fr.design.RestartHelper; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; import com.fr.design.extra.exe.callback.JSCallback; +import com.fr.design.extra.exe.extratask.ExtraPluginTask; +import com.fr.design.extra.exe.extratask.UpdatePluginTask; import com.fr.design.gui.ilable.UILabel; import com.fr.general.FRLogger; import com.fr.general.Inter; @@ -13,6 +15,7 @@ import com.fr.general.SiteCenter; import com.fr.plugin.PluginLicense; import com.fr.plugin.PluginLicenseManager; import com.fr.plugin.context.PluginContext; +import com.fr.plugin.context.PluginMarker; import com.fr.plugin.manage.PluginManager; import com.fr.stable.ArrayUtils; import com.fr.stable.StringUtils; @@ -145,15 +148,14 @@ public class PluginWebBridge { * 从插件服务器上安装插件 * * @param pluginInfo 插件的ID - * @param callback 回调函数 + * @param callback 回调函数 */ public void installPluginOnline(final String pluginInfo, final JSObject callback) { JSCallback jsCallback = new JSCallback(webEngine, callback); - PluginOperateUtils.installPluginOnline(pluginInfo,jsCallback); + PluginOperateUtils.installPluginOnline(pluginInfo, jsCallback); } - /** * 从磁盘上选择插件安装包进行安装 * @@ -161,7 +163,8 @@ public class PluginWebBridge { */ public void installPluginFromDisk(final String filePath, final JSObject callback) { JSCallback jsCallback = new JSCallback(webEngine, callback); - PluginOperateUtils.installPluginFromDisk(filePath,jsCallback); + File file = new File(filePath); + PluginOperateUtils.installPluginFromDisk(file, jsCallback); } /** @@ -182,7 +185,12 @@ public class PluginWebBridge { */ public void updatePluginOnline(JSObject pluginIDs, final JSObject callback) { JSCallback jsCallback = new JSCallback(webEngine, callback); - PluginOperateUtils.updatePluginOnline(pluginIDs, jsCallback); + String[] pluginInfos = jsObjectToStringArray(pluginIDs); + List pluginMarkerList = new ArrayList(); + for (int i = 0; i < pluginInfos.length; i++) { + pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i])); + } + PluginOperateUtils.updatePluginOnline(pluginMarkerList, jsCallback); } /** diff --git a/designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java b/designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java index abd053362..add949796 100644 --- a/designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java +++ b/designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java @@ -6,15 +6,14 @@ import com.fr.general.SiteCenter; import com.fr.general.http.HttpClient; import com.fr.json.JSONArray; import com.fr.json.JSONException; -import com.fr.plugin.Plugin; -import com.fr.plugin.PluginLoader; +import com.fr.plugin.manage.PluginManager; +import com.fr.plugin.view.PluginView; +import com.fr.plugin.view.PluginViewReader; 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; +import java.util.*; /** * @author richie @@ -22,15 +21,15 @@ import java.util.Set; * @since 8.0 */ public class PluginsReaderFromStore { - private static Set plugins = new HashSet(); - private static Set pluginsToUpdate = new HashSet(); + private static Set plugins = new HashSet(); + private static Set pluginsToUpdate = new HashSet(); /** * 从插件商店服务器读取插件信息,以JSON形式返回 * * @return 插件信息 */ - public static Plugin[] readPlugins() throws Exception { + public static List readPlugins() throws Exception { String resText; try { HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.store")); @@ -40,23 +39,7 @@ public class PluginsReaderFromStore { } catch (Exception e) { throw new Exception(Inter.getLocText("FR-Designer-Plugin_PluginMarket_Coding")); } - if (StringUtils.isNotEmpty(resText)) { - try { - plugins.clear();//先清空set - JSONArray jsonArray = new JSONArray(resText); - for (int i = 0, size = jsonArray.length(); i < size; i++) { - Plugin plugin = new Plugin(); - plugin.parseJSON(jsonArray.optJSONObject(i)); - if (plugin.isValidate()) { - plugins.add(plugin); - } - } - } catch (JSONException e) { - throw new Exception(Inter.getLocText("FR-Designer-Plugin_Read_Plugin_List_Error")); - } - } - - return plugins.toArray(new Plugin[plugins.size()]); + return parseResText(resText, plugins); } /** @@ -64,12 +47,12 @@ public class PluginsReaderFromStore { * * @return 插件信息 */ - public static Plugin[] readPluginsForUpdate() throws Exception { + public static List readPluginsForUpdate() throws Exception { String resText = null; String url = SiteCenter.getInstance().acquireUrlByKind("plugin.update"); if (StringUtils.isNotEmpty(url)) { HashMap para = new HashMap(); - para.put("plugins", PluginLoader.getLoader().pluginsToString()); + para.put("plugins", PluginUtils.transPluginsToString(PluginManager.getContexts())); //只有当前设计器的jar高于插件新版本需要的jarTime时, 才提示更新该插件. para.put("jarTime", GeneralUtils.readBuildNO()); HttpClient httpClient = new HttpClient(url, para); @@ -77,22 +60,25 @@ public class PluginsReaderFromStore { String charSet = EncodeConstants.ENCODING_UTF_8; resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); } + return parseResText(resText, pluginsToUpdate); + } + + private static List parseResText(String resText, Set plugins) throws Exception { if (StringUtils.isNotEmpty(resText)) { try { - pluginsToUpdate.clear(); + plugins.clear(); JSONArray jsonArray = new JSONArray(resText); for (int i = 0, size = jsonArray.length(); i < size; i++) { - Plugin plugin = new Plugin(); - plugin.parseJSON(jsonArray.optJSONObject(i)); - if (plugin.isValidate()) { - pluginsToUpdate.add(plugin); + PluginView pluginView = PluginViewReader.readFromJson(jsonArray.optJSONObject(i)); + if (PluginOperateUtils.pluginValidate(pluginView)) { + plugins.add(pluginView); } } } catch (JSONException e) { throw new Exception(Inter.getLocText("FR-Designer-Plugin_Read_Plugin_List_Error")); } } - return pluginsToUpdate.toArray(new Plugin[pluginsToUpdate.size()]); + return new ArrayList<>(plugins); } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java b/designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java deleted file mode 100644 index f65dd1584..000000000 --- a/designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.DesignerEnvManager; -import com.fr.design.extra.Process; -import com.fr.plugin.manage.bbs.BBSPluginLogin; -import com.fr.stable.StringUtils; - -/** - * Created by lp on 2016/8/16. - */ -public class GetLoginInfoExecutor implements Executor { - private String result = "[]"; - - @Override - public String getTaskFinishMessage() { - return result; - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return null; - } - - @Override - public void run(Process process) { - String username = BBSPluginLogin.getInstance().getUserInfo().getUserName(); - String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName(); - if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) { - return; - }else { - result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername; - } - } - } - }; - } -} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java b/designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java deleted file mode 100644 index c90521316..000000000 --- a/designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.PluginConstants; -import com.fr.design.extra.Process; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; - -/** - * Created by vito on 16/5/16. - */ -public class GetPluginCategoriesExecutor implements Executor { - private String result = "[]"; - - @Override - public String getTaskFinishMessage() { - return result; - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return null; - } - - @Override - public void run(Process process) { - String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category"); - if (url != null) { - HttpClient httpClient = new HttpClient(url); - result = httpClient.getResponseText(); - } else { - result = PluginConstants.CONNECTION_404; - } - } - } - }; - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java b/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java deleted file mode 100644 index a276d386c..000000000 --- a/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.PluginConstants; -import com.fr.design.extra.Process; -import com.fr.general.FRLogger; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; -import com.fr.stable.StringUtils; - -/** - * Created by vito on 16/4/18. - * 获取插件分类信息 - */ -public class GetPluginFromStoreExecutor implements Executor { - private String result = "[]"; - private String category; - private String seller; - private String fee; - - public GetPluginFromStoreExecutor(String category, String seller, String fee) { - this.category = category; - this.seller = seller; - this.fee = fee; - } - - @Override - public String getTaskFinishMessage() { - return result; - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return StringUtils.EMPTY; - } - - @Override - public void run(Process process) { - 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()); - result = httpClient.getResponseText(); - } catch (Exception e) { - FRLogger.getLogger().error(e.getMessage()); - } - } else { - result = PluginConstants.CONNECTION_404; - } - } - } - }; - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java b/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java deleted file mode 100644 index 3d5629a3c..000000000 --- a/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.Process; -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 com.fr.plugin.manage.control.ProgressCallback; - -import javax.swing.*; -import java.io.File; - -/** - * Created by richie on 16/3/19. - */ -public class InstallFromDiskExecutor implements Executor { - private String filePath; - - public InstallFromDiskExecutor(String filePath) { - this.filePath = filePath; - - } - - @Override - public String getTaskFinishMessage() { - return Inter.getLocText("FR-Designer-Plugin_Success_Install"); - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return Inter.getLocText("FR-Designer-Plugin_Unzipping") + filePath; - } - - @Override - public void run(Process process) { - - } - }, - new Command() { - @Override - public String getExecuteMessage() { - return Inter.getLocText("FR-Designer-Plugin_Installing"); - } - - @Override - public void run(Process process) { - PluginManager.getController().install(new File(filePath), new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - } - @Override - public void done(PluginTaskResult result) { - if (result.isSuccess()) { - FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success")); - } else if(result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()){ - int rv = JOptionPane.showOptionDialog( - null, - Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE, - null, - null, - null - ); - if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { - return; - } - installWithDependence(); - }else{ - FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed")); - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } - } - }; - } - - public void installWithDependence(){ - PluginManager.getController().install(new File(filePath), new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - } - @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{ - FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed")); - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java deleted file mode 100644 index 42f7be72d..000000000 --- a/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.LoginCheckContext; -import com.fr.design.extra.PluginUtils; -import com.fr.design.extra.Process; -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.bbs.BBSPluginLogin; -import com.fr.plugin.manage.control.PluginTaskResult; -import com.fr.plugin.manage.control.ProgressCallback; - -import javax.swing.*; - -/** - * Created by richie on 16/3/19. - */ -public class InstallOnlineExecutor implements Executor { - - private String pluginInfo; - - public InstallOnlineExecutor(String pluginInfo) { - this.pluginInfo = pluginInfo; - } - - @Override - public String getTaskFinishMessage() { - return "task succeed"; - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return Inter.getLocText("FR-Designer-Plugin_Downloading") + ":" + pluginInfo.split("_")[0]; - } - - @Override - public void run(final Process process) { - //下载插件 - if (!BBSPluginLogin.getInstance().hasLogin()) { - LoginCheckContext.fireLoginCheckListener(); - } - PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); - if (BBSPluginLogin.getInstance().hasLogin()) { - PluginManager.getController().download(pluginMarker, new ProgressCallback() { - @Override - public void updateProgress(String description, double aProgress) { -// process.process(Math.round(aProgress * 100) + "%"); - } - - @Override - public void done(PluginTaskResult result) { - if (result.isSuccess()) { - installPlugin(pluginMarker); - } else { - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - - } - } - } - }; - } - - public void installPlugin(PluginMarker pluginMarker) { - PluginManager.getController().install(pluginMarker, new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - - } - - @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; - } - installPluginWithDependence(pluginMarker); - } else { - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } - - public void installPluginWithDependence(PluginMarker pluginMarker) { - PluginManager.getController().install(pluginMarker, new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - } - - @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 { - FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed")); - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java deleted file mode 100644 index 0f1c6405d..000000000 --- a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.PluginUtils; -import com.fr.design.extra.Process; -import com.fr.general.Inter; -import com.fr.plugin.context.PluginContext; -import com.fr.plugin.context.PluginMarker; -import com.fr.plugin.manage.PluginManager; -import com.fr.plugin.manage.control.PluginTaskCallback; -import com.fr.plugin.manage.control.PluginTaskResult; -import com.fr.stable.StringUtils; - -import javax.swing.*; - -/** - * Created by richie on 16/3/19. - */ -public class ModifyStatusExecutor implements Executor { - - private String pluginInfo; - private boolean active; - private PluginContext plugin; - - public ModifyStatusExecutor(String pluginInfo) { - this.pluginInfo = pluginInfo; - } - - @Override - public String getTaskFinishMessage() { - return plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"); - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return StringUtils.EMPTY; - } - - @Override - public void run(Process process) { - PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); - plugin = PluginManager.getContext(pluginMarker); - active = !plugin.isActive(); - if (active) { - PluginManager.getController().forbid(pluginMarker, new PluginTaskCallback() { - @Override - public void done(PluginTaskResult result) { - if (result.isSuccess()) { - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled")); - } else { - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } else { - PluginManager.getController().enable(pluginMarker, new PluginTaskCallback() { - @Override - public void done(PluginTaskResult result) { - if (result.isSuccess()) { - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived")); - } else { - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } - } - } - }; - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/PluginLoginExecutor.java b/designer_base/src/com/fr/design/extra/exe/PluginLoginExecutor.java deleted file mode 100644 index c1101f800..000000000 --- a/designer_base/src/com/fr/design/extra/exe/PluginLoginExecutor.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.LoginWebBridge; -import com.fr.design.extra.Process; -import com.fr.design.gui.ilable.UILabel; - -/** - * Created by Slpire on 2016/11/7. - */ -public class PluginLoginExecutor implements Executor { - - private String result = "[]"; - - private String username; - private String password; - private UILabel uiLabel; - - public PluginLoginExecutor(String username, String password, UILabel uiLabel) { - this.username = username; - this.password = password; - this.uiLabel = uiLabel; - } - - @Override - public String getTaskFinishMessage() { - return result; - } - - @Override - public Command[] getCommands() { - return new Command[] { - new Command() { - @Override - public String getExecuteMessage() { - return null; - } - - @Override - public void run(Process process) { - String loginResult = LoginWebBridge.getHelper().login(username, password, uiLabel); - if (Integer.valueOf(loginResult) == 0) { - LoginWebBridge.getHelper().updateMessageCount(); - } - result = loginResult; - } - } - }; - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java deleted file mode 100644 index 9bcfce699..000000000 --- a/designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.PluginReaderForDesigner; -import com.fr.design.extra.Process; -import com.fr.general.FRLogger; -import com.fr.stable.StringUtils; -import org.json.JSONArray; -import org.json.JSONObject; - -/** - * Created by vito on 16/4/19. - */ -public class ReadUpdateOnlineExecutor implements Executor { - private String[] plugins; - private String result; - - @Override - public String getTaskFinishMessage() { - return result; - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return StringUtils.EMPTY; - } - - @Override - public void run(Process process) { - try { - plugins = PluginReaderForDesigner.readPluginsForUpdate(); - JSONArray jsonArray = new JSONArray(); - for (String plugin : plugins) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("pluginid", plugin); - jsonArray.put(jsonObject); - } - result = jsonArray.toString(); - } catch (Exception e) { - FRLogger.getLogger().error(e.getMessage()); - } - } - } - }; - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java deleted file mode 100644 index 089173c98..000000000 --- a/designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.Process; -import com.fr.general.FRLogger; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; -import com.fr.stable.StringUtils; - -/** - * Created by vito on 16/4/18. - */ -public class SearchOnlineExecutor implements Executor { - private String result; - private String keyword; - - public SearchOnlineExecutor(String keyword) { - this.keyword = keyword; - } - - @Override - public String getTaskFinishMessage() { - return result; - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return StringUtils.EMPTY; - } - - @Override - public void run(Process process) { - try { - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.plist") + "&keyword=" + keyword); - result = httpClient.getResponseText(); - - } catch (Exception e) { - FRLogger.getLogger().error(e.getMessage()); - } - } - } - }; - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java b/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java deleted file mode 100644 index 79d34bf21..000000000 --- a/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.PluginUtils; -import com.fr.design.extra.Process; -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.PluginTaskCallback; -import com.fr.plugin.manage.control.PluginTaskResult; - -import javax.swing.*; - -/** - * Created by richie on 16/3/19. - */ -public class UninstallExecutor implements Executor { - - private String pluginInfo; - private boolean isForce; - private String result = "undo"; - - public UninstallExecutor(String pluginInfo, boolean isForce) { - this.pluginInfo = pluginInfo; - this.isForce = isForce; - } - - @Override - public String getTaskFinishMessage() { - return result; - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return null; - } - - @Override - public void run(Process process) { - PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); - PluginManager.getController().uninstall(pluginMarker, isForce, new PluginTaskCallback() { - @Override - public void done(PluginTaskResult pluginTaskResult) { - if (pluginTaskResult.isSuccess()) { - result = "done"; - 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, pluginTaskResult.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } - } - }; - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java b/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java deleted file mode 100644 index 8be5a3834..000000000 --- a/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.design.extra.Process; -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 com.fr.plugin.manage.control.ProgressCallback; - -import javax.swing.*; -import java.io.File; - -/** - * Created by richie on 16/3/19. - */ -public class UpdateFromDiskExecutor implements Executor { - - private String filePath; - - public UpdateFromDiskExecutor(String filePath) { - this.filePath = filePath; - } - - @Override - public String getTaskFinishMessage() { - return Inter.getLocText("FR-Designer-Plugin_Update_End"); - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return null; - } - - @Override - public void run(Process process) { - PluginManager.getController().update(new File(filePath), new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - - } - - @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()) { - updatePluginWithDependence(); - } else { - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } - } - }; - } - - public void updatePluginWithDependence() { - PluginManager.getController().update(new File(filePath), new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - - } - - @Override - public void done(PluginTaskResult result) { - if (result.isSuccess()) { - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); - } else { - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } -} diff --git a/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java deleted file mode 100644 index c8f1fc778..000000000 --- a/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.fr.design.extra.exe; - -import com.fr.base.FRContext; -import com.fr.design.DesignerEnvManager; -import com.fr.design.extra.*; -import com.fr.design.extra.Process; -import com.fr.general.FRLogger; -import com.fr.general.Inter; -import com.fr.json.JSONObject; -import com.fr.plugin.context.PluginMarker; -import com.fr.plugin.error.PluginErrorCode; -import com.fr.plugin.manage.PluginManager; -import com.fr.plugin.manage.bbs.BBSPluginLogin; -import com.fr.plugin.manage.control.PluginTaskResult; -import com.fr.plugin.manage.control.ProgressCallback; -import com.fr.stable.StringUtils; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by richie on 16/3/19. - */ -public class UpdateOnlineExecutor implements Executor { - - private String[] pluginInfos; - private static final int PERCENT_100 = 100; - - public UpdateOnlineExecutor(String[] pluginInfos) { - this.pluginInfos = pluginInfos; - } - - @Override - public String getTaskFinishMessage() { - return "task succeed"; - } - - @Override - public Command[] getCommands() { - return new Command[]{ - new Command() { - @Override - public String getExecuteMessage() { - return null; - } - - @Override - public void run(Process process) { - if (!(BBSPluginLogin.getInstance().hasLogin())){ - LoginCheckContext.fireLoginCheckListener(); - } - if (BBSPluginLogin.getInstance().hasLogin()) { - List pluginMarkerList = new ArrayList(); - for (int i = 0; i < pluginInfos.length; i++) { - pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i])); - } - updatePlugins(pluginMarkerList, process); } - } - } - }; - } - - public void updatePluginWithDependence(PluginMarker pluginMarker, PluginMarker toMarker) { - PluginManager.getController().update(pluginMarker, toMarker, new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - - } - - @Override - public void done(PluginTaskResult result) { - if (result.isSuccess()) { - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); - } else { - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } - - public void updatePlugins(List pluginMarkerList, Process process) { - for (int i = 0; i < pluginMarkerList.size(); i++) { - try { - int a = i; - //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"); - PluginManager.getController().update(pluginMarkerList.get(i), PluginMarker.create(pluginMarkerList.get(i).getPluginID(), latestPluginVersion), new ProgressCallback() { - @Override - public void updateProgress(String description, double progress) { - process.process(PERCENT_100 / pluginMarkerList.size() * (a + 1) + "%"); - - } - - @Override - public void done(PluginTaskResult result) { - if (result.isSuccess()) { - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful")); - } else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) { - updatePluginWithDependence(pluginMarkerList.get(a), PluginMarker.create(pluginMarkerList.get(a).getPluginID(), latestPluginVersion)); - } else { - JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - } - } - }); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - } - -} diff --git a/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java index c641c622f..3f13f531d 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java @@ -10,7 +10,6 @@ import com.fr.plugin.manage.control.ProgressCallback; public abstract class AbstractPluginTaskCallback implements ProgressCallback{ protected PluginMarker pluginMarker; - protected JSCallback jsCallback; @Override public void updateProgress(String description, double aProgress) { diff --git a/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java index d12f50592..ba4d9b31f 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java @@ -11,6 +11,7 @@ import javax.swing.*; */ public class DownloadCallback extends AbstractPluginTaskCallback { private ExtraPluginTask extraPluginTask; + protected JSCallback jsCallback; public DownloadCallback(ExtraPluginTask extraPluginTask, JSCallback jsCallback) { this.extraPluginTask = extraPluginTask; @@ -24,6 +25,7 @@ public class DownloadCallback extends AbstractPluginTaskCallback { @Override public void done(PluginTaskResult result) { + jsCallback.execute("done"); if (result.isSuccess()) { extraPluginTask.doExtraPluginTask(); } else { diff --git a/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java index 035ebbf32..cf13dd0a5 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java @@ -14,6 +14,7 @@ import java.io.File; */ public class InstallFromDiskCallback extends AbstractPluginTaskCallback { private File zipFile; + protected JSCallback jsCallback; public InstallFromDiskCallback(File zipFile, JSCallback jsCallback) { this.zipFile = zipFile; @@ -28,14 +29,15 @@ public class InstallFromDiskCallback extends AbstractPluginTaskCallback { @Override public void done(PluginTaskResult result) { + jsCallback.execute("done"); 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"), + Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")), + Inter.getLocText("FR-Designer-Plugin_Install_Success"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, diff --git a/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java index 8649b5cd3..a1ee0ee4c 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java @@ -13,6 +13,8 @@ import javax.swing.*; * Created by ibm on 2017/5/26. */ public class InstallOnlineCallback extends AbstractPluginTaskCallback { + protected JSCallback jsCallback; + public InstallOnlineCallback(PluginMarker pluginMarker, JSCallback jsCallback){ this.pluginMarker = pluginMarker; @@ -27,14 +29,15 @@ public class InstallOnlineCallback extends AbstractPluginTaskCallback { @Override public void done(PluginTaskResult result) { + jsCallback.execute("done"); 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"), + Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")), + Inter.getLocText("FR-Designer-Plugin_Install_Success"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, diff --git a/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java index 5ee99a69c..8204a88eb 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java @@ -1,5 +1,6 @@ package com.fr.design.extra.exe.callback; +import com.fr.stable.StringUtils; import javafx.scene.web.WebEngine; import netscape.javascript.JSObject; @@ -16,7 +17,7 @@ public class JSCallback { } public void execute(String newValue) { - String fun = "(" + callback + ")(\"" + newValue + "\")"; + String fun = "(" + callback + ")(\"" + trimText(newValue) + "\")"; try { webEngine.executeScript(fun); } catch (Exception e) { @@ -24,6 +25,34 @@ public class JSCallback { } } + public void execute(double progress) { + String fun = "(" + callback + ")(\"" + trimText(String.valueOf(progress)) + "\")"; + try { + webEngine.executeScript(fun); + } catch (Exception e) { + webEngine.executeScript("alert(\"" + e.getMessage() + "\")"); + } + } + + /** + * vito:由于使用webEngine.executeScript("(" + callback + ")(\"" + newValue + "\")") + * 执行脚本,所以原来规范的json格式也会在拼接字符串后可能抛出参数异常,需要转换掉一些会造成错误的特殊字符, + * 选择在java端替换的原因是异常抛出自executeScript方法的参数. + *

+ * 1.""中的""必须转义 + * 2.js字符串中的\n会导致js字符串变成多行,而js字符串不支持多行拼接 + * 3.由JSONObject.toString()得到的字符串中html标签的属性会自动加上\造成替换难度加大, + * 这边建议去除所有的html标签 + * + * @param old 原始字符串 + * @return 处理之后的字符串 + */ + private String trimText(String old) { + if (StringUtils.isNotBlank(old)) { + return old.replaceAll("\n", "").replaceAll("\"", "\\\\\"").replaceAll("\'", "\\\\\'"); + } + return StringUtils.EMPTY; + } } diff --git a/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java index 66282df9d..851c9e4e4 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java @@ -4,7 +4,6 @@ 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.*; diff --git a/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java index 390598835..0f79a1614 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java @@ -2,7 +2,6 @@ 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; @@ -15,8 +14,9 @@ import java.io.File; */ public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { private File zipFile; + protected JSCallback jsCallback; - public UpdateFromDiskCallback(File zipFile,JSCallback jsCallback) { + public UpdateFromDiskCallback(File zipFile, JSCallback jsCallback) { this.zipFile = zipFile; this.jsCallback = jsCallback; } @@ -29,14 +29,15 @@ public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { @Override public void done(PluginTaskResult result) { + jsCallback.execute("done"); 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"), + Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")), + Inter.getLocText("FR-Designer-Plugin_Install_Success"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, diff --git a/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java index cce4934b6..65a71a80c 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java @@ -14,9 +14,9 @@ import javax.swing.*; */ public class UpdateOnlineCallback extends AbstractPluginTaskCallback { public PluginMarker toPluginMarker; + protected JSCallback jsCallback; - - public UpdateOnlineCallback(PluginMarker pluginMarker , PluginMarker toPluginMarker, JSCallback jsCallback) { + public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) { this.pluginMarker = pluginMarker; this.toPluginMarker = toPluginMarker; this.jsCallback = jsCallback; @@ -29,14 +29,15 @@ public class UpdateOnlineCallback extends AbstractPluginTaskCallback { @Override public void done(PluginTaskResult result) { + jsCallback.execute("done"); 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"), + Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")), + Inter.getLocText("FR-Designer-Plugin_Install_Success"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, diff --git a/designer_base/src/com/fr/design/extra/exe/extratask/AbstractExtraPluginTask.java b/designer_base/src/com/fr/design/extra/exe/extratask/AbstractExtraPluginTask.java new file mode 100644 index 000000000..22cd8c826 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/extratask/AbstractExtraPluginTask.java @@ -0,0 +1,11 @@ +package com.fr.design.extra.exe.extratask; + +import com.fr.design.extra.exe.callback.JSCallback; +import com.fr.plugin.context.PluginMarker; + +/** + * Created by ibm on 2017/5/27. + */ +public abstract class AbstractExtraPluginTask implements ExtraPluginTask { + protected PluginMarker pluginMarker; +} diff --git a/designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java b/designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java index 4ae1fe381..37ac42d4d 100644 --- a/designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java +++ b/designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java @@ -6,18 +6,19 @@ 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){ +public class InstallPluginTask extends AbstractExtraPluginTask { + protected 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)); diff --git a/designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java b/designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java index c79ea114a..7cfdf9622 100644 --- a/designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java +++ b/designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java @@ -2,20 +2,18 @@ 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 class UpdatePluginTask extends AbstractExtraPluginTask { - public PluginMarker pluginMarker; public PluginMarker toPluginMarker; - public JSCallback jsCallback; + protected JSCallback jsCallback; - public UpdatePluginTask(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback){ + public UpdatePluginTask(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) { this.pluginMarker = pluginMarker; this.toPluginMarker = toPluginMarker; this.jsCallback = jsCallback; diff --git a/designer_base/src/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java b/designer_base/src/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java new file mode 100644 index 000000000..bac8d080a --- /dev/null +++ b/designer_base/src/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java @@ -0,0 +1,55 @@ +package com.fr.design.extra.tradition.callback; + +import com.fr.design.extra.PluginStatusCheckCompletePane; +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 com.fr.plugin.manage.control.ProgressCallback; + +import javax.swing.*; + +/** + * Created by ibm on 2017/5/31. + */ +public class UpdateOnlineCallback implements ProgressCallback { + private PluginStatusCheckCompletePane pane; + private PluginMarker pluginMarker; + private PluginMarker toPluginMarker; + + public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, PluginStatusCheckCompletePane pane){ + this.pluginMarker = pluginMarker; + this.toPluginMarker = toPluginMarker; + this.pane = pane; + } + public void updateProgress(String description, double progress){ + pane.setProgress(progress); + } + + 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_Dependence")), + Inter.getLocText("FR-Designer-Plugin_Install_Success"), + 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, pane)); + } 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); + } + } +}