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