From e16c65f0398f5c04e930632d06c2d485e5e21734 Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 19 Apr 2019 13:43:44 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-442=20=E4=B8=8D=E8=83=BD=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=A4=A7=E5=B0=8F=E5=86=99=EF=BC=8C=E8=A2=AB=E8=BF=AB?= =?UTF-8?q?=E6=94=B9=E4=B8=AA=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/upm/UPMBridge.java | 390 ------------------ .../java/com/fr/design/upm/UpmFinder.java | 13 +- .../upm/{UpmBridge.java => UpmJSBridge.java} | 9 +- .../upm/{UpmPane.java => UpmModernPane.java} | 8 +- 4 files changed, 9 insertions(+), 411 deletions(-) delete mode 100644 designer-base/src/main/java/com/fr/design/upm/UPMBridge.java rename designer-base/src/main/java/com/fr/design/upm/{UpmBridge.java => UpmJSBridge.java} (98%) rename designer-base/src/main/java/com/fr/design/upm/{UpmPane.java => UpmModernPane.java} (92%) 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 deleted file mode 100644 index 8984e41913..0000000000 --- a/designer-base/src/main/java/com/fr/design/upm/UPMBridge.java +++ /dev/null @@ -1,390 +0,0 @@ -package com.fr.design.upm; - -import com.fr.base.passport.FinePassportManager; -import com.fr.config.MarketConfig; -import com.fr.decision.webservice.v10.plugin.helper.category.impl.UpmResourceLoader; -import com.fr.design.bridge.exec.JSBridge; -import com.fr.design.bridge.exec.JSCallback; -import com.fr.design.extra.PluginOperateUtils; -import com.fr.design.extra.PluginUtils; -import com.fr.design.extra.exe.GetInstalledPluginsExecutor; -import com.fr.design.extra.exe.GetPluginCategoriesExecutor; -import com.fr.design.extra.exe.GetPluginFromStoreExecutor; -import com.fr.design.extra.exe.PluginLoginExecutor; -import com.fr.design.extra.exe.ReadUpdateOnlineExecutor; -import com.fr.design.extra.exe.SearchOnlineExecutor; -import com.fr.design.i18n.Toolkit; -import com.fr.design.upm.event.CertificateEvent; -import com.fr.design.upm.event.DownloadEvent; -import com.fr.design.upm.exec.UpmBrowserExecutor; -import com.fr.design.upm.task.UpmTaskWorker; -import com.fr.event.EventDispatcher; -import com.fr.general.CloudCenter; -import com.fr.general.GeneralUtils; -import com.fr.json.JSONObject; -import com.fr.log.FineLoggerFactory; -import com.fr.plugin.context.PluginMarker; -import com.fr.stable.ArrayUtils; -import com.fr.stable.StringUtils; -import com.teamdev.jxbrowser.chromium.Browser; -import com.teamdev.jxbrowser.chromium.JSArray; -import com.teamdev.jxbrowser.chromium.JSFunction; -import com.teamdev.jxbrowser.chromium.JSObject; - -import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import java.awt.*; -import java.io.File; -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.FutureTask; -import java.util.concurrent.RunnableFuture; - -/** - * @author richie - * @version 10.0 - * Created by richie on 2019-04-12 - * 桥接Java和JavaScript的类 - */ -public class UpmBridge { - - public static UpmBridge getBridge(Browser browser) { - return new UpmBridge(browser); - } - - private JSObject window; - - private UpmBridge(Browser browser) { - this.window = browser.executeJavaScriptAndReturnValue("window").asObject(); - } - - public void startDownload() { - try { - UpmResourceLoader.INSTANCE.download(); - UpmResourceLoader.INSTANCE.install(); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - EventDispatcher.fire(DownloadEvent.FINISH, "start"); - } - - @JSBridge - public String i18nText(String key) { - return Toolkit.i18nText(key); - } - - @JSBridge - public void closeWindow() { - UpmFinder.closeWindow(); - } - - - @JSBridge - public boolean isDesigner() { - return true; - } - - @JSBridge - public void getPackInfo(final JSFunction callback) { - callback.invoke(window, StringUtils.EMPTY); - } - - /** - * 在线获取插件分类 - * - * @param callback 回调函数 - */ - @JSBridge - public void getPluginCategories(final JSFunction callback) { - UpmTaskWorker task = new UpmTaskWorker<>(new JSCallback(UpmBrowserExecutor.create(window, callback)), new GetPluginCategoriesExecutor()); - task.execute(); - } - - /** - * 根据条件获取在线插件 - * - * @param info 插件信息 - * @param callback 回调函数 - */ - @JSBridge - public void getPluginFromStoreNew(String info, final JSFunction callback) { - UpmTaskWorker task = new UpmTaskWorker<>(new JSCallback(UpmBrowserExecutor.create(window, callback)), new GetPluginFromStoreExecutor(new JSONObject(info))); - task.execute(); - } - - /** - * 已安装插件检查更新 - */ - @JSBridge - public void readUpdateOnline(final JSFunction callback) { - UpmTaskWorker task = new UpmTaskWorker<>(new JSCallback(UpmBrowserExecutor.create(window, callback)), new ReadUpdateOnlineExecutor()); - task.execute(); - } - - /** - * 获取已经安装的插件的数组 - */ - @JSBridge - public void getInstalledPlugins(final JSFunction callback) { - UpmTaskWorker task = new UpmTaskWorker<>(new JSCallback(UpmBrowserExecutor.create(window, callback)), new GetInstalledPluginsExecutor()); - task.execute(); - } - - /** - * 从插件服务器上更新选中的插件 - * - * @param pluginIDs 插件集合 - */ - @JSBridge - public void updatePluginOnline(Object pluginIDs, final JSFunction callback) { - JSCallback jsCallback = new JSCallback(UpmBrowserExecutor.create(window, callback)); - List pluginMarkerList = new ArrayList<>(); - if (pluginIDs instanceof String) { - pluginMarkerList.add(PluginUtils.createPluginMarker(pluginIDs.toString())); - } else if (pluginIDs instanceof JSArray) { - JSArray pluginInfos = (JSArray) pluginIDs; - for (int i = 0, len = pluginInfos.length(); i < len; i++) { - String value = pluginInfos.get(i).asString().getValue(); - pluginMarkerList.add(PluginUtils.createPluginMarker(value)); - } - } - PluginOperateUtils.updatePluginOnline(pluginMarkerList, jsCallback); - } - - /** - * 搜索在线插件 - * - * @param keyword 关键字 - */ - @JSBridge - public void searchPlugin(String keyword, final JSFunction callback) { - UpmTaskWorker worker = new UpmTaskWorker<>(new JSCallback(UpmBrowserExecutor.create(window, callback)), new SearchOnlineExecutor(keyword)); - worker.execute(); - } - - /** - * 从磁盘上选择插件安装包进行安装 - * - * @param filePath 插件包的路径 - */ - @JSBridge - public void installPluginFromDisk(final String filePath, final JSFunction callback) { - JSCallback jsCallback = new JSCallback(UpmBrowserExecutor.create(window, callback)); - File file = new File(filePath); - PluginOperateUtils.installPluginFromDisk(file, jsCallback); - } - - /** - * 卸载当前选中的插件 - * - * @param pluginInfo 插件信息 - */ - @JSBridge - public void uninstallPlugin(final String pluginInfo, final boolean isForce, final JSFunction callback) { - JSCallback jsCallback = new JSCallback(UpmBrowserExecutor.create(window, callback)); - PluginOperateUtils.uninstallPlugin(pluginInfo, isForce, jsCallback); - } - - /** - * 从插件服务器上安装插件 - * - * @param pluginInfo 插件的ID - * @param callback 回调函数 - */ - @JSBridge - public void installPluginOnline(final String pluginInfo, final JSFunction callback) { - JSCallback jsCallback = new JSCallback(UpmBrowserExecutor.create(window, callback)); - PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo); - PluginOperateUtils.installPluginOnline(pluginMarker, jsCallback); - } - - /** - * 从磁盘上选择插件安装包进行插件升级 - * - * @param filePath 插件包的路径 - */ - public void updatePluginFromDisk(String filePath, final JSFunction callback) { - JSCallback jsCallback = new JSCallback(UpmBrowserExecutor.create(window, callback)); - File file = new File(filePath); - PluginOperateUtils.updatePluginFromDisk(file, jsCallback); - } - - /** - * 修改选中的插件的活跃状态 - * - * @param pluginID 插件ID - */ - @JSBridge - public void setPluginActive(String pluginID, final JSFunction callback) { - JSCallback jsCallback = new JSCallback(UpmBrowserExecutor.create(window, callback)); - PluginOperateUtils.setPluginActive(pluginID, jsCallback); - } - - /** - * 选择文件对话框 - * - * @return 选择的文件的路径 - */ - @JSBridge - public String showFileChooser() { - return showFileChooserWithFilter(StringUtils.EMPTY, StringUtils.EMPTY); - } - - /** - * 选择文件对话框 - * - * @param des 过滤文件描述 - * @param filter 文件的后缀 - * @return 选择的文件的路径 - * 这里换用JFileChooser会卡死,不知道为什么 - */ - @JSBridge - public String showFileChooserWithFilter(final String des, final String filter) { - RunnableFuture future = new FutureTask<>(new Callable() { - @Override - public String call() { - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - - if (StringUtils.isNotEmpty(filter)) { - fileChooser.setFileFilter(new FileNameExtensionFilter(des, UpmUtils.findMatchedExtension(filter))); - } - - int result = fileChooser.showOpenDialog(UpmFinder.getDialog()); - if (result == JFileChooser.APPROVE_OPTION) { - return fileChooser.getSelectedFile().getAbsolutePath(); - } - return null; - } - }); - SwingUtilities.invokeLater(future); - try { - return future.get(); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return null; - } - - /** - * 选择文件对话框 - * - * @param des 过滤文件描述 - * @param args 文件的后缀 - * @return 选择的文件的路径 - */ - @JSBridge - public String showFileChooserWithFilters(final String des, final Object args) { - RunnableFuture future = new FutureTask<>(new Callable() { - @Override - public String call() { - JFileChooser fileChooser = new JFileChooser(); - List filterList = new ArrayList<>(); - if (args instanceof String) { - filterList.add(GeneralUtils.objectToString(args)); - } else if (args instanceof JSArray) { - JSArray array = (JSArray)args; - for (int i = 0, len = array.length(); i < len; i ++) { - filterList.add(array.get(i).getStringValue()); - } - } - String[] filters = filterList.toArray(new String[0]); - if (ArrayUtils.isNotEmpty(filters)) { - FileNameExtensionFilter filter = new FileNameExtensionFilter(des, UpmUtils.findMatchedExtension(filters)); - fileChooser.setFileFilter(filter); - } - int result = fileChooser.showOpenDialog(UpmFinder.getDialog()); - if (result == JFileChooser.APPROVE_OPTION) { - return fileChooser.getSelectedFile().getAbsolutePath(); - } - return null; - } - }); - SwingUtilities.invokeLater(future); - try { - return future.get(); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return null; - } - - ////////登录相关/////// - - /** - * 获取系统登录的用户名 - */ - @JSBridge - public String getLoginInfo(final JSFunction callback) { - registerLoginInfo(callback); - return MarketConfig.getInstance().getBbsUsername(); - } - - /** - * 系统登录注册 - * - * @param callback 回调函数 - */ - @JSBridge - public void registerLoginInfo(final JSFunction callback) { - JSCallback jsCallback = new JSCallback(UpmBrowserExecutor.create(window, callback)); - String username = MarketConfig.getInstance().getBbsUsername(); - if (StringUtils.isEmpty(username)) { - jsCallback.execute(StringUtils.EMPTY); - EventDispatcher.fire(CertificateEvent.LOGOUT, StringUtils.EMPTY); - } else { - jsCallback.execute(username); - EventDispatcher.fire(CertificateEvent.LOGIN, username); - } - } - - - /** - * 设计器端的用户登录 - * - * @param username 用户名 - * @param password 密码 - * @param callback 回调函数 - */ - @JSBridge - public void defaultLogin(String username, String password, final JSFunction callback) { - UpmTaskWorker worker = new UpmTaskWorker<>(new JSCallback(UpmBrowserExecutor.create(window, callback)), new PluginLoginExecutor(username, password)); - worker.execute(); - } - - /** - * 清除用户信息 - */ - public void clearUserInfo() { - MarketConfig.getInstance().setInShowBBsName(StringUtils.EMPTY); - FinePassportManager.getInstance().logout(); - EventDispatcher.fire(CertificateEvent.LOGOUT, StringUtils.EMPTY); - } - - /** - * 打开论坛消息界面 - */ - @JSBridge - public void getPriviteMessage() { - try { - String loginUrl = CloudCenter.getInstance().acquireUrlByKind("bbs.default"); - Desktop.getDesktop().browse(new URI(loginUrl)); - } catch (Exception exp) { - FineLoggerFactory.getLogger().info(exp.getMessage()); - } - } - - /** - * 忘记密码 - */ - @JSBridge - public void forgetHref() { - try { - Desktop.getDesktop().browse(new URI(CloudCenter.getInstance().acquireUrlByKind("bbs.reset"))); - } catch (Exception e) { - FineLoggerFactory.getLogger().info(e.getMessage()); - } - } -} diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmFinder.java b/designer-base/src/main/java/com/fr/design/upm/UpmFinder.java index 84e0ad5b79..a74923577d 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmFinder.java +++ b/designer-base/src/main/java/com/fr/design/upm/UpmFinder.java @@ -1,28 +1,17 @@ package com.fr.design.upm; import com.fr.base.FRContext; -import com.fr.base.TemplateUtils; 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.general.GeneralContext; -import com.fr.general.IOUtils; -import com.fr.log.FineLoggerFactory; import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; import com.fr.workspace.Workspace; import com.fr.workspace.WorkspaceEvent; import javax.swing.*; import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; /** * @author richie @@ -62,7 +51,7 @@ public class UpmFinder { } public static void showUPMDialog() { - UpmPane upmPane = new UpmPane(); + UpmModernPane upmPane = new UpmModernPane(); if (dialog == null) { dialog = new UpmDialog(DesignerContext.getDesignerFrame(), upmPane); } diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java b/designer-base/src/main/java/com/fr/design/upm/UpmJSBridge.java similarity index 98% rename from designer-base/src/main/java/com/fr/design/upm/UpmBridge.java rename to designer-base/src/main/java/com/fr/design/upm/UpmJSBridge.java index bc2fe0b037..af3fa4858c 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java +++ b/designer-base/src/main/java/com/fr/design/upm/UpmJSBridge.java @@ -18,7 +18,6 @@ import com.fr.design.upm.event.CertificateEvent; import com.fr.design.upm.event.DownloadEvent; import com.fr.design.upm.exec.UpmBrowserExecutor; import com.fr.design.upm.task.UpmTaskWorker; -import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.general.CloudCenter; import com.fr.general.GeneralUtils; @@ -49,15 +48,15 @@ import java.util.concurrent.RunnableFuture; * Created by richie on 2019-04-12 * 桥接Java和JavaScript的类 */ -public class UpmBridge { +public class UpmJSBridge { - public static UpmBridge getBridge(Browser browser) { - return new UpmBridge(browser); + public static UpmJSBridge getBridge(Browser browser) { + return new UpmJSBridge(browser); } private JSObject window; - private UpmBridge(Browser browser) { + private UpmJSBridge(Browser browser) { this.window = browser.executeJavaScriptAndReturnValue("window").asObject(); } diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmPane.java b/designer-base/src/main/java/com/fr/design/upm/UpmModernPane.java similarity index 92% rename from designer-base/src/main/java/com/fr/design/upm/UpmPane.java rename to designer-base/src/main/java/com/fr/design/upm/UpmModernPane.java index 3e4ccc5814..86bee5476e 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmPane.java +++ b/designer-base/src/main/java/com/fr/design/upm/UpmModernPane.java @@ -18,7 +18,7 @@ import java.awt.*; * Created by richie on 2019-04-12 * Update Plugin Manager容器 */ -public class UpmPane extends BasicPane { +public class UpmModernPane extends BasicPane { private ModernUIPane modernUIPane; @@ -27,7 +27,7 @@ public class UpmPane extends BasicPane { return "UPM"; } - public UpmPane() { + public UpmModernPane() { setLayout(new BorderLayout()); if (UpmFinder.checkUPMResourcesExist()) { modernUIPane = new ModernUIPane.Builder<>() @@ -35,7 +35,7 @@ public class UpmPane extends BasicPane { @Override public void onScriptContextCreated(ScriptContextEvent event) { JSValue window = event.getBrowser().executeJavaScriptAndReturnValue("window"); - window.asObject().setProperty("PluginHelper", UpmBridge.getBridge(event.getBrowser())); + window.asObject().setProperty("PluginHelper", UpmJSBridge.getBridge(event.getBrowser())); } }) .withURL(UpmFinder.getMainResourcePath()) @@ -47,7 +47,7 @@ public class UpmPane extends BasicPane { @Override public void onScriptContextCreated(ScriptContextEvent event) { JSValue window = event.getBrowser().executeJavaScriptAndReturnValue("window"); - window.asObject().setProperty("PluginHelper", UpmBridge.getBridge(event.getBrowser())); + window.asObject().setProperty("PluginHelper", UpmJSBridge.getBridge(event.getBrowser())); } }).build(); EventDispatcher.listen(DownloadEvent.SUCCESS, new Listener() {