|
|
|
@ -17,15 +17,18 @@ import com.fr.form.share.Group;
|
|
|
|
|
import com.fr.form.share.SharableWidgetProvider; |
|
|
|
|
import com.fr.form.share.bean.OnlineShareWidget; |
|
|
|
|
import com.fr.form.share.group.DefaultShareGroupManager; |
|
|
|
|
import com.fr.json.JSONArray; |
|
|
|
|
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 javax.swing.JOptionPane; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import java.awt.Window; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -35,6 +38,13 @@ import java.util.Set;
|
|
|
|
|
*/ |
|
|
|
|
public class NativeProductBridge { |
|
|
|
|
private final JSObject 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<>(); |
|
|
|
|
|
|
|
|
|
public NativeProductBridge(JSObject window) { |
|
|
|
|
this.window = window; |
|
|
|
@ -42,30 +52,116 @@ public class NativeProductBridge {
|
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public String getDownloadedProductIds() { |
|
|
|
|
Set<String> uuidList = new HashSet<>(); |
|
|
|
|
public boolean isProductDownloaded(String uuid) { |
|
|
|
|
for (Group group : DefaultShareGroupManager.getInstance().getAllGroup()) { |
|
|
|
|
SharableWidgetProvider[] widgetProviderList = group.getAllBindInfoList(); |
|
|
|
|
for (SharableWidgetProvider widget: widgetProviderList) { |
|
|
|
|
if (StringUtils.isNotEmpty(widget.getId())) { |
|
|
|
|
uuidList.add(widget.getId()); |
|
|
|
|
if (StringUtils.equals(uuid, widget.getId())) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
JSONArray array = JSONArray.create(uuidList); |
|
|
|
|
return array.toString(); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public void addProductDownloadTaskStartListener(String json, JSFunction 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; |
|
|
|
|
Set<JSFunction> startListeners = downloadTaskGetters.get(widget.getUuid()); |
|
|
|
|
if (startListeners == null) { |
|
|
|
|
startListeners = new HashSet<>(); |
|
|
|
|
} |
|
|
|
|
startListeners.add(function); |
|
|
|
|
downloadTaskGetters.put(widget.getUuid(), startListeners); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public void removeProductDownloadTaskStartListener(String json, JSFunction 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; |
|
|
|
|
|
|
|
|
|
Set<JSFunction> startListeners = downloadTaskGetters.get(uuid); |
|
|
|
|
if (startListeners == null) { |
|
|
|
|
startListeners = new HashSet<>(); |
|
|
|
|
} |
|
|
|
|
startListeners.remove(function); |
|
|
|
|
downloadTaskGetters.put(uuid, startListeners); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object getExecutingProductDownloadTask(String json) { |
|
|
|
|
JSONObject object = new JSONObject(json); |
|
|
|
|
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(object); |
|
|
|
|
String uuid = widget.getUuid(); |
|
|
|
|
boolean isPackage = widget.isWidgetPackage(); |
|
|
|
|
|
|
|
|
|
Map<String, ? extends NativeTaskBridge> executingDownloadTask = |
|
|
|
|
isPackage ? executingComponentsPackageInstallationTasks : executingComponentInstallationTasks; |
|
|
|
|
NativeTaskBridge task = executingDownloadTask.get(uuid); |
|
|
|
|
if (task != null) { |
|
|
|
|
task.checkJSEnvChange(this.window); |
|
|
|
|
} |
|
|
|
|
return task; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object createProductDownloadTask(String json) { |
|
|
|
|
return new ComponentInstallationTask(window, 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); |
|
|
|
|
} else { |
|
|
|
|
return new ComponentInstallationTask(window, widget); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public void addThemeDownloadTaskStartListener(String themePath, JSFunction function) { |
|
|
|
|
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
if (startListeners == null) { |
|
|
|
|
startListeners = new HashSet<>(); |
|
|
|
|
} |
|
|
|
|
startListeners.add(function); |
|
|
|
|
themeDownloadTaskStartListeners.put(themePath, startListeners); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object createProductsPackageDownloadTask(String json) { |
|
|
|
|
return new ComponentsPackageInstallationTask(window, json); |
|
|
|
|
public void removeThemeDownloadTaskStartListener(String themePath, JSFunction function) { |
|
|
|
|
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
if (startListeners == null) { |
|
|
|
|
startListeners = new HashSet<>(); |
|
|
|
|
} |
|
|
|
|
startListeners.remove(function); |
|
|
|
|
themeDownloadTaskStartListeners.put(themePath, startListeners); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object getExecutingThemeDownloadTask(String themePath) { |
|
|
|
|
NativeTaskBridge task = executingTemplateThemeInstallationTasks.get(themePath); |
|
|
|
|
if (task != null) { |
|
|
|
|
task.checkJSEnvChange(this.window); |
|
|
|
|
} |
|
|
|
|
return task; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
@ -74,15 +170,13 @@ public class NativeProductBridge {
|
|
|
|
|
return new TemplateThemeInstallationTask(window, themePath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class ComponentInstallationTask extends NativeTaskBridge { |
|
|
|
|
public class ComponentInstallationTask extends NativeTaskBridge { |
|
|
|
|
private final OnlineShareWidget widget; |
|
|
|
|
private final ComponentInstallation action; |
|
|
|
|
|
|
|
|
|
public ComponentInstallationTask(JSObject window, String widgetJson) { |
|
|
|
|
public ComponentInstallationTask(JSObject window, OnlineShareWidget widget) { |
|
|
|
|
super(window); |
|
|
|
|
|
|
|
|
|
JSONObject object = new JSONObject(widgetJson); |
|
|
|
|
widget = OnlineShareWidget.parseFromJSONObject(object); |
|
|
|
|
this.widget = widget; |
|
|
|
|
action = new ComponentInstallation(widget); |
|
|
|
|
action.setActionListener(new AsyncInstallation.AsyncActionListener() { |
|
|
|
|
@Override |
|
|
|
@ -93,8 +187,8 @@ public class NativeProductBridge {
|
|
|
|
|
@Override |
|
|
|
|
public void onSuccess() { |
|
|
|
|
fireSuccessEvent(null); |
|
|
|
|
LocalWidgetRepoPane.getInstance().refreshPane(); |
|
|
|
|
if (!DesignerContext.getDesignerFrame().isActive()) { |
|
|
|
|
LocalWidgetRepoPane.getInstance().refreshPane(); |
|
|
|
|
FormWidgetDetailPane.getInstance().switch2Local(); |
|
|
|
|
EastRegionContainerPane.getInstance().switchTabTo(EastRegionContainerPane.KEY_WIDGET_LIB); |
|
|
|
|
} |
|
|
|
@ -147,19 +241,38 @@ 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); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireFailureEvent(String event) { |
|
|
|
|
executingComponentInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
super.fireFailureEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireSuccessEvent(String event) { |
|
|
|
|
executingComponentInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
super.fireSuccessEvent(event); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class ComponentsPackageInstallationTask extends NativeTaskBridge { |
|
|
|
|
public class ComponentsPackageInstallationTask extends NativeTaskBridge { |
|
|
|
|
|
|
|
|
|
private final ComponentsPackageInstallation action; |
|
|
|
|
private final OnlineShareWidget widget; |
|
|
|
|
private final int childrenCount; |
|
|
|
|
|
|
|
|
|
public ComponentsPackageInstallationTask(JSObject window, String widgetJson) { |
|
|
|
|
public ComponentsPackageInstallationTask(JSObject window, OnlineShareWidget widget, int childrenCount) { |
|
|
|
|
super(window); |
|
|
|
|
JSONObject object = new JSONObject(widgetJson); |
|
|
|
|
widget = OnlineShareWidget.parseFromJSONObject(object); |
|
|
|
|
childrenCount = object.optInt("pkgsize", 0); |
|
|
|
|
this.widget = widget; |
|
|
|
|
this.childrenCount = childrenCount; |
|
|
|
|
action = new ComponentsPackageInstallation(widget, childrenCount); |
|
|
|
|
action.setActionListener(new AsyncInstallation.AsyncActionListener() { |
|
|
|
|
@Override |
|
|
|
@ -170,8 +283,8 @@ public class NativeProductBridge {
|
|
|
|
|
@Override |
|
|
|
|
public void onSuccess() { |
|
|
|
|
fireSuccessEvent(null); |
|
|
|
|
LocalWidgetRepoPane.getInstance().refreshPane(); |
|
|
|
|
if (!DesignerContext.getDesignerFrame().isActive()) { |
|
|
|
|
LocalWidgetRepoPane.getInstance().refreshPane(); |
|
|
|
|
FormWidgetDetailPane.getInstance().switch2Local(); |
|
|
|
|
EastRegionContainerPane.getInstance().switchTabTo(EastRegionContainerPane.KEY_WIDGET_LIB); |
|
|
|
|
} |
|
|
|
@ -232,13 +345,37 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireStartEvent(String event) { |
|
|
|
|
executingComponentsPackageInstallationTasks.put(widget.getUuid(), this); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
|
|
|
|
|
|
Set<JSFunction> startListeners = componentsPackageDownloadTaskStartListeners.get(widget.getUuid()); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, window); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireFailureEvent(String event) { |
|
|
|
|
executingComponentsPackageInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
super.fireFailureEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireSuccessEvent(String event) { |
|
|
|
|
executingComponentsPackageInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
super.fireSuccessEvent(event); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class TemplateThemeInstallationTask extends NativeTaskBridge { |
|
|
|
|
public class TemplateThemeInstallationTask extends NativeTaskBridge { |
|
|
|
|
private final String themePath; |
|
|
|
|
private final TemplateThemeInstallation action; |
|
|
|
|
public TemplateThemeInstallationTask(JSObject window, String themePath) { |
|
|
|
|
super(window); |
|
|
|
|
action = new TemplateThemeInstallation(themePath); |
|
|
|
|
this.themePath = themePath; |
|
|
|
|
Window miniShopWindow = MiniComponentShopDialog.getInstance().getWindow(); |
|
|
|
|
action = new TemplateThemeInstallation(miniShopWindow, themePath); |
|
|
|
|
action.setActionListener(new AsyncInstallation.AsyncActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onProgress(double value) { |
|
|
|
@ -283,5 +420,25 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireStartEvent(String event) { |
|
|
|
|
executingTemplateThemeInstallationTasks.put(themePath, this); |
|
|
|
|
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, window); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireFailureEvent(String event) { |
|
|
|
|
executingTemplateThemeInstallationTasks.remove(themePath); |
|
|
|
|
super.fireFailureEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireSuccessEvent(String event) { |
|
|
|
|
executingTemplateThemeInstallationTasks.remove(themePath); |
|
|
|
|
super.fireSuccessEvent(event); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|