From cbbf0bf07c5466298fbd67d5edce8a079fb583f6 Mon Sep 17 00:00:00 2001 From: vito Date: Fri, 8 Apr 2016 23:08:57 +0800 Subject: [PATCH 01/11] =?UTF-8?q?1=E3=80=81=E6=9B=B4=E6=94=B9=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=AA=97=E5=8F=A3=E4=BB=A5=E9=80=82=E9=85=8D=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=95=86=E5=BA=97=E5=B8=83=E5=B1=80=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=202=E3=80=81=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=96=B0=E7=9A=84=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/server/PluginManagerAction.java | 3 +- .../src/com/fr/design/dialog/BasicDialog.java | 1 + .../src/com/fr/design/dialog/BasicPane.java | 766 +++++++++--------- .../com/fr/design/extra/PluginWebBridge.java | 25 + .../com/fr/design/extra/PluginWebPane.java | 5 +- 5 files changed, 430 insertions(+), 370 deletions(-) diff --git a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java index 91b4eb810..646eb479a 100644 --- a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java +++ b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java @@ -28,8 +28,7 @@ public class PluginManagerAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { final PluginManagerPane managerPane = new PluginManagerPane(); - BasicDialog dlg = managerPane.showLargeWindow(DesignerContext.getDesignerFrame(),null); - + BasicDialog dlg = managerPane.showCustomSizeWindow(DesignerContext.getDesignerFrame(), null, BasicDialog.LARGE_SHOP); dlg.setVisible(true); } diff --git a/designer_base/src/com/fr/design/dialog/BasicDialog.java b/designer_base/src/com/fr/design/dialog/BasicDialog.java index 703b19205..a1f2785cf 100644 --- a/designer_base/src/com/fr/design/dialog/BasicDialog.java +++ b/designer_base/src/com/fr/design/dialog/BasicDialog.java @@ -10,6 +10,7 @@ public abstract class BasicDialog extends UIDialog { public static final Dimension MEDIUM = new Dimension(600, 400); public static final Dimension DEFAULT = new Dimension(660, 600); public static final Dimension LARGE = new Dimension(900, 600); + public static final Dimension LARGE_SHOP = new Dimension(900, 760); public static final Dimension CHART = new Dimension(760, 560); public static final Dimension MAP_SIZE = new Dimension(760, 450); public static final Dimension UPDATE_ONLINE_SIZE = new Dimension(600,300); diff --git a/designer_base/src/com/fr/design/dialog/BasicPane.java b/designer_base/src/com/fr/design/dialog/BasicPane.java index c94c246bf..09190f20f 100644 --- a/designer_base/src/com/fr/design/dialog/BasicPane.java +++ b/designer_base/src/com/fr/design/dialog/BasicPane.java @@ -16,380 +16,414 @@ import java.awt.*; */ public abstract class BasicPane extends JPanel { - /** - *显示窗口 - * @param window 窗口 - * @return 对话框 - */ - public BasicDialog showWindow(Window window) { - return this.showWindow(window, null); - } - - - /** - * 显示窗口 - * @param window 窗口 - * @param l 对话框监听器 - * @return 对话框 - */ - public BasicDialog showWindow(Window window, DialogActionListener l) { - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window); - } else { - dg = new DIALOG((Dialog) window); - } - - if (l != null) { - dg.addDialogActionListener(l); - } - - dg.setBasicDialogSize(BasicDialog.DEFAULT); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - /** - * 显示窗口 - * @param window 窗口 - * @param isNeedButtonsPane 是否需要确定删除按钮 - * @return 对话框 - */ - public BasicDialog showWindow(Window window, boolean isNeedButtonsPane) { - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window, isNeedButtonsPane); - } else { - dg = new DIALOG((Dialog) window, isNeedButtonsPane); - } - dg.setBasicDialogSize(BasicDialog.DEFAULT); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - - - /** - * 图表类型选择时 弹出的按钮大小, 不适合用最大最小, 因为图表大小 默认是规定好的, 那么界面大小也是必须配合. - * 并且包括 条件显示中 多个条件的大小 - * @param window 窗口 - * @param l 监听器 - * @return 对话框 - */ - public BasicDialog showWindow4ChartType(Window window, DialogActionListener l) { - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window); - } else { - dg = new DIALOG((Dialog) window); - } - - if (l != null) { - dg.addDialogActionListener(l); - } - - dg.setBasicDialogSize(BasicDialog.CHART); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - /** - * 显示窗口 - * @param window 窗口 - * @param l 对话框监听器 - * @return 对话框 - */ - public BasicDialog showSmallWindow(Window window, DialogActionListener l) { - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window); - } else { - dg = new DIALOG((Dialog) window); - } - - if (l != null) { - dg.addDialogActionListener(l); - } - dg.setBasicDialogSize(BasicDialog.SMALL); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - /** - * 显示窗口 - * @param window 窗口 - * @param l 对话框监听器 - * @return 对话框 - */ - public BasicDialog showMediumWindow(Window window, DialogActionListener l) { - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window); - } else { - dg = new DIALOG((Dialog) window); - } - - if (l != null) { - dg.addDialogActionListener(l); - } - dg.setBasicDialogSize(BasicDialog.MEDIUM); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - /** - * 显示窗口 - * @param window 窗口 - * @param l 对话框监听器 - * @return 对话框 - */ - public BasicDialog showLargeWindow(Window window, DialogActionListener l) { - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window); - } else { - dg = new DIALOG((Dialog) window); - } - - if (l != null) { - dg.addDialogActionListener(l); - } - dg.setBasicDialogSize(BasicDialog.LARGE); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - /** - * 显示窗口 - * @param window 窗口 - * @param l 对话框监听器 - * @return 对话框 - */ - public UIDialog showUnsizedWindow(Window window, DialogActionListener l) { - UIDialog dg; - if (window instanceof Frame) { - dg = new UnsizedDialog((Frame) window); - } else { - dg = new UnsizedDialog((Dialog) window); - } - - if (l != null) { - dg.addDialogActionListener(l); - } - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - /** - * 显示窗口 - * @param window 窗口 - * @param l 对话框监听器 - * @return 对话框 - */ - public BasicDialog showWindow4ChartMapArray(Window window,DialogActionListener l){ - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window); - } else { - dg = new DIALOG((Dialog) window); - } - - if (l != null) { - dg.addDialogActionListener(l); - } - dg.setBasicDialogSize(BasicDialog.MAP_SIZE); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - - /** - * 显示窗口 - * @param window 窗口 - * @return 对话框 - */ - public BasicDialog showWindow4UpdateOnline(Window window){ - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window,false); - } else { - dg = new DIALOG((Dialog) window,false); - } - dg.setBasicDialogSize(BasicDialog.UPDATE_ONLINE_SIZE); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - - protected abstract String title4PopupWindow(); - - public String getTitle(){ - return title4PopupWindow(); - } - - /** - * 作为名字面板 - * @return 面板 - */ - public NamePane asNamePane() { - return new NamePane(this); - } - - /** - * 检查是否符合规范 + /** + * 显示窗口 * - * @throws Exception 异常 - */ - public void checkValid() throws Exception { - } - - public static final class NamePane extends BasicPane { - private UITextField nameTextField; - private BasicPane centerPane; - private UILabel showfield; - private PropertyChangeAdapter changeListener; - - private NamePane(BasicPane bPane) { - this.setLayout(new BorderLayout(4, 4)); - - nameTextField = new UITextField(30); - JPanel northPane = new JPanel(new BorderLayout(4, 4)); - northPane.add(new UILabel(Inter.getLocText("FR-Designer-Hyperlink_Name") + ":"), BorderLayout.WEST); - northPane.add(nameTextField, BorderLayout.CENTER); - northPane.add(showfield = new UILabel(" "), BorderLayout.EAST); - showfield.setForeground(new Color(204, 0, 1)); - showfield.setPreferredSize(new Dimension(220, showfield.getPreferredSize().height)); - this.add(northPane, BorderLayout.NORTH); - this.centerPane = bPane; - this.add(bPane, BorderLayout.CENTER); - this.nameTextField.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() { - - @Override - public void insertUpdate(DocumentEvent e) { - doTextChanged(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - doTextChanged(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - doTextChanged(); - } - - }); - } - - private void doTextChanged() { - if (changeListener != null) { - changeListener.propertyChange(); - } - } - - public String getObjectName() { - return this.nameTextField.getText().trim(); - } - - public void setObjectName(String name) { - this.nameTextField.setText(name); - } - - public void setShowText(String name) { - this.showfield.setText(name); - } - - @Override - protected String title4PopupWindow() { - return centerPane.title4PopupWindow(); - } - - /** - * 检查是否符合规范 - * - * @throws Exception 异常 - */ - public void checkValid() throws Exception { - super.checkValid(); - - this.centerPane.checkValid(); - } - - /** - * 添加属性改变的监听器 - * @param listener 监听器 - */ - public void addPropertyChangeListener(PropertyChangeAdapter listener) { - this.changeListener = listener; - } - } - - private class DIALOG extends BasicDialog { - public DIALOG(Frame parent) { - super(parent, BasicPane.this); - this.setTitle(BasicPane.this.title4PopupWindow()); - } - - public DIALOG(Dialog parent) { - super(parent, BasicPane.this); - this.setTitle(BasicPane.this.title4PopupWindow()); - } - - - public DIALOG(Frame parent, boolean isNeedButtonPane) { - super(parent, BasicPane.this, isNeedButtonPane); - this.setTitle(BasicPane.this.title4PopupWindow()); - } - - - public DIALOG(Dialog parent, boolean isNeedButtonPane) { - super(parent, BasicPane.this, isNeedButtonPane); - this.setTitle(BasicPane.this.title4PopupWindow()); - } - - - - /** - * init Components - */ - - - /** - * Check valid. - */ - public void checkValid() throws Exception { - BasicPane.this.checkValid(); - } + * @param window 窗口 + * @return 对话框 + */ + public BasicDialog showWindow(Window window) { + return this.showWindow(window, null); + } - } - private class UnsizedDialog extends UIDialog { + /** + * 显示窗口 + * + * @param window 窗口 + * @param l 对话框监听器 + * @return 对话框 + */ + public BasicDialog showWindow(Window window, DialogActionListener l) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window); + } else { + dg = new DIALOG((Dialog) window); + } + + if (l != null) { + dg.addDialogActionListener(l); + } + + dg.setBasicDialogSize(BasicDialog.DEFAULT); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + /** + * 显示窗口 + * + * @param window 窗口 + * @param isNeedButtonsPane 是否需要确定删除按钮 + * @return 对话框 + */ + public BasicDialog showWindow(Window window, boolean isNeedButtonsPane) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window, isNeedButtonsPane); + } else { + dg = new DIALOG((Dialog) window, isNeedButtonsPane); + } + dg.setBasicDialogSize(BasicDialog.DEFAULT); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + + /** + * 图表类型选择时 弹出的按钮大小, 不适合用最大最小, 因为图表大小 默认是规定好的, 那么界面大小也是必须配合. + * 并且包括 条件显示中 多个条件的大小 + * + * @param window 窗口 + * @param l 监听器 + * @return 对话框 + */ + public BasicDialog showWindow4ChartType(Window window, DialogActionListener l) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window); + } else { + dg = new DIALOG((Dialog) window); + } + + if (l != null) { + dg.addDialogActionListener(l); + } + + dg.setBasicDialogSize(BasicDialog.CHART); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + /** + * 显示窗口 + * + * @param window 窗口 + * @param l 对话框监听器 + * @return 对话框 + */ + public BasicDialog showSmallWindow(Window window, DialogActionListener l) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window); + } else { + dg = new DIALOG((Dialog) window); + } + + if (l != null) { + dg.addDialogActionListener(l); + } + dg.setBasicDialogSize(BasicDialog.SMALL); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + /** + * 显示窗口 + * + * @param window 窗口 + * @param l 对话框监听器 + * @return 对话框 + */ + public BasicDialog showMediumWindow(Window window, DialogActionListener l) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window); + } else { + dg = new DIALOG((Dialog) window); + } + + if (l != null) { + dg.addDialogActionListener(l); + } + dg.setBasicDialogSize(BasicDialog.MEDIUM); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + /** + * 显示窗口 + * + * @param window 窗口 + * @param l 对话框监听器 + * @return 对话框 + */ + public BasicDialog showLargeWindow(Window window, DialogActionListener l) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window); + } else { + dg = new DIALOG((Dialog) window); + } + + if (l != null) { + dg.addDialogActionListener(l); + } + dg.setBasicDialogSize(BasicDialog.LARGE); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + /** + * 显示自定义大小的窗口 + * + * @param window 窗口 + * @param l 对话框监听器 + * @param dimension 窗口大小 + * @return 对话框 + */ + public BasicDialog showCustomSizeWindow(Window window, DialogActionListener l, Dimension dimension) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window); + } else { + dg = new DIALOG((Dialog) window); + } + if (l != null) { + dg.addDialogActionListener(l); + } + dg.setBasicDialogSize(dimension); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + /** + * 显示窗口 + * + * @param window 窗口 + * @param l 对话框监听器 + * @return 对话框 + */ + public UIDialog showUnsizedWindow(Window window, DialogActionListener l) { + UIDialog dg; + if (window instanceof Frame) { + dg = new UnsizedDialog((Frame) window); + } else { + dg = new UnsizedDialog((Dialog) window); + } + + if (l != null) { + dg.addDialogActionListener(l); + } + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + /** + * 显示窗口 + * + * @param window 窗口 + * @param l 对话框监听器 + * @return 对话框 + */ + public BasicDialog showWindow4ChartMapArray(Window window, DialogActionListener l) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window); + } else { + dg = new DIALOG((Dialog) window); + } + + if (l != null) { + dg.addDialogActionListener(l); + } + dg.setBasicDialogSize(BasicDialog.MAP_SIZE); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + + /** + * 显示窗口 + * + * @param window 窗口 + * @return 对话框 + */ + public BasicDialog showWindow4UpdateOnline(Window window) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window, false); + } else { + dg = new DIALOG((Dialog) window, false); + } + dg.setBasicDialogSize(BasicDialog.UPDATE_ONLINE_SIZE); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + + protected abstract String title4PopupWindow(); + + public String getTitle() { + return title4PopupWindow(); + } + + /** + * 作为名字面板 + * + * @return 面板 + */ + public NamePane asNamePane() { + return new NamePane(this); + } - public UnsizedDialog(Frame parent) { - super(parent, BasicPane.this); - this.setTitle(BasicPane.this.title4PopupWindow()); - } + /** + * 检查是否符合规范 + * + * @throws Exception 异常 + */ + public void checkValid() throws Exception { + } + + public static final class NamePane extends BasicPane { + private UITextField nameTextField; + private BasicPane centerPane; + private UILabel showfield; + private PropertyChangeAdapter changeListener; + + private NamePane(BasicPane bPane) { + this.setLayout(new BorderLayout(4, 4)); + + nameTextField = new UITextField(30); + JPanel northPane = new JPanel(new BorderLayout(4, 4)); + northPane.add(new UILabel(Inter.getLocText("FR-Designer-Hyperlink_Name") + ":"), BorderLayout.WEST); + northPane.add(nameTextField, BorderLayout.CENTER); + northPane.add(showfield = new UILabel(" "), BorderLayout.EAST); + showfield.setForeground(new Color(204, 0, 1)); + showfield.setPreferredSize(new Dimension(220, showfield.getPreferredSize().height)); + this.add(northPane, BorderLayout.NORTH); + this.centerPane = bPane; + this.add(bPane, BorderLayout.CENTER); + this.nameTextField.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() { + + @Override + public void insertUpdate(DocumentEvent e) { + doTextChanged(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + doTextChanged(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + doTextChanged(); + } + + }); + } + + private void doTextChanged() { + if (changeListener != null) { + changeListener.propertyChange(); + } + } + + public String getObjectName() { + return this.nameTextField.getText().trim(); + } + + public void setObjectName(String name) { + this.nameTextField.setText(name); + } + + public void setShowText(String name) { + this.showfield.setText(name); + } + + @Override + protected String title4PopupWindow() { + return centerPane.title4PopupWindow(); + } + + /** + * 检查是否符合规范 + * + * @throws Exception 异常 + */ + public void checkValid() throws Exception { + super.checkValid(); + + this.centerPane.checkValid(); + } + + /** + * 添加属性改变的监听器 + * + * @param listener 监听器 + */ + public void addPropertyChangeListener(PropertyChangeAdapter listener) { + this.changeListener = listener; + } + } + + private class DIALOG extends BasicDialog { + public DIALOG(Frame parent) { + super(parent, BasicPane.this); + this.setTitle(BasicPane.this.title4PopupWindow()); + } + + public DIALOG(Dialog parent) { + super(parent, BasicPane.this); + this.setTitle(BasicPane.this.title4PopupWindow()); + } + + + public DIALOG(Frame parent, boolean isNeedButtonPane) { + super(parent, BasicPane.this, isNeedButtonPane); + this.setTitle(BasicPane.this.title4PopupWindow()); + } + + + public DIALOG(Dialog parent, boolean isNeedButtonPane) { + super(parent, BasicPane.this, isNeedButtonPane); + this.setTitle(BasicPane.this.title4PopupWindow()); + } + + + /** + * init Components + */ + + + /** + * Check valid. + */ + public void checkValid() throws Exception { + BasicPane.this.checkValid(); + } + + } - public UnsizedDialog(Dialog parent) { - super(parent, BasicPane.this); - this.setTitle(BasicPane.this.title4PopupWindow()); - } + private class UnsizedDialog extends UIDialog { + + public UnsizedDialog(Frame parent) { + super(parent, BasicPane.this); + this.setTitle(BasicPane.this.title4PopupWindow()); + } + + public UnsizedDialog(Dialog parent) { + super(parent, BasicPane.this); + this.setTitle(BasicPane.this.title4PopupWindow()); + } - public void checkValid() throws Exception { - BasicPane.this.checkValid(); - } + public void checkValid() throws Exception { + BasicPane.this.checkValid(); + } - } + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index b4eb6e9e1..b32dcdd40 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -1,6 +1,8 @@ package com.fr.design.extra; import com.fr.design.extra.exe.*; +import com.fr.general.FRLogger; +import com.fr.general.http.HttpClient; import com.fr.json.JSONArray; import com.fr.json.JSONObject; import com.fr.plugin.Plugin; @@ -157,6 +159,7 @@ public class PluginWebBridge { /** * 获取已经安装的插件的数组 + * * @return 已安装的插件组成的数组 */ public Plugin[] getInstalledPlugins() { @@ -174,4 +177,26 @@ public class PluginWebBridge { } return list.toArray(new String[len]); } + + public String getPluginFromStore(String category, String seller, String fee) { + + StringBuilder url = new StringBuilder("http://127.0.0.1:8080/ShopServer?pg=plist"); + 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]); + } + String resText = null; + try { + HttpClient httpClient = new HttpClient(url.toString()); + resText = httpClient.getResponseText(); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + return resText == null ? StringUtils.EMPTY : resText; + } } diff --git a/designer_base/src/com/fr/design/extra/PluginWebPane.java b/designer_base/src/com/fr/design/extra/PluginWebPane.java index 8b899220f..54c882bdd 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebPane.java +++ b/designer_base/src/com/fr/design/extra/PluginWebPane.java @@ -5,6 +5,7 @@ import javafx.embed.swing.JFXPanel; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; +import javafx.scene.layout.BorderPane; import javafx.scene.web.WebEngine; import javafx.scene.web.WebEvent; import javafx.scene.web.WebView; @@ -24,7 +25,7 @@ public class PluginWebPane extends JFXPanel { Platform.runLater(new Runnable() { @Override public void run() { - Group root = new Group(); + BorderPane root = new BorderPane(); Scene scene = new Scene(root); PluginWebPane.this.setScene(scene); WebView webView = new WebView(); @@ -38,7 +39,7 @@ public class PluginWebPane extends JFXPanel { }); JSObject obj = (JSObject) webEngine.executeScript("window"); obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine)); - root.getChildren().add(webView); + root.setCenter(webView); } }); } From 69455f31fa77ab0f494cace53f993968a2f5cfd3 Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 12 Apr 2016 18:51:04 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/server/PluginManagerAction.java | 4 ++ .../com/fr/design/extra/PluginWebBridge.java | 39 +++++++++++++++---- .../com/fr/design/extra/PluginWebPane.java | 1 - 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java index 646eb479a..4225f0c4f 100644 --- a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java +++ b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java @@ -3,7 +3,9 @@ package com.fr.design.actions.server; import com.fr.base.BaseUtils; import com.fr.design.actions.UpdateAction; import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.UIDialog; import com.fr.design.extra.PluginManagerPane; +import com.fr.design.extra.PluginWebBridge; import com.fr.design.mainframe.DesignerContext; import com.fr.design.menu.MenuKeySet; import com.fr.general.Inter; @@ -28,7 +30,9 @@ public class PluginManagerAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { final PluginManagerPane managerPane = new PluginManagerPane(); + //// TODO: 16/4/11 重新写下这个界面窗口. BasicDialog dlg = managerPane.showCustomSizeWindow(DesignerContext.getDesignerFrame(), null, BasicDialog.LARGE_SHOP); + PluginWebBridge.getHelper().setDialogHandle(dlg); dlg.setVisible(true); } diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index b32dcdd40..6a1ad0f28 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -1,10 +1,10 @@ package com.fr.design.extra; +import com.fr.design.actions.server.PluginManagerAction; +import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; import com.fr.general.FRLogger; import com.fr.general.http.HttpClient; -import com.fr.json.JSONArray; -import com.fr.json.JSONObject; import com.fr.plugin.Plugin; import com.fr.plugin.PluginLoader; import com.fr.stable.ArrayUtils; @@ -15,6 +15,7 @@ import javafx.stage.FileChooser; import javafx.stage.Stage; import netscape.javascript.JSObject; +import javax.swing.*; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -26,24 +27,38 @@ public class PluginWebBridge { private static PluginWebBridge helper; - public static PluginWebBridge getHelper(WebEngine webEngine) { + private UIDialog uiDialog; + + public static PluginWebBridge getHelper() { if (helper != null) { return helper; } synchronized (PluginWebBridge.class) { if (helper == null) { - helper = new PluginWebBridge(webEngine); + helper = new PluginWebBridge(); } return helper; } } + public static PluginWebBridge getHelper(WebEngine webEngine) { + getHelper(); + helper.setEngine(webEngine); + return helper; + } + private WebEngine webEngine; - private PluginWebBridge(WebEngine webEngine) { + private PluginWebBridge() { + } + + public void setEngine(WebEngine webEngine){ this.webEngine = webEngine; } + public void setDialogHandle(UIDialog uiDialog){ + this.uiDialog = uiDialog; + } /** * 从插件服务器上安装插件 * @@ -181,13 +196,13 @@ public class PluginWebBridge { public String getPluginFromStore(String category, String seller, String fee) { StringBuilder url = new StringBuilder("http://127.0.0.1:8080/ShopServer?pg=plist"); - if(StringUtils.isNotBlank(category)){ + if (StringUtils.isNotBlank(category)) { url.append("&cid=").append(category.split("-")[1]); } - if(StringUtils.isNotBlank(seller)){ + if (StringUtils.isNotBlank(seller)) { url.append("&seller=").append(seller.split("-")[1]); } - if(StringUtils.isNotBlank(fee)){ + if (StringUtils.isNotBlank(fee)) { url.append("&fee=").append(fee.split("-")[1]); } String resText = null; @@ -199,4 +214,12 @@ public class PluginWebBridge { } return resText == null ? StringUtils.EMPTY : resText; } + + public void closeWindow() { + if (uiDialog != null) { + uiDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + uiDialog.setVisible(false); + uiDialog.dispose(); + } + } } diff --git a/designer_base/src/com/fr/design/extra/PluginWebPane.java b/designer_base/src/com/fr/design/extra/PluginWebPane.java index 54c882bdd..7a864bdcb 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebPane.java +++ b/designer_base/src/com/fr/design/extra/PluginWebPane.java @@ -3,7 +3,6 @@ package com.fr.design.extra; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.event.EventHandler; -import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.scene.web.WebEngine; From 36b48b30dc4c340b5d98d26ff44cc1d9eaf9c151 Mon Sep 17 00:00:00 2001 From: vito Date: Thu, 14 Apr 2016 10:38:27 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/extra/PluginWebBridge.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 6a1ad0f28..0f5122f3e 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -1,6 +1,5 @@ package com.fr.design.extra; -import com.fr.design.actions.server.PluginManagerAction; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; import com.fr.general.FRLogger; @@ -114,10 +113,9 @@ public class PluginWebBridge { * 修改选中的插件的活跃状态 * * @param pluginID 插件ID - * @param active 如果要把插件修改为激活状态,则为true,否则为false */ - public void setPluginActive(String pluginID, boolean active, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new ModifyStatusExecutor(pluginID, active)); + public void setPluginActive(String pluginID, final JSObject callback) { + Task task = new PluginTask<>(webEngine, callback, new ModifyStatusExecutor(pluginID)); new Thread(task).start(); } @@ -195,7 +193,7 @@ public class PluginWebBridge { public String getPluginFromStore(String category, String seller, String fee) { - StringBuilder url = new StringBuilder("http://127.0.0.1:8080/ShopServer?pg=plist"); + StringBuilder url = new StringBuilder("http://192.168.101.20/ShopServer?pg=plist"); if (StringUtils.isNotBlank(category)) { url.append("&cid=").append(category.split("-")[1]); } @@ -208,6 +206,7 @@ public class PluginWebBridge { String resText = null; try { HttpClient httpClient = new HttpClient(url.toString()); + //httpClient.setTimeout(5000); resText = httpClient.getResponseText(); } catch (Exception e) { FRLogger.getLogger().error(e.getMessage()); @@ -217,9 +216,8 @@ public class PluginWebBridge { public void closeWindow() { if (uiDialog != null) { - uiDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); uiDialog.setVisible(false); - uiDialog.dispose(); } } } From 97140c177cbd03777b1bd70300175d78d2204c97 Mon Sep 17 00:00:00 2001 From: vito Date: Sat, 16 Apr 2016 02:03:28 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=95=86=E5=BA=97API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/bbs/BBSDialog.java | 3 +- .../com/fr/design/extra/PluginWebBridge.java | 80 +++++++++++++++++-- .../extra/exe/InstallFromDiskExecutor.java | 28 +++++-- .../extra/exe/InstallOnlineExecutor.java | 33 +++++++- .../extra/exe/ModifyStatusExecutor.java | 34 +++++++- .../design/extra/exe/UninstallExecutor.java | 50 +++++++++++- .../extra/exe/UpdateFromDiskExecutor.java | 20 ++++- 7 files changed, 222 insertions(+), 26 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java index 8dbdd0acf..856e9264a 100644 --- a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java +++ b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java @@ -143,9 +143,8 @@ public class BBSDialog extends UIDialog { * 提供给web页面调用的关闭窗口 */ public void closeWindow() { - this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setVisible(false); - this.dispose(); } /** * 略 diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 0f5122f3e..ce6dd8fba 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -1,8 +1,11 @@ package com.fr.design.extra; +import com.fr.base.FRContext; +import com.fr.design.RestartHelper; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; import com.fr.general.FRLogger; +import com.fr.general.Inter; import com.fr.general.http.HttpClient; import com.fr.plugin.Plugin; import com.fr.plugin.PluginLoader; @@ -92,10 +95,10 @@ public class PluginWebBridge { /** * 从插件服务器上更新选中的插件 * - * @param pluginID 插件的ID + * @param pluginIDs 插件集合 */ - public void updatePluginOnline(String pluginID, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new UpdateOnlineExecutor(pluginID)); + public void updatePluginOnline(JSObject pluginIDs, final JSObject callback) { + Task task = new PluginTask<>(webEngine, callback, new UpdateOnlineExecutor(jsObjectToStringArray(pluginIDs))); new Thread(task).start(); } @@ -193,7 +196,7 @@ public class PluginWebBridge { public String getPluginFromStore(String category, String seller, String fee) { - StringBuilder url = new StringBuilder("http://192.168.101.20/ShopServer?pg=plist"); + StringBuilder url = new StringBuilder("http://127.0.0.1:8080/ShopServer?pg=plist"); if (StringUtils.isNotBlank(category)) { url.append("&cid=").append(category.split("-")[1]); } @@ -206,7 +209,7 @@ public class PluginWebBridge { String resText = null; try { HttpClient httpClient = new HttpClient(url.toString()); - //httpClient.setTimeout(5000); + httpClient.setTimeout(3000); resText = httpClient.getResponseText(); } catch (Exception e) { FRLogger.getLogger().error(e.getMessage()); @@ -214,10 +217,77 @@ public class PluginWebBridge { return resText == null ? StringUtils.EMPTY : resText; } + + public void showRestartMessage(String message){ + int rv = JOptionPane.showOptionDialog( + null, + message, + 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(); + } + } + public void closeWindow() { if (uiDialog != null) { uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); uiDialog.setVisible(false); } } + + public void updateFileFromDisk(File fileOnDisk){ + try { + Plugin plugin = PluginHelper.readPlugin(fileOnDisk); + if (plugin == null) { + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + return; + } + 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( + null, + 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); + } + } + }); + } else { + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Version_Is_Lower_Than_Current"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } else { + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } catch (Exception e1) { + JOptionPane.showMessageDialog(null, e1.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } } diff --git a/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java b/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java index 098a91c02..cb803f314 100644 --- a/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java @@ -1,5 +1,16 @@ package com.fr.design.extra.exe; +import com.fr.design.RestartHelper; +import com.fr.design.extra.After; +import com.fr.design.extra.PluginHelper; +import com.fr.design.extra.PluginWebBridge; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import org.apache.poi.poifs.crypt.AgileDecryptor; + +import javax.swing.*; +import java.io.File; + /** * Created by richie on 16/3/19. */ @@ -27,11 +38,6 @@ public class InstallFromDiskExecutor implements Executor { @Override public void run() { - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } } }, new Command() { @@ -43,9 +49,15 @@ public class InstallFromDiskExecutor implements Executor { @Override public void run() { try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); + PluginHelper.installPluginFromDisk(new File(filePath), new After() { + @Override + public void done() { + FRLogger.getLogger().info("插件安装成功"); + PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Install_Successful")); + } + }); + } catch (Exception e1) { + FRLogger.getLogger().error(e1.getMessage()); } } } diff --git a/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java index 7baf378fd..348898877 100644 --- a/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java @@ -1,5 +1,16 @@ package com.fr.design.extra.exe; +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.RestartHelper; +import com.fr.design.extra.After; +import com.fr.design.extra.PluginHelper; +import com.fr.design.extra.PluginWebBridge; +import com.fr.design.extra.Process; +import com.fr.general.Inter; + +import javax.swing.*; + /** * Created by richie on 16/3/19. */ @@ -27,10 +38,17 @@ public class InstallOnlineExecutor implements Executor { @Override public void run() { + String username = DesignerEnvManager.getEnvManager().getBBSName(); + String password = DesignerEnvManager.getEnvManager().getBBSPassword(); try { - Thread.sleep(3000); - } catch (InterruptedException e) { - e.printStackTrace(); + PluginHelper.downloadPluginFile(pluginID,username,password, new Process() { + @Override + public void process(Double integer) { + + } + }); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); } } }, @@ -43,9 +61,16 @@ public class InstallOnlineExecutor implements Executor { @Override public void run() { try { - Thread.sleep(3000); + PluginHelper.installPluginFromDisk(PluginHelper.getDownloadTempFile(), new After() { + @Override + public void done() { + PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Update_Successful")); + } + }); } catch (InterruptedException e) { e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } } } diff --git a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java index ff5d82bd5..2d5b0f8c7 100644 --- a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java @@ -1,5 +1,12 @@ package com.fr.design.extra.exe; +import com.fr.base.FRContext; +import com.fr.design.extra.PluginWebBridge; +import com.fr.general.Inter; +import com.fr.plugin.Plugin; +import com.fr.plugin.PluginLoader; +import com.fr.stable.StringUtils; + /** * Created by richie on 16/3/19. */ @@ -7,19 +14,38 @@ public class ModifyStatusExecutor implements Executor { private String pluginID; private boolean active; + private Plugin plugin; - public ModifyStatusExecutor(String pluginID, boolean active) { + public ModifyStatusExecutor(String pluginID) { this.pluginID = pluginID; - this.active = active; } @Override public String getTaskFinishMessage() { - return "插件" + pluginID + "已更改为可用状态:" + active; + 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[0]; + return new Command[]{ + new Command() { + @Override + public String getExecuteMessage() { + return StringUtils.EMPTY; + } + @Override + public void run() { + plugin = PluginLoader.getLoader().getPluginById(pluginID); + active = !plugin.isActive(); + plugin.setActive(active); + try { + FRContext.getCurrentEnv().writePlugin(plugin); + PluginWebBridge.getHelper().showRestartMessage(plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled")); + } catch (Exception e) { + FRContext.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 index 5138c1a58..56b1c5304 100644 --- a/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java @@ -1,5 +1,14 @@ package com.fr.design.extra.exe; +import com.fr.base.FRContext; +import com.fr.design.RestartHelper; +import com.fr.design.extra.PluginHelper; +import com.fr.general.Inter; +import com.fr.plugin.Plugin; +import com.fr.plugin.PluginLoader; + +import javax.swing.*; + /** * Created by richie on 16/3/19. */ @@ -18,6 +27,45 @@ public class UninstallExecutor implements Executor { @Override public Command[] getCommands() { - return new Command[0]; + return new Command[]{ + new Command() { + @Override + public String getExecuteMessage() { + return "删除成功"; + } + + @Override + public void run() { + int rv = JOptionPane.showOptionDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), + Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later"), + Inter.getLocText("FR-Designer-Basic_Cancel") + }, + null + ); + if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { + return; + } + for (String pluginID : pluginIDs) { + try { + Plugin plugin = PluginLoader.getLoader().getPluginById(pluginID); + String[] filesToBeDelete = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), plugin); + RestartHelper.saveFilesWhichToDelete(filesToBeDelete); + } catch (Exception e) { + JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } + if (rv == JOptionPane.OK_OPTION) { + RestartHelper.restart(); + } + } + } + }; } } diff --git a/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java b/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java index cfc0ab222..26615b9b3 100644 --- a/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java @@ -1,5 +1,9 @@ package com.fr.design.extra.exe; +import com.fr.design.extra.PluginWebBridge; + +import java.io.File; + /** * Created by richie on 16/3/19. */ @@ -13,11 +17,23 @@ public class UpdateFromDiskExecutor implements Executor { @Override public String getTaskFinishMessage() { - return "插件已更新完毕"; + return "插件更新操作结束"; } @Override public Command[] getCommands() { - return new Command[0]; + return new Command[]{ + new Command() { + @Override + public String getExecuteMessage() { + return null; + } + + @Override + public void run() { + PluginWebBridge.getHelper().updateFileFromDisk(new File(filePath)); + } + } + }; } } From 1987927759d80c828bead3bf708b7b03a4c59c91 Mon Sep 17 00:00:00 2001 From: vito Date: Sun, 17 Apr 2016 02:04:46 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=95=86=E5=BA=97?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9Bjava=E6=95=B0=E6=8D=AEAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/extra/PluginTask.java | 15 ++- .../src/com/fr/design/extra/exe/Command.java | 4 +- .../extra/exe/InstallFromDiskExecutor.java | 15 +-- .../extra/exe/InstallOnlineExecutor.java | 14 +-- .../extra/exe/ModifyStatusExecutor.java | 3 +- .../design/extra/exe/UninstallExecutor.java | 3 +- .../extra/exe/UpdateFromDiskExecutor.java | 3 +- .../extra/exe/UpdateOnlineExecutor.java | 95 +++++++++++++++++-- 8 files changed, 128 insertions(+), 24 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/PluginTask.java b/designer_base/src/com/fr/design/extra/PluginTask.java index e67f4e426..a86e088b3 100644 --- a/designer_base/src/com/fr/design/extra/PluginTask.java +++ b/designer_base/src/com/fr/design/extra/PluginTask.java @@ -2,6 +2,7 @@ package com.fr.design.extra; import com.fr.design.extra.exe.Executor; import com.fr.design.extra.exe.Command; +import com.fr.stable.StringUtils; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.concurrent.Task; @@ -10,6 +11,7 @@ import netscape.javascript.JSObject; /** * 插件安装,卸载,更新等任务 + * * @param */ public class PluginTask extends Task { @@ -40,8 +42,17 @@ public class PluginTask extends Task { Command[] commands = executor.getCommands(); for (Command command : commands) { String message = command.getExecuteMessage(); - updateMessage(message); - command.run(); + if (StringUtils.isNotBlank(message)) { + updateMessage(message); + } + command.run(new Process() { + @Override + public void process(String s) { + if (StringUtils.isNotBlank(s)) { + updateMessage(s); + } + } + }); } return null; } diff --git a/designer_base/src/com/fr/design/extra/exe/Command.java b/designer_base/src/com/fr/design/extra/exe/Command.java index 5b117586e..c16b0c288 100644 --- a/designer_base/src/com/fr/design/extra/exe/Command.java +++ b/designer_base/src/com/fr/design/extra/exe/Command.java @@ -1,5 +1,7 @@ package com.fr.design.extra.exe; +import com.fr.design.extra.Process; + /** * Created by richie on 16/3/19. */ @@ -7,5 +9,5 @@ public interface Command { String getExecuteMessage(); - void run(); + void run(Process process); } diff --git a/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java b/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java index cb803f314..da5222f96 100644 --- a/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java @@ -1,12 +1,12 @@ package com.fr.design.extra.exe; -import com.fr.design.RestartHelper; import com.fr.design.extra.After; import com.fr.design.extra.PluginHelper; import com.fr.design.extra.PluginWebBridge; +import com.fr.design.extra.Process; import com.fr.general.FRLogger; import com.fr.general.Inter; -import org.apache.poi.poifs.crypt.AgileDecryptor; +import com.fr.plugin.PluginVerifyException; import javax.swing.*; import java.io.File; @@ -37,7 +37,8 @@ public class InstallFromDiskExecutor implements Executor { } @Override - public void run() { + public void run(Process process) { + } }, new Command() { @@ -47,7 +48,7 @@ public class InstallFromDiskExecutor implements Executor { } @Override - public void run() { + public void run(Process process) { try { PluginHelper.installPluginFromDisk(new File(filePath), new After() { @Override @@ -56,8 +57,10 @@ public class InstallFromDiskExecutor implements Executor { PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Install_Successful")); } }); - } catch (Exception e1) { - FRLogger.getLogger().error(e1.getMessage()); + } catch (PluginVerifyException e) { + JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); } } } diff --git a/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java index 348898877..bd3711bd6 100644 --- a/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java @@ -2,12 +2,12 @@ package com.fr.design.extra.exe; import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; -import com.fr.design.RestartHelper; import com.fr.design.extra.After; import com.fr.design.extra.PluginHelper; import com.fr.design.extra.PluginWebBridge; import com.fr.design.extra.Process; import com.fr.general.Inter; +import com.fr.plugin.PluginVerifyException; import javax.swing.*; @@ -24,7 +24,7 @@ public class InstallOnlineExecutor implements Executor { @Override public String getTaskFinishMessage() { - return "已成功安裝"; + return "task succeed"; } @Override @@ -37,14 +37,14 @@ public class InstallOnlineExecutor implements Executor { } @Override - public void run() { + public void run(final Process process) { String username = DesignerEnvManager.getEnvManager().getBBSName(); String password = DesignerEnvManager.getEnvManager().getBBSPassword(); try { - PluginHelper.downloadPluginFile(pluginID,username,password, new Process() { + PluginHelper.downloadPluginFile(pluginID, username, password, new Process() { @Override public void process(Double integer) { - + process.process(Math.round(integer * 100) + "%"); } }); } catch (Exception e) { @@ -59,7 +59,7 @@ public class InstallOnlineExecutor implements Executor { } @Override - public void run() { + public void run(Process process) { try { PluginHelper.installPluginFromDisk(PluginHelper.getDownloadTempFile(), new After() { @Override @@ -67,6 +67,8 @@ public class InstallOnlineExecutor implements Executor { PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Update_Successful")); } }); + } catch (PluginVerifyException e) { + JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); } catch (InterruptedException e) { e.printStackTrace(); } catch (Exception e) { diff --git a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java index 2d5b0f8c7..c3fb43262 100644 --- a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java @@ -2,6 +2,7 @@ package com.fr.design.extra.exe; import com.fr.base.FRContext; import com.fr.design.extra.PluginWebBridge; +import com.fr.design.extra.Process; import com.fr.general.Inter; import com.fr.plugin.Plugin; import com.fr.plugin.PluginLoader; @@ -34,7 +35,7 @@ public class ModifyStatusExecutor implements Executor { return StringUtils.EMPTY; } @Override - public void run() { + public void run(Process process) { plugin = PluginLoader.getLoader().getPluginById(pluginID); active = !plugin.isActive(); plugin.setActive(active); diff --git a/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java b/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java index 56b1c5304..3f0845a7a 100644 --- a/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java @@ -3,6 +3,7 @@ package com.fr.design.extra.exe; import com.fr.base.FRContext; import com.fr.design.RestartHelper; import com.fr.design.extra.PluginHelper; +import com.fr.design.extra.Process; import com.fr.general.Inter; import com.fr.plugin.Plugin; import com.fr.plugin.PluginLoader; @@ -35,7 +36,7 @@ public class UninstallExecutor implements Executor { } @Override - public void run() { + public void run(Process process) { int rv = JOptionPane.showOptionDialog( null, Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"), diff --git a/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java b/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java index 26615b9b3..5c8c6e361 100644 --- a/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java @@ -1,6 +1,7 @@ package com.fr.design.extra.exe; import com.fr.design.extra.PluginWebBridge; +import com.fr.design.extra.Process; import java.io.File; @@ -30,7 +31,7 @@ public class UpdateFromDiskExecutor implements Executor { } @Override - public void run() { + public void run(Process process) { PluginWebBridge.getHelper().updateFileFromDisk(new File(filePath)); } } diff --git a/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java index a5f49ea6e..4621dc3db 100644 --- a/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java @@ -1,23 +1,106 @@ package com.fr.design.extra.exe; +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.RestartHelper; +import com.fr.design.extra.After; +import com.fr.design.extra.PluginHelper; +import com.fr.design.extra.Process; +import com.fr.general.Inter; +import com.fr.plugin.Plugin; +import com.fr.plugin.PluginLoader; + +import javax.swing.*; +import java.io.File; + /** * Created by richie on 16/3/19. */ public class UpdateOnlineExecutor implements Executor { - private String pluginID; - - public UpdateOnlineExecutor(String pluginID) { - this.pluginID = pluginID; + private String[] pluginIDs; + private static final int PERCENT_100 = 100; + public UpdateOnlineExecutor(String[] pluginIDs) { + this.pluginIDs = pluginIDs; } + @Override public String getTaskFinishMessage() { - return "插件已更新完毕:" + pluginID; + return "task succeed"; } @Override public Command[] getCommands() { - return new Command[0]; + return new Command[]{ + new Command() { + @Override + public String getExecuteMessage() { + return null; + } + + @Override + public void run(Process process) { + for (int i = 0; i < pluginIDs.length; i++) { + Plugin plugin = PluginLoader.getLoader().getPluginById(pluginIDs[i]); + 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) { + } + }); + updateFileFromDisk(PluginHelper.getDownloadTempFile()); + process.process(PERCENT_100 / pluginIDs.length * (i + 1) + "%"); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + int rv = JOptionPane.showOptionDialog( + null, + 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(); + } + } + } + }; + } + + private void updateFileFromDisk(File fileOnDisk){ + try { + Plugin plugin = PluginHelper.readPlugin(fileOnDisk); + if (plugin == null) { + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + return; + } + Plugin oldPlugin = PluginLoader.getLoader().getPluginById(plugin.getId()); + if (oldPlugin != null) { + String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin); + PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() { + @Override + public void done() { + } + }); + } else { + JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } + } catch (Exception e1) { + JOptionPane.showMessageDialog(null, e1.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + } } } From 805dc0695945a451ae27ec36403cd42601431751 Mon Sep 17 00:00:00 2001 From: vito Date: Mon, 18 Apr 2016 02:06:22 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=95=86=E5=BA=97?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/server/PluginManagerAction.java | 4 +- .../src/com/fr/design/dialog/BasicDialog.java | 1 - .../src/com/fr/design/dialog/BasicPane.java | 24 ---------- .../com/fr/design/extra/PluginWebBridge.java | 18 +++++++- .../src/com/fr/design/extra/ShopDialog.java | 26 +++++++++++ .../fr/design/extra/exe/searchExecutor.java | 46 +++++++++++++++++++ 6 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 designer_base/src/com/fr/design/extra/ShopDialog.java create mode 100644 designer_base/src/com/fr/design/extra/exe/searchExecutor.java diff --git a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java index 4225f0c4f..b6e3e25c0 100644 --- a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java +++ b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java @@ -6,6 +6,7 @@ import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.PluginManagerPane; import com.fr.design.extra.PluginWebBridge; +import com.fr.design.extra.ShopDialog; import com.fr.design.mainframe.DesignerContext; import com.fr.design.menu.MenuKeySet; import com.fr.general.Inter; @@ -30,8 +31,7 @@ public class PluginManagerAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { final PluginManagerPane managerPane = new PluginManagerPane(); - //// TODO: 16/4/11 重新写下这个界面窗口. - BasicDialog dlg = managerPane.showCustomSizeWindow(DesignerContext.getDesignerFrame(), null, BasicDialog.LARGE_SHOP); + UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(),managerPane); PluginWebBridge.getHelper().setDialogHandle(dlg); dlg.setVisible(true); } diff --git a/designer_base/src/com/fr/design/dialog/BasicDialog.java b/designer_base/src/com/fr/design/dialog/BasicDialog.java index a1f2785cf..703b19205 100644 --- a/designer_base/src/com/fr/design/dialog/BasicDialog.java +++ b/designer_base/src/com/fr/design/dialog/BasicDialog.java @@ -10,7 +10,6 @@ public abstract class BasicDialog extends UIDialog { public static final Dimension MEDIUM = new Dimension(600, 400); public static final Dimension DEFAULT = new Dimension(660, 600); public static final Dimension LARGE = new Dimension(900, 600); - public static final Dimension LARGE_SHOP = new Dimension(900, 760); public static final Dimension CHART = new Dimension(760, 560); public static final Dimension MAP_SIZE = new Dimension(760, 450); public static final Dimension UPDATE_ONLINE_SIZE = new Dimension(600,300); diff --git a/designer_base/src/com/fr/design/dialog/BasicPane.java b/designer_base/src/com/fr/design/dialog/BasicPane.java index 09190f20f..9bc96f643 100644 --- a/designer_base/src/com/fr/design/dialog/BasicPane.java +++ b/designer_base/src/com/fr/design/dialog/BasicPane.java @@ -171,30 +171,6 @@ public abstract class BasicPane extends JPanel { return dg; } - /** - * 显示自定义大小的窗口 - * - * @param window 窗口 - * @param l 对话框监听器 - * @param dimension 窗口大小 - * @return 对话框 - */ - public BasicDialog showCustomSizeWindow(Window window, DialogActionListener l, Dimension dimension) { - BasicDialog dg; - if (window instanceof Frame) { - dg = new DIALOG((Frame) window); - } else { - dg = new DIALOG((Dialog) window); - } - if (l != null) { - dg.addDialogActionListener(l); - } - dg.setBasicDialogSize(dimension); - GUICoreUtils.centerWindow(dg); - dg.setResizable(false); - return dg; - } - /** * 显示窗口 * diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index ce6dd8fba..378e90459 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -31,6 +31,8 @@ public class PluginWebBridge { private UIDialog uiDialog; + public static final String PLUGIN_SHOP = "http://127.0.0.1:8080/ShopServer?pg=plist"; + public static PluginWebBridge getHelper() { if (helper != null) { return helper; @@ -196,7 +198,7 @@ public class PluginWebBridge { public String getPluginFromStore(String category, String seller, String fee) { - StringBuilder url = new StringBuilder("http://127.0.0.1:8080/ShopServer?pg=plist"); + StringBuilder url = new StringBuilder(PLUGIN_SHOP); if (StringUtils.isNotBlank(category)) { url.append("&cid=").append(category.split("-")[1]); } @@ -217,6 +219,20 @@ public class PluginWebBridge { return resText == null ? StringUtils.EMPTY : resText; } + /** + * 搜索在线插件 + * + * @param keyword 关键字 + */ + public String searchPlugin(String keyword) { + try { + HttpClient httpClient = new HttpClient(PluginWebBridge.PLUGIN_SHOP + "&keyword=" + keyword); + return httpClient.getResponseText(); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + return StringUtils.EMPTY; + } public void showRestartMessage(String message){ int rv = JOptionPane.showOptionDialog( diff --git a/designer_base/src/com/fr/design/extra/ShopDialog.java b/designer_base/src/com/fr/design/extra/ShopDialog.java new file mode 100644 index 000000000..e394c0c1f --- /dev/null +++ b/designer_base/src/com/fr/design/extra/ShopDialog.java @@ -0,0 +1,26 @@ +package com.fr.design.extra; + +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.gui.GUICoreUtils; + +import java.awt.*; + +/** + * Created by vito on 16/4/18. + */ +public class ShopDialog extends UIDialog{ + private static final Dimension DEFAULT_SHOP = new Dimension(900, 760); + + public ShopDialog(Frame frame, BasicPane pane) { + super(frame, pane,false); + setSize(DEFAULT_SHOP); + GUICoreUtils.centerWindow(this); + setResizable(false); + } + + @Override + public void checkValid() throws Exception { + + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/searchExecutor.java b/designer_base/src/com/fr/design/extra/exe/searchExecutor.java new file mode 100644 index 000000000..afa4971d5 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/searchExecutor.java @@ -0,0 +1,46 @@ +package com.fr.design.extra.exe; + +import com.fr.design.extra.PluginWebBridge; +import com.fr.design.extra.Process; +import com.fr.general.FRLogger; +import com.fr.general.http.HttpClient; +import com.fr.stable.StringUtils; + +/** + * Created by vito on 16/4/18. + */ +public class SearchExecutor implements Executor { + private String result; + private String keyword; + + public SearchExecutor(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(PluginWebBridge.PLUGIN_SHOP + "&keyword=" + keyword); + result = httpClient.getResponseText(); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } + } + }; + } +} From 31cc16f4c89417c0ccc4dfaf40916bc712317854 Mon Sep 17 00:00:00 2001 From: vito Date: Mon, 18 Apr 2016 19:47:57 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=99=A8=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=95=86=E5=BA=97=E6=9B=B4=E6=96=B0=E5=92=8C=E6=90=9C?= =?UTF-8?q?=E7=B4=A2API=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/bbs/BBSDialog.java | 55 +++------ .../actions/server/PluginManagerAction.java | 5 +- .../fr/design/extra/PluginManagerPane.java | 13 --- ...{ShopDialog.java => PluginShopDialog.java} | 9 +- .../extra/PluginStatusCheckCompletePane.java | 4 +- .../src/com/fr/design/extra/PluginTask.java | 18 ++- .../com/fr/design/extra/PluginUpdatePane.java | 22 ++-- .../com/fr/design/extra/PluginWebBridge.java | 104 +++++++++++------- .../com/fr/design/extra/PluginWebPane.java | 27 ++++- .../extra/exe/GetPluginFromStoreExecutor.java | 61 ++++++++++ .../extra/exe/ModifyStatusExecutor.java | 1 + .../extra/exe/UpdateOnlineExecutor.java | 10 +- 12 files changed, 208 insertions(+), 121 deletions(-) rename designer_base/src/com/fr/design/extra/{ShopDialog.java => PluginShopDialog.java} (74%) create mode 100644 designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java index 856e9264a..bedbc8d3c 100644 --- a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java +++ b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe.bbs; import com.fr.design.dialog.UIDialog; +import com.fr.design.extra.PluginWebBridge; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; @@ -19,8 +20,6 @@ import netscape.javascript.JSObject; import javax.swing.*; import java.awt.*; -import java.io.IOException; -import java.net.URI; /** * @author richie @@ -53,7 +52,7 @@ public class BBSDialog extends UIDialog { } private void disableLink(final WebEngine eng) { - try{ + try { // webView端不跳转 虽然webView可以指定本地浏览器打开某个链接,但是当本地浏览器跳转到指定链接的同时,webView也做了跳转, // 为了避免出现在一个600*400的资讯框里加载整个网页的情况,webView不跳转到新网页 Platform.runLater(new Runnable() { @@ -62,16 +61,17 @@ public class BBSDialog extends UIDialog { eng.executeScript("history.go(0)"); } }); - }catch(Exception e){ + } catch (Exception e) { FRLogger.getLogger().error(e.getMessage()); } } /** * 打开资讯框 + * * @param url 资讯链接 */ - public void showWindow(final String url){ + public void showWindow(final String url) { GUICoreUtils.centerWindow(this); this.setResizable(false); Platform.runLater(new Runnable() { @@ -92,20 +92,19 @@ public class BBSDialog extends UIDialog { root.getChildren().add(view); eng.locationProperty().addListener(new ChangeListener() { @Override - public void changed(ObservableValue observable, final String oldValue, String newValue) - { - disableLink(eng); - // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 - if(ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, BBSConstants.BBS_MOBILE_MOD)){ - return; - } - openUrlAtLocalWebBrowser(eng,newValue); - } - }); + public void changed(ObservableValue observable, final String oldValue, String newValue) { + disableLink(eng); + // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 + if (ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, BBSConstants.BBS_MOBILE_MOD)) { + return; + } + PluginWebBridge.getHelper().openUrlAtLocalWebBrowser(eng, newValue); + } + }); eng.getLoadWorker().stateProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Worker.State oldValue, Worker.State newValue) { - if (newValue == Worker.State.SUCCEEDED){ + if (newValue == Worker.State.SUCCEEDED) { JSObject obj = (JSObject) eng.executeScript("window"); obj.setMember("BBSWebBridge", BBSDialog.this); setVisible(true); @@ -116,29 +115,6 @@ public class BBSDialog extends UIDialog { }); } - // 在本地浏览器里打开url - private void openUrlAtLocalWebBrowser(WebEngine eng,String url){ - if(Desktop.isDesktopSupported()){ - try{ - //创建一个URI实例,注意不是URL - URI uri = URI.create(url); - //获取当前系统桌面扩展 - Desktop desktop = Desktop.getDesktop(); - //判断系统桌面是否支持要执行的功能 - if(desktop.isSupported(Desktop.Action.BROWSE)){ - //获取系统默认浏览器打开链接 - desktop.browse(uri); - } - }catch(NullPointerException e){ - //此为uri为空时抛出异常 - FRLogger.getLogger().error(e.getMessage()); - }catch(IOException e){ - //此为无法获取系统默认浏览器 - FRLogger.getLogger().error(e.getMessage()); - } - } - } - /** * 提供给web页面调用的关闭窗口 */ @@ -146,6 +122,7 @@ public class BBSDialog extends UIDialog { this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setVisible(false); } + /** * 略 */ diff --git a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java index b6e3e25c0..d88fdf992 100644 --- a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java +++ b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java @@ -2,11 +2,10 @@ package com.fr.design.actions.server; import com.fr.base.BaseUtils; import com.fr.design.actions.UpdateAction; -import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.PluginManagerPane; import com.fr.design.extra.PluginWebBridge; -import com.fr.design.extra.ShopDialog; +import com.fr.design.extra.PluginShopDialog; import com.fr.design.mainframe.DesignerContext; import com.fr.design.menu.MenuKeySet; import com.fr.general.Inter; @@ -31,7 +30,7 @@ public class PluginManagerAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { final PluginManagerPane managerPane = new PluginManagerPane(); - UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(),managerPane); + UIDialog dlg = new PluginShopDialog(DesignerContext.getDesignerFrame(),managerPane); PluginWebBridge.getHelper().setDialogHandle(dlg); dlg.setVisible(true); } diff --git a/designer_base/src/com/fr/design/extra/PluginManagerPane.java b/designer_base/src/com/fr/design/extra/PluginManagerPane.java index d2e267ed0..f1209a6ea 100644 --- a/designer_base/src/com/fr/design/extra/PluginManagerPane.java +++ b/designer_base/src/com/fr/design/extra/PluginManagerPane.java @@ -2,23 +2,10 @@ package com.fr.design.extra; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.frpane.UITabbedPane; -import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.stable.StableUtils; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.concurrent.Worker; -import javafx.scene.web.WebEngine; -import javax.script.Bindings; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.swing.*; import java.awt.*; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; import java.net.URL; /** diff --git a/designer_base/src/com/fr/design/extra/ShopDialog.java b/designer_base/src/com/fr/design/extra/PluginShopDialog.java similarity index 74% rename from designer_base/src/com/fr/design/extra/ShopDialog.java rename to designer_base/src/com/fr/design/extra/PluginShopDialog.java index e394c0c1f..5d04401b2 100644 --- a/designer_base/src/com/fr/design/extra/ShopDialog.java +++ b/designer_base/src/com/fr/design/extra/PluginShopDialog.java @@ -9,11 +9,11 @@ import java.awt.*; /** * Created by vito on 16/4/18. */ -public class ShopDialog extends UIDialog{ - private static final Dimension DEFAULT_SHOP = new Dimension(900, 760); +public class PluginShopDialog extends UIDialog { + private static final Dimension DEFAULT_SHOP = new Dimension(900, 710); - public ShopDialog(Frame frame, BasicPane pane) { - super(frame, pane,false); + public PluginShopDialog(Frame frame, BasicPane pane) { + super(frame, pane, false); setSize(DEFAULT_SHOP); GUICoreUtils.centerWindow(this); setResizable(false); @@ -21,6 +21,5 @@ public class ShopDialog extends UIDialog{ @Override public void checkValid() throws Exception { - } } diff --git a/designer_base/src/com/fr/design/extra/PluginStatusCheckCompletePane.java b/designer_base/src/com/fr/design/extra/PluginStatusCheckCompletePane.java index cf772d5d6..46f55d40b 100644 --- a/designer_base/src/com/fr/design/extra/PluginStatusCheckCompletePane.java +++ b/designer_base/src/com/fr/design/extra/PluginStatusCheckCompletePane.java @@ -67,8 +67,8 @@ public abstract class PluginStatusCheckCompletePane extends PluginAbstractViewPa public void setProgress(double percent) { progressBar.setVisible(true); - progressBar.setValue((int)percent); - progressBar.setString((int)percent + "%"); + progressBar.setValue((int) percent); + progressBar.setString((int) percent + "%"); progressBar.repaint(); } diff --git a/designer_base/src/com/fr/design/extra/PluginTask.java b/designer_base/src/com/fr/design/extra/PluginTask.java index a86e088b3..5efcdd1d4 100644 --- a/designer_base/src/com/fr/design/extra/PluginTask.java +++ b/designer_base/src/com/fr/design/extra/PluginTask.java @@ -27,7 +27,7 @@ public class PluginTask extends Task { messageProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, String oldValue, String newValue) { - String fun = "(" + callback + ")('" + newValue + "')"; + String fun = "(" + callback + ")(\"" + newValue + "\")"; try { webEngine.executeScript(fun); } catch (Exception e) { @@ -49,7 +49,7 @@ public class PluginTask extends Task { @Override public void process(String s) { if (StringUtils.isNotBlank(s)) { - updateMessage(s); + updateMessage(changText(s)); } } }); @@ -59,6 +59,18 @@ public class PluginTask extends Task { @Override protected void done() { - updateMessage(executor.getTaskFinishMessage()); + updateMessage(changText(executor.getTaskFinishMessage())); + } + + /** + * 转换掉一些会造成错误的特殊字符 + * 1 ""中的""必须转义 + * 2 js字符串中的\n会导致js字符串变成多行,而js字符创不支持多行拼接 + * + * @param old 原始字符串 + * @return 处理之后的字符串 + */ + private String changText(String old) { + return old.replaceAll("\"", "\\\\\"").replaceAll("\n", ""); } } diff --git a/designer_base/src/com/fr/design/extra/PluginUpdatePane.java b/designer_base/src/com/fr/design/extra/PluginUpdatePane.java index 33d976372..e0b3ada35 100644 --- a/designer_base/src/com/fr/design/extra/PluginUpdatePane.java +++ b/designer_base/src/com/fr/design/extra/PluginUpdatePane.java @@ -25,7 +25,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane(){ + if (StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())) { + new SwingWorker() { @Override protected Void doInBackground() throws Exception { @@ -181,7 +183,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane() { + PluginHelper.downloadPluginFile(id, username, password, new Process() { @Override public void process(Double integer) { publish(integer); @@ -264,12 +266,14 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane alert = new Dialog<>(); -// alert.getDialogPane().setContentText(message); -// alert.getDialogPane().getButtonTypes().add(ButtonType.OK); -// alert.showAndWait(); } } diff --git a/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java b/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java new file mode 100644 index 000000000..030b22f21 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java @@ -0,0 +1,61 @@ +package com.fr.design.extra.exe; + +import com.fr.design.extra.PluginWebBridge; +import com.fr.design.extra.Process; +import com.fr.general.FRLogger; +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) { + StringBuilder url = new StringBuilder(PluginWebBridge.PLUGIN_SHOP); + 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()); + } + } + } + }; + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java index c3fb43262..c544858dd 100644 --- a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java @@ -34,6 +34,7 @@ public class ModifyStatusExecutor implements Executor { public String getExecuteMessage() { return StringUtils.EMPTY; } + @Override public void run(Process process) { plugin = PluginLoader.getLoader().getPluginById(pluginID); diff --git a/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java index 4621dc3db..f1c3b0f04 100644 --- a/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java @@ -81,7 +81,7 @@ public class UpdateOnlineExecutor implements Executor { }; } - private void updateFileFromDisk(File fileOnDisk){ + private void updateFileFromDisk(File fileOnDisk) { try { Plugin plugin = PluginHelper.readPlugin(fileOnDisk); if (plugin == null) { @@ -92,10 +92,10 @@ public class UpdateOnlineExecutor implements Executor { if (oldPlugin != null) { String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin); PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() { - @Override - public void done() { - } - }); + @Override + public void done() { + } + }); } else { JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); } From 3921be849ba08b3d4753a63857f896aebdd39094 Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 19 Apr 2016 09:30:33 +0800 Subject: [PATCH 08/11] =?UTF-8?q?jdk1.8=E6=89=93=E5=BC=80=E6=96=B0?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer_base/src/com/fr/design/extra/PluginManagerPane.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/designer_base/src/com/fr/design/extra/PluginManagerPane.java b/designer_base/src/com/fr/design/extra/PluginManagerPane.java index f1209a6ea..bd4e50ec4 100644 --- a/designer_base/src/com/fr/design/extra/PluginManagerPane.java +++ b/designer_base/src/com/fr/design/extra/PluginManagerPane.java @@ -24,7 +24,8 @@ public class PluginManagerPane extends BasicPane { public PluginManagerPane() { setLayout(new BorderLayout()); - if (StableUtils.isDebug()) { + if (System.getProperty("java.version").startsWith("1.8")) { + System.out.println(System.getProperty("java.version")); URL url = ClassLoader.getSystemResource(""); String installHome = url.getPath(); PluginWebPane webPane = new PluginWebPane(installHome); From ad4bc04cde88540e8d1f578b7ea6839c077af6ce Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 19 Apr 2016 09:30:59 +0800 Subject: [PATCH 09/11] =?UTF-8?q?dubug=E5=8E=BB=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer_base/src/com/fr/design/extra/PluginManagerPane.java | 1 - 1 file changed, 1 deletion(-) diff --git a/designer_base/src/com/fr/design/extra/PluginManagerPane.java b/designer_base/src/com/fr/design/extra/PluginManagerPane.java index bd4e50ec4..ef008717d 100644 --- a/designer_base/src/com/fr/design/extra/PluginManagerPane.java +++ b/designer_base/src/com/fr/design/extra/PluginManagerPane.java @@ -25,7 +25,6 @@ public class PluginManagerPane extends BasicPane { public PluginManagerPane() { setLayout(new BorderLayout()); if (System.getProperty("java.version").startsWith("1.8")) { - System.out.println(System.getProperty("java.version")); URL url = ClassLoader.getSystemResource(""); String installHome = url.getPath(); PluginWebPane webPane = new PluginWebPane(installHome); From ada306b10b5e51c87fd2d6392ce4aae8fd1095bd Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 19 Apr 2016 09:46:36 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E6=BC=8F=E6=8E=89=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ebfc6188b..ec8c85a73 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ designer/bin designer_base/bin designer_chart/bin designer_form/bin +*.iml From 2a0c239ad137dea2977b7dde3d0b5ca60edea64c Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 19 Apr 2016 09:49:45 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer_base/src/com/fr/design/extra/PluginManagerPane.java | 1 - designer_base/src/com/fr/design/extra/PluginWebBridge.java | 2 +- .../exe/{searchExecutor.java => SearchOnlineExecutor.java} | 5 +++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename designer_base/src/com/fr/design/extra/exe/{searchExecutor.java => SearchOnlineExecutor.java} (91%) diff --git a/designer_base/src/com/fr/design/extra/PluginManagerPane.java b/designer_base/src/com/fr/design/extra/PluginManagerPane.java index ef008717d..3a63c685b 100644 --- a/designer_base/src/com/fr/design/extra/PluginManagerPane.java +++ b/designer_base/src/com/fr/design/extra/PluginManagerPane.java @@ -3,7 +3,6 @@ package com.fr.design.extra; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.frpane.UITabbedPane; import com.fr.general.Inter; -import com.fr.stable.StableUtils; import java.awt.*; import java.net.URL; diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 908690966..65ef0c56d 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -205,7 +205,7 @@ public class PluginWebBridge { * @param keyword 关键字 */ public void searchPlugin(String keyword, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new SearchExecutor(keyword)); + Task task = new PluginTask<>(webEngine, callback, new SearchOnlineExecutor(keyword)); new Thread(task).start(); } diff --git a/designer_base/src/com/fr/design/extra/exe/searchExecutor.java b/designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java similarity index 91% rename from designer_base/src/com/fr/design/extra/exe/searchExecutor.java rename to designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java index afa4971d5..a94fcc5f2 100644 --- a/designer_base/src/com/fr/design/extra/exe/searchExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java @@ -9,11 +9,11 @@ import com.fr.stable.StringUtils; /** * Created by vito on 16/4/18. */ -public class SearchExecutor implements Executor { +public class SearchOnlineExecutor implements Executor { private String result; private String keyword; - public SearchExecutor(String keyword) { + public SearchOnlineExecutor(String keyword) { this.keyword = keyword; } @@ -36,6 +36,7 @@ public class SearchExecutor implements Executor { try { HttpClient httpClient = new HttpClient(PluginWebBridge.PLUGIN_SHOP + "&keyword=" + keyword); result = httpClient.getResponseText(); + } catch (Exception e) { FRLogger.getLogger().error(e.getMessage()); }