diff --git a/designer-base/src/main/java/com/fr/design/actions/server/PluginManagerAction.java b/designer-base/src/main/java/com/fr/design/actions/server/PluginManagerAction.java index 840cab45e8..aa2eef705b 100644 --- a/designer-base/src/main/java/com/fr/design/actions/server/PluginManagerAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/server/PluginManagerAction.java @@ -9,6 +9,8 @@ import com.fr.design.extra.ShopDialog; import com.fr.design.extra.WebViewDlgHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.menu.MenuKeySet; +import com.fr.design.upm.UPM; +import com.fr.design.upm.UPMDialog; import com.fr.design.upm.UPMPane; import com.fr.general.IOUtils; @@ -35,9 +37,7 @@ public class PluginManagerAction extends UpdateAction { // 可以启用新版本的插件商店(使用JxBrowser作为容器) if (DesignerEnvManager.getEnvManager().isOpenDebug() ||ServerPreferenceConfig.getInstance().isUseOptimizedUPM()) { - UPMPane upmPane = new UPMPane(); - UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), upmPane); - dlg.setVisible(true); + UPM.showUPMDialog(); } else { WebViewDlgHelper.createPluginDialog(); } diff --git a/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java b/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java index 0198ebfe7c..5f6c8c9552 100644 --- a/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java +++ b/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java @@ -98,6 +98,14 @@ public class ModernUIPane extends BasicPane { }); } + /** + * 转向一个新的地址,相当于重新加载 + * @param url 新的地址 + */ + public void redirect(String url) { + browser.loadURL(url); + } + @Override protected String title4PopupWindow() { return "Modern"; diff --git a/designer-base/src/main/java/com/fr/design/upm/UPM.java b/designer-base/src/main/java/com/fr/design/upm/UPM.java new file mode 100644 index 0000000000..b8b95fab63 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/upm/UPM.java @@ -0,0 +1,63 @@ +package com.fr.design.upm; + +import com.fr.base.FRContext; +import com.fr.design.dialog.UIDialog; +import com.fr.design.mainframe.DesignerContext; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.stable.StableUtils; +import com.fr.workspace.Workspace; +import com.fr.workspace.WorkspaceEvent; + +import javax.swing.*; +import java.io.File; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-04-12 + */ +public class UPM { + + private static final String MAIN_RESOURCE_PATH = "/upm/plugin.html"; + + public static String installHome = FRContext.getCommonOperator().getWebRootPath(); + + private static UIDialog dialog = null; + + static { + EventDispatcher.listen(WorkspaceEvent.AfterSwitch, new Listener() { + @Override + public void on(Event event, Workspace param) { + installHome = FRContext.getCommonOperator().getWebRootPath(); + } + }); + } + + public static boolean checkUPMResourcesExist() { + String mainJsPath = StableUtils.pathJoin(installHome, MAIN_RESOURCE_PATH); + File file = new File(mainJsPath); + return file.exists(); + } + + public static String getMainResourcePath() { + return "file:///" + StableUtils.pathJoin(installHome, MAIN_RESOURCE_PATH); + } + + public static void showUPMDialog() { + UPMPane upmPane = new UPMPane(); + if (dialog == null) { + dialog = new UPMDialog(DesignerContext.getDesignerFrame(), upmPane); + } + dialog.setVisible(true); + } + + public static void closeWindow() { + if (dialog != null) { + dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + dialog.setVisible(false); + dialog = null; + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/upm/UPMBridge.java b/designer-base/src/main/java/com/fr/design/upm/UPMBridge.java new file mode 100644 index 0000000000..4fa98ed32b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/upm/UPMBridge.java @@ -0,0 +1,31 @@ +package com.fr.design.upm; + +import com.fr.design.upm.event.DownloadEvent; +import com.fr.event.EventDispatcher; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-04-12 + * 桥接Java和JavaScript的类 + */ +public class UPMBridge { + + private static UPMBridge bridge = new UPMBridge(); + + public static UPMBridge getBridge() { + return bridge; + } + + public void startDownload() { + // do something..... + EventDispatcher.fire(DownloadEvent.FINISH, "start"); + } + + + + public void closeWindow() { + UPM.closeWindow(); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/upm/UPMDialog.java b/designer-base/src/main/java/com/fr/design/upm/UPMDialog.java new file mode 100644 index 0000000000..d5a2f4b79d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/upm/UPMDialog.java @@ -0,0 +1,34 @@ +package com.fr.design.upm; + +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.stable.StableUtils; + +import javax.swing.*; +import java.awt.*; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-04-12 + */ +public class UPMDialog extends UIDialog { + + private static final Dimension DEFAULT_SHOP = new Dimension(900, 700); + + public UPMDialog(Frame frame, BasicPane pane) { + super(frame); + setUndecorated(true); + JPanel panel = (JPanel) getContentPane(); + panel.setLayout(new BorderLayout()); + add(pane, BorderLayout.CENTER); + setSize(DEFAULT_SHOP); + GUICoreUtils.centerWindow(this); + setResizable(false); + } + + @Override + public void checkValid() throws Exception { + } +} diff --git a/designer-base/src/main/java/com/fr/design/upm/UPMPane.java b/designer-base/src/main/java/com/fr/design/upm/UPMPane.java index e9d7032256..6480d8ad7c 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UPMPane.java +++ b/designer-base/src/main/java/com/fr/design/upm/UPMPane.java @@ -1,7 +1,15 @@ package com.fr.design.upm; +import com.fr.base.FRContext; import com.fr.design.dialog.BasicPane; import com.fr.design.ui.ModernUIPane; +import com.fr.design.upm.event.DownloadEvent; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.teamdev.jxbrowser.chromium.JSValue; +import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter; +import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent; import java.awt.*; @@ -12,6 +20,9 @@ import java.awt.*; * Update Plugin Manager容器 */ public class UPMPane extends BasicPane { + + private ModernUIPane modernUIPane; + @Override protected String title4PopupWindow() { return "UPM"; @@ -19,9 +30,28 @@ public class UPMPane extends BasicPane { public UPMPane() { setLayout(new BorderLayout()); - ModernUIPane modernUIPane = new ModernUIPane.Builder() - .withURL("https://market.fanruan.com") - .build(); + if (false) { + modernUIPane = new ModernUIPane.Builder<>() + .withURL(UPM.getMainResourcePath()) + .build(); + } else { + modernUIPane = new ModernUIPane.Builder<>() + .withComponent(WarnComponent.KEY) + .prepare(new ScriptContextAdapter() { + @Override + public void onScriptContextCreated(ScriptContextEvent event) { + JSValue window = event.getBrowser().executeJavaScriptAndReturnValue("window"); + window.asObject().setProperty("PluginBridgeTest", UPMBridge.getBridge()); + } + }).build(); + EventDispatcher.listen(DownloadEvent.FINISH, new Listener() { + @Override + public void on(Event event, String param) { + modernUIPane.redirect(UPM.getMainResourcePath()); + } + }); + } add(modernUIPane, BorderLayout.CENTER); } + } diff --git a/designer-base/src/main/java/com/fr/design/upm/WarnComponent.java b/designer-base/src/main/java/com/fr/design/upm/WarnComponent.java new file mode 100644 index 0000000000..3ab134acf1 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/upm/WarnComponent.java @@ -0,0 +1,33 @@ +package com.fr.design.upm; + +import com.fr.web.struct.AssembleComponent; +import com.fr.web.struct.Atom; +import com.fr.web.struct.browser.RequestClient; +import com.fr.web.struct.category.ScriptPath; +import com.fr.web.struct.impl.FineUI; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-04-12 + */ +public class WarnComponent extends AssembleComponent { + + public static final WarnComponent KEY = new WarnComponent(); + + private WarnComponent() { + + } + + @Override + public ScriptPath script(RequestClient req) { + return ScriptPath.build("com/fr/design/upm/warn.js"); + } + + @Override + public Atom[] refer() { + return new Atom[]{ + FineUI.KEY + }; + } +} diff --git a/designer-base/src/main/java/com/fr/design/upm/event/DownloadEvent.java b/designer-base/src/main/java/com/fr/design/upm/event/DownloadEvent.java new file mode 100644 index 0000000000..7ac53dd17d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/upm/event/DownloadEvent.java @@ -0,0 +1,13 @@ +package com.fr.design.upm.event; + +import com.fr.event.Event; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-04-12 + */ +public enum DownloadEvent implements Event { + + FINISH +} diff --git a/designer-base/src/main/resources/com/fr/design/upm/warn.js b/designer-base/src/main/resources/com/fr/design/upm/warn.js new file mode 100644 index 0000000000..f09b9b9adb --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/upm/warn.js @@ -0,0 +1,20 @@ +window.onload = function () { + let button = BI.createWidget({ + type : "bi.button", + text : "点击我跳转到插件商店", + level: 'common', + height: 30, + handler : function () { + PluginBridgeTest.startDownload(); + } + }); + BI.createWidget({ + type:"bi.absolute", + element: "body", + items: [{ + el: button, + left: 100, + top: 100 + }] + }); +}; \ No newline at end of file