Browse Source

Merge pull request #816 in DESIGN/design from ~RICHIE/design:release/10.0 to release/10.0

* commit '57116cff094005f8928439b215a303e2f092026b':
  KERNEL-442 配合测试新版本插件商店
bugfix/10.0
richie 6 years ago
parent
commit
7831baef0c
  1. 6
      designer-base/src/main/java/com/fr/design/actions/server/PluginManagerAction.java
  2. 8
      designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java
  3. 63
      designer-base/src/main/java/com/fr/design/upm/UPM.java
  4. 31
      designer-base/src/main/java/com/fr/design/upm/UPMBridge.java
  5. 34
      designer-base/src/main/java/com/fr/design/upm/UPMDialog.java
  6. 36
      designer-base/src/main/java/com/fr/design/upm/UPMPane.java
  7. 33
      designer-base/src/main/java/com/fr/design/upm/WarnComponent.java
  8. 13
      designer-base/src/main/java/com/fr/design/upm/event/DownloadEvent.java
  9. 20
      designer-base/src/main/resources/com/fr/design/upm/warn.js

6
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();
}

8
designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java

@ -98,6 +98,14 @@ public class ModernUIPane<T> extends BasicPane {
});
}
/**
* 转向一个新的地址相当于重新加载
* @param url 新的地址
*/
public void redirect(String url) {
browser.loadURL(url);
}
@Override
protected String title4PopupWindow() {
return "Modern";

63
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<Workspace>() {
@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;
}
}
}

31
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();
}
}

34
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 {
}
}

36
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<Object> modernUIPane;
@Override
protected String title4PopupWindow() {
return "UPM";
@ -19,9 +30,28 @@ public class UPMPane extends BasicPane {
public UPMPane() {
setLayout(new BorderLayout());
ModernUIPane<Void> modernUIPane = new ModernUIPane.Builder<Void>()
.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<String>() {
@Override
public void on(Event event, String param) {
modernUIPane.redirect(UPM.getMainResourcePath());
}
});
}
add(modernUIPane, BorderLayout.CENTER);
}
}

33
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
};
}
}

13
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<String> {
FINISH
}

20
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
}]
});
};
Loading…
Cancel
Save