Browse Source

Pull request #7916: REPORT-66306 & REPORT-66465

Merge in DESIGN/design from ~STARRYI/design:release/11.0 to release/11.0

* commit '7040a69a398b4f14d2b2abaa9871c74649c78d61':
  REPORT-66465 【组件商城风格优化】设计器商城,概率打开空白
  REPORT-66306 组件包下载面板无遮罩阴影
bugfix/11.0
starryi 3 years ago
parent
commit
b9cb6838a0
  1. 40
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineDownloadPackagePane.java
  2. 23
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/MiniComponentShopPane.java
  3. 19
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/ComposedNativeBridges.java
  4. 3
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/NativeAuthBridge.java
  5. 13
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/NativeBrowserBridge.java
  6. 86
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/NativeProductBridge.java
  7. 21
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/NativeTaskBridge.java
  8. 29
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/SafeJSFunctionInvoker.java

40
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineDownloadPackagePane.java

@ -72,22 +72,6 @@ public class OnlineDownloadPackagePane extends OnlineWidgetSelectPane {
return false;
}
protected JPanel createWidgetPane() {
return new JPanel() {
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.65f);
g2d.setComposite(composite);
g2d.setColor(Color.DARK_GRAY);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setComposite(oldComposite);
}
};
}
protected JPanel createContentPane(JPanel widgetPane) {
JPanel panel = new JPanel() {
@Override
@ -114,7 +98,20 @@ public class OnlineDownloadPackagePane extends OnlineWidgetSelectPane {
parentPane.resetWidgetDetailPane(packageId, getSharableWidgetProviders());
}
}
});
}) {
@Override
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.65f);
g2d.setComposite(composite);
g2d.setColor(Color.DARK_GRAY);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setComposite(oldComposite);
super.paint(g);
}
};
panel.add(downloadProgressPane);
panel.add(widgetPane, BorderLayout.CENTER);
return panel;
@ -125,10 +122,16 @@ public class OnlineDownloadPackagePane extends OnlineWidgetSelectPane {
final com.fr.design.extra.Process<Double> downloadProcess = aDouble -> {
OnlineDownloadPackagePane.this.process = 0.8 * aDouble;
downloadProgressPane.updateProgress(process);
if (downloadProgressPane != null) {
downloadProgressPane.repaint();
}
};
final com.fr.design.extra.Process<Double> installProcess = aDouble -> {
OnlineDownloadPackagePane.this.process = 0.8 + 0.2 * aDouble;
downloadProgressPane.updateProgress(process);
if (downloadProgressPane != null) {
downloadProgressPane.repaint();
}
};
downloadProcess.process(0.0D);
@ -220,6 +223,9 @@ public class OnlineDownloadPackagePane extends OnlineWidgetSelectPane {
File file = new File(filePath);
installProcess.process(0.0D);
downloadProgressPane.changeState();
if (downloadProgressPane != null) {
downloadProgressPane.repaint();
}
InstallUtils.InstallResult result = null;
try {
if (file.exists()) {

23
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/MiniComponentShopPane.java

@ -3,15 +3,18 @@ package com.fr.design.mainframe.share.ui.online.mini;
import com.fr.design.mainframe.share.ui.online.mini.bridge.ComposedNativeBridges;
import com.fr.design.mainframe.share.util.OnlineShopUtils;
import com.fr.design.ui.ModernUIPane;
import com.fr.design.ui.compatible.ModernUIPaneFactory;
import com.fr.design.upm.event.CertificateEvent;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.teamdev.jxbrowser.browser.callback.InjectJsCallback;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter;
import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent;
import com.teamdev.jxbrowser.js.JsObject;
import org.jetbrains.annotations.Nullable;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.BorderLayout;
@ -27,14 +30,26 @@ public class MiniComponentShopPane extends JPanel {
public MiniComponentShopPane() {
setLayout(new BorderLayout());
modernUIPane = new ModernUIPane.Builder<>()
modernUIPane = ModernUIPaneFactory.modernUIPaneBuilder()
.withURL(OnlineShopUtils.getWebMiniShopPath())
.prepare(new ScriptContextAdapter() {
.prepareForV6(new ScriptContextAdapter() {
@Override
public void onScriptContextCreated(ScriptContextEvent event) {
super.onScriptContextCreated(event);
JSObject window = event.getBrowser().executeJavaScriptAndReturnValue("window").asObject();
window.asObject().setProperty("ShopHelper", new ComposedNativeBridges(window, JOptionPane.getFrameForComponent(MiniComponentShopPane.this)));
window.setProperty("ShopHelper", new ComposedNativeBridges(window));
}
})
.prepareForV7(new InjectJsCallback() {
@Nullable
@Override
public Response on(Params params) {
// 7.x
JsObject window = params.frame().executeJavaScript("window");
if (window != null) {
window.putProperty("ShopHelper", new ComposedNativeBridges(window));
}
return InjectJsCallback.Response.proceed();
}
})
.build();

19
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/ComposedNativeBridges.java

@ -1,9 +1,7 @@
package com.fr.design.mainframe.share.ui.online.mini.bridge;
import com.teamdev.jxbrowser.chromium.JSAccessible;
import com.teamdev.jxbrowser.chromium.JSObject;
import java.awt.Window;
import com.teamdev.jxbrowser.js.JsAccessible;
/**
* @author Starryi
@ -12,14 +10,19 @@ import java.awt.Window;
*/
public class ComposedNativeBridges {
@JSAccessible
public final NativeBrowserBridge Browser;
@JsAccessible
public final Object Browser;
@JSAccessible
public final NativeAuthBridge Auth;
@JsAccessible
public final Object Auth;
@JSAccessible
public final NativeProductBridge Product;
@JsAccessible
public final Object Product;
public ComposedNativeBridges(JSObject window, Window nativeWindow) {
this.Browser = new NativeBrowserBridge(nativeWindow);
public ComposedNativeBridges(Object window) {
this.Browser = new NativeBrowserBridge();
this.Auth = new NativeAuthBridge();
this.Product = new NativeProductBridge(window);
}

3
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/NativeAuthBridge.java

@ -6,6 +6,7 @@ import com.fr.design.login.DesignerLoginHelper;
import com.fr.design.login.DesignerLoginSource;
import com.fr.design.mainframe.share.ui.online.mini.MiniComponentShopDialog;
import com.teamdev.jxbrowser.chromium.JSAccessible;
import com.teamdev.jxbrowser.js.JsAccessible;
import java.awt.Window;
import java.util.HashMap;
@ -17,12 +18,14 @@ import java.util.HashMap;
*/
public class NativeAuthBridge {
@JSAccessible
@JsAccessible
@JSBridge
public String getLoginUsername() {
return DesignerEnvManager.getEnvManager().getDesignerLoginUsername();
}
@JSAccessible
@JsAccessible
@JSBridge
public void goLogin() {
Window parentWindow = MiniComponentShopDialog.getInstance().getWindow();

13
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/NativeBrowserBridge.java

@ -1,7 +1,9 @@
package com.fr.design.mainframe.share.ui.online.mini.bridge;
import com.fr.design.bridge.exec.JSBridge;
import com.fr.design.mainframe.share.ui.online.mini.MiniComponentShopDialog;
import com.teamdev.jxbrowser.chromium.JSAccessible;
import com.teamdev.jxbrowser.js.JsAccessible;
import java.awt.Window;
@ -11,15 +13,14 @@ import java.awt.Window;
* Created by Starryi on 2021/12/20
*/
public class NativeBrowserBridge {
private final Window nativeWindow;
public NativeBrowserBridge(Window nativeWindow) {
this.nativeWindow = nativeWindow;
}
@JSAccessible
@JsAccessible
@JSBridge
public void dispose() {
this.nativeWindow.dispose();
Window nativeWindow = MiniComponentShopDialog.getInstance().getWindow();
if (nativeWindow != null) {
nativeWindow.dispose();
}
}
}

86
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/NativeProductBridge.java

@ -21,8 +21,7 @@ import com.fr.form.share.group.DefaultShareGroupManager;
import com.fr.json.JSONObject;
import com.fr.stable.StringUtils;
import com.teamdev.jxbrowser.chromium.JSAccessible;
import com.teamdev.jxbrowser.chromium.JSFunction;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.js.JsAccessible;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
@ -38,20 +37,21 @@ import java.util.Set;
* Created by Starryi on 2021/12/20
*/
public class NativeProductBridge {
private final JSObject window;
private final Object window;
private static final Map<String, ComponentInstallationTask> executingComponentInstallationTasks = new HashMap<>();
private static final Map<String, ComponentsPackageInstallationTask> executingComponentsPackageInstallationTasks = new HashMap<>();
private static final Map<String, TemplateThemeInstallationTask> executingTemplateThemeInstallationTasks = new HashMap<>();
private final Map<String, Set<JSFunction>> componentDownloadTaskStartListeners = new HashMap<>();
private final Map<String, Set<JSFunction>> componentsPackageDownloadTaskStartListeners = new HashMap<>();
private final Map<String, Set<JSFunction>> themeDownloadTaskStartListeners = new HashMap<>();
private final Map<String, Set<Object>> componentDownloadTaskStartListeners = new HashMap<>();
private final Map<String, Set<Object>> componentsPackageDownloadTaskStartListeners = new HashMap<>();
private final Map<String, Set<Object>> themeDownloadTaskStartListeners = new HashMap<>();
public NativeProductBridge(JSObject window) {
public NativeProductBridge(Object window) {
this.window = window;
}
@JSAccessible
@JsAccessible
@JSBridge
public boolean isProductDownloaded(String uuid) {
for (Group group : DefaultShareGroupManager.getInstance().getAllGroup()) {
@ -66,16 +66,17 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
public void addProductDownloadTaskStartListener(String json, JSFunction function) {
public void addProductDownloadTaskStartListener(String json, Object function) {
JSONObject object = new JSONObject(json);
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(object);
String uuid = widget.getUuid();
boolean isPackage = widget.isWidgetPackage();
Map<String, Set<JSFunction>> downloadTaskGetters =
Map<String, Set<Object>> downloadTaskGetters =
isPackage ? componentsPackageDownloadTaskStartListeners : componentDownloadTaskStartListeners;
Set<JSFunction> startListeners = downloadTaskGetters.get(widget.getUuid());
Set<Object> startListeners = downloadTaskGetters.get(widget.getUuid());
if (startListeners == null) {
startListeners = new HashSet<>();
}
@ -86,16 +87,17 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
public void removeProductDownloadTaskStartListener(String json, JSFunction function) {
public void removeProductDownloadTaskStartListener(String json, Object function) {
JSONObject object = new JSONObject(json);
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(object);
String uuid = widget.getUuid();
boolean isPackage = widget.isWidgetPackage();
Map<String, Set<JSFunction>> downloadTaskGetters = isPackage ? componentsPackageDownloadTaskStartListeners : componentDownloadTaskStartListeners;
Map<String, Set<Object>> downloadTaskGetters = isPackage ? componentsPackageDownloadTaskStartListeners : componentDownloadTaskStartListeners;
Set<JSFunction> startListeners = downloadTaskGetters.get(uuid);
Set<Object> startListeners = downloadTaskGetters.get(uuid);
if (startListeners == null) {
startListeners = new HashSet<>();
}
@ -104,6 +106,7 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
public Object getExecutingProductDownloadTask(String json) {
JSONObject object = new JSONObject(json);
@ -121,22 +124,24 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
public Object createProductDownloadTask(String json) {
JSONObject object = new JSONObject(json);
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(object);
int childrenCount = object.optInt("pkgsize", 0);
if (childrenCount > 0) {
return new ComponentsPackageInstallationTask(window, widget, childrenCount);
return new ComponentsPackageInstallationTask(this, window, widget, childrenCount);
} else {
return new ComponentInstallationTask(window, widget);
return new ComponentInstallationTask(this, window, widget);
}
}
@JSAccessible
@JsAccessible
@JSBridge
public void addThemeDownloadTaskStartListener(String themePath, JSFunction function) {
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath);
public void addThemeDownloadTaskStartListener(String themePath, Object function) {
Set<Object> startListeners = themeDownloadTaskStartListeners.get(themePath);
if (startListeners == null) {
startListeners = new HashSet<>();
}
@ -145,9 +150,10 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
public void removeThemeDownloadTaskStartListener(String themePath, JSFunction function) {
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath);
public void removeThemeDownloadTaskStartListener(String themePath, Object function) {
Set<Object> startListeners = themeDownloadTaskStartListeners.get(themePath);
if (startListeners == null) {
startListeners = new HashSet<>();
}
@ -156,9 +162,10 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
public Object getExecutingThemeDownloadTask(String themePath) {
NativeTaskBridge task = executingTemplateThemeInstallationTasks.get(themePath);
NativeTaskBridge task = (NativeTaskBridge) executingTemplateThemeInstallationTasks.get(themePath);
if (task != null) {
task.checkJSEnvChange(this.window);
}
@ -166,17 +173,20 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
public Object createTemplateThemeDownloadTask(String themePath) {
return new TemplateThemeInstallationTask(window, themePath);
return new TemplateThemeInstallationTask(this, window, themePath);
}
public class ComponentInstallationTask extends NativeTaskBridge {
public static class ComponentInstallationTask extends NativeTaskBridge {
private final NativeProductBridge env;
private final OnlineShareWidget widget;
private final ComponentInstallation action;
public ComponentInstallationTask(JSObject window, OnlineShareWidget widget) {
public ComponentInstallationTask(NativeProductBridge env, Object window, OnlineShareWidget widget) {
super(window);
this.env = env;
this.widget = widget;
action = new ComponentInstallation(widget);
action.setActionListener(new AsyncInstallation.AsyncActionListener() {
@ -203,6 +213,7 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
@Override
public void execute() {
@ -231,6 +242,7 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
@Override
public void cancel() {
@ -246,8 +258,8 @@ public class NativeProductBridge {
@Override
protected void fireStartEvent(String event) {
executingComponentInstallationTasks.put(widget.getUuid(), this);
Set<JSFunction> startListeners = componentDownloadTaskStartListeners.get(widget.getUuid());
SafeJSFunctionInvoker.invoke(startListeners, window);
Set<Object> startListeners = env.componentDownloadTaskStartListeners.get(widget.getUuid());
SafeJSFunctionInvoker.invoke(startListeners, env.window);
super.fireStartEvent(event);
}
@ -264,14 +276,16 @@ public class NativeProductBridge {
}
}
public class ComponentsPackageInstallationTask extends NativeTaskBridge {
public static class ComponentsPackageInstallationTask extends NativeTaskBridge {
private final NativeProductBridge env;
private final ComponentsPackageInstallation action;
private final OnlineShareWidget widget;
private final int childrenCount;
public ComponentsPackageInstallationTask(JSObject window, OnlineShareWidget widget, int childrenCount) {
public ComponentsPackageInstallationTask(NativeProductBridge env, Object window, OnlineShareWidget widget, int childrenCount) {
super(window);
this.env = env;
this.widget = widget;
this.childrenCount = childrenCount;
action = new ComponentsPackageInstallation(widget, childrenCount);
@ -299,6 +313,7 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
@Override
public void execute() {
@ -343,6 +358,7 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
@Override
public void cancel() {
@ -360,8 +376,8 @@ public class NativeProductBridge {
executingComponentsPackageInstallationTasks.put(widget.getUuid(), this);
super.fireStartEvent(event);
Set<JSFunction> startListeners = componentsPackageDownloadTaskStartListeners.get(widget.getUuid());
SafeJSFunctionInvoker.invoke(startListeners, window);
Set<Object> startListeners = env.componentsPackageDownloadTaskStartListeners.get(widget.getUuid());
SafeJSFunctionInvoker.invoke(startListeners, env.window);
}
@Override
@ -377,11 +393,13 @@ public class NativeProductBridge {
}
}
public class TemplateThemeInstallationTask extends NativeTaskBridge {
public static class TemplateThemeInstallationTask extends NativeTaskBridge {
private final NativeProductBridge env;
private final String themePath;
private final TemplateThemeInstallation action;
public TemplateThemeInstallationTask(JSObject window, String themePath) {
public TemplateThemeInstallationTask(NativeProductBridge env, Object window, String themePath) {
super(window);
this.env = env;
this.themePath = themePath;
Window miniShopWindow = MiniComponentShopDialog.getInstance().getWindow();
action = new TemplateThemeInstallation(miniShopWindow, themePath);
@ -404,6 +422,7 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
@Override
public void execute() {
@ -418,6 +437,7 @@ public class NativeProductBridge {
}
@JSAccessible
@JsAccessible
@JSBridge
@Override
public void cancel() {
@ -433,8 +453,8 @@ public class NativeProductBridge {
@Override
protected void fireStartEvent(String event) {
executingTemplateThemeInstallationTasks.put(themePath, this);
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath);
SafeJSFunctionInvoker.invoke(startListeners, window);
Set<Object> startListeners = env.themeDownloadTaskStartListeners.get(themePath);
SafeJSFunctionInvoker.invoke(startListeners, env.window);
super.fireStartEvent(event);
}

21
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/NativeTaskBridge.java

@ -4,12 +4,9 @@ import com.fr.design.bridge.exec.JSBridge;
import com.fr.design.mainframe.share.mini.MiniShopNativeTask;
import com.fr.design.mainframe.share.mini.MiniShopNativeTaskManager;
import com.teamdev.jxbrowser.chromium.JSAccessible;
import com.teamdev.jxbrowser.chromium.JSFunction;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.js.JsAccessible;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
@ -19,14 +16,14 @@ import java.util.Set;
*/
public class NativeTaskBridge implements MiniShopNativeTask {
private JSObject window;
protected final Set<JSFunction> statusCbs = new HashSet<>();
private Object window;
protected final Set<Object> statusCbs = new HashSet<>();
public NativeTaskBridge(JSObject window) {
public NativeTaskBridge(Object window) {
this.window = window;
}
public void checkJSEnvChange(JSObject window) {
public void checkJSEnvChange(Object window) {
if (this.window != window) {
this.window = window;
this.statusCbs.clear();
@ -35,24 +32,28 @@ public class NativeTaskBridge implements MiniShopNativeTask {
@JSBridge
@JSAccessible
public void addStatusCallback(JSFunction cb) {
@JsAccessible
public void addStatusCallback(Object cb) {
this.statusCbs.add(cb);
}
@JSBridge
@JSAccessible
public void removeStatusCallback(JSFunction cb) {
@JsAccessible
public void removeStatusCallback(Object cb) {
this.statusCbs.remove(cb);
}
@JSBridge
@JSAccessible
@JsAccessible
@Override
public void execute() {
}
@JSBridge
@JSAccessible
@JsAccessible
@Override
public void cancel() {
MiniShopNativeTaskManager.getInstance().removeCompletedTask(this);

29
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/mini/bridge/SafeJSFunctionInvoker.java

@ -2,6 +2,8 @@ package com.fr.design.mainframe.share.ui.online.mini.bridge;
import com.teamdev.jxbrowser.chromium.JSFunction;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.js.JsFunction;
import com.teamdev.jxbrowser.js.JsObject;
import java.util.Collection;
@ -12,18 +14,31 @@ import java.util.Collection;
*/
public class SafeJSFunctionInvoker {
public static void invoke(Collection<JSFunction> functions, JSObject instance, Object... args) {
public static void invoke(Collection<Object> functions, Object instance, Object... args) {
if (functions != null) {
for (JSFunction function: functions) {
if (function != null && !function.getContext().isDisposed()) {
function.invoke(instance, args);
}
for (Object function: functions) {
invoke(function, instance, args);
}
}
}
public static void invoke(JSFunction function, JSObject instance, Object... args) {
if (function != null && !function.getContext().isDisposed()) {
public static void invoke(Object function, Object instance, Object... args) {
if (function != null) {
if (function instanceof JSFunction && instance instanceof JSObject) {
invokeV6((JSFunction) function, (JSObject) instance, args);
} else if (function instanceof JsFunction && instance instanceof JsObject) {
invokeV7((JsFunction) function, (JsObject) instance, args);
}
}
}
private static void invokeV6(JSFunction function, JSObject instance, Object... args) {
if (!function.getContext().isDisposed()) {
function.invoke(instance, args);
}
}
private static void invokeV7(JsFunction function, JsObject instance, Object... args) {
function.invoke(instance, args);
}
}

Loading…
Cancel
Save