|
|
|
@ -1,10 +1,8 @@
|
|
|
|
|
package com.fr.van.chart.designer.component.richText; |
|
|
|
|
|
|
|
|
|
import com.fr.concurrent.NamedThreadFactory; |
|
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
|
import com.fr.design.ui.ModernUIPane; |
|
|
|
|
import com.fr.general.IOUtils; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fr.plugin.chart.base.AttrTooltipRichText; |
|
|
|
|
import com.fr.plugin.chart.type.TextAlign; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
@ -15,38 +13,20 @@ import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent;
|
|
|
|
|
|
|
|
|
|
import java.util.Locale; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
|
|
|
|
public class VanChartRichEditorPane { |
|
|
|
|
|
|
|
|
|
private static final String namespace = "Pool"; |
|
|
|
|
private static final String variable = "data"; |
|
|
|
|
private static final String richEditorPath = "/com/fr/design/editor/rich_editor.html"; |
|
|
|
|
private static final String expression = "dispatch()"; |
|
|
|
|
private static final String NAME_SPACE = "Pool"; |
|
|
|
|
private static final String VARIABLE = "data"; |
|
|
|
|
|
|
|
|
|
private static final String RICH_EDITOR_HTML = "/com/fr/design/editor/rich_editor.html"; |
|
|
|
|
|
|
|
|
|
private static final String REFRESH = "refresh()"; |
|
|
|
|
private static final String ADD_FIELD = "addField()"; |
|
|
|
|
|
|
|
|
|
private static ModernUIPane<VanChartRichEditorModel> richEditorPane; |
|
|
|
|
private static Browser browser; |
|
|
|
|
|
|
|
|
|
public static void initRichEditorPane() { |
|
|
|
|
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("VanChartRichEditor")); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
singleThreadExecutor.submit(new Runnable() { |
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
try { |
|
|
|
|
richEditorPane = initPane(new VanChartRichEditorModel()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} finally { |
|
|
|
|
singleThreadExecutor.shutdown(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ModernUIPane<VanChartRichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) { |
|
|
|
|
VanChartRichEditorModel model = getRichEditorModel(richEditor); |
|
|
|
|
return createRichEditorPane(model); |
|
|
|
@ -55,13 +35,25 @@ public class VanChartRichEditorPane {
|
|
|
|
|
public static ModernUIPane<VanChartRichEditorModel> createRichEditorPane(VanChartRichEditorModel model) { |
|
|
|
|
if (richEditorPane == null) { |
|
|
|
|
richEditorPane = initPane(model); |
|
|
|
|
} else if (browser != null) { |
|
|
|
|
updatePane(browser, model); |
|
|
|
|
} else { |
|
|
|
|
richEditorRefresh(model); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return richEditorPane; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void richEditorRefresh(VanChartRichEditorModel model) { |
|
|
|
|
if (richEditorPane != null && browser != null) { |
|
|
|
|
refresh(browser, model); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void richEditorAddField(VanChartRichEditorModel model) { |
|
|
|
|
if (richEditorPane != null && browser != null) { |
|
|
|
|
addField(browser, model); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ModernUIPane<VanChartRichEditorModel> initPane(VanChartRichEditorModel model) { |
|
|
|
|
return new ModernUIPane.Builder<VanChartRichEditorModel>() |
|
|
|
|
.prepare(new ScriptContextAdapter() { |
|
|
|
@ -74,18 +66,26 @@ public class VanChartRichEditorPane {
|
|
|
|
|
browser.executeJavaScript(generateTransformI18nJS()); |
|
|
|
|
browser.executeJavaScript(IOUtils.readResourceAsString("/com/fr/web/ui/materials.min.js")); |
|
|
|
|
|
|
|
|
|
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace); |
|
|
|
|
ns.asObject().setProperty(variable, model); |
|
|
|
|
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + NAME_SPACE); |
|
|
|
|
ns.asObject().setProperty(VARIABLE, model); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.withEMB(richEditorPath) |
|
|
|
|
.namespace(namespace).build(); |
|
|
|
|
.withEMB(RICH_EDITOR_HTML) |
|
|
|
|
.namespace(NAME_SPACE).build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void refresh(Browser browser, VanChartRichEditorModel model) { |
|
|
|
|
stateChange(browser, model, REFRESH); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void addField(Browser browser, VanChartRichEditorModel model) { |
|
|
|
|
stateChange(browser, model, ADD_FIELD); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void updatePane(Browser browser, VanChartRichEditorModel model) { |
|
|
|
|
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace); |
|
|
|
|
ns.asObject().setProperty(variable, model); |
|
|
|
|
browser.executeJavaScript("window." + namespace + "." + expression); |
|
|
|
|
public static void stateChange(Browser browser, VanChartRichEditorModel model, String trigger) { |
|
|
|
|
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + NAME_SPACE); |
|
|
|
|
ns.asObject().setProperty(VARIABLE, model); |
|
|
|
|
browser.executeJavaScript("window." + NAME_SPACE + "." + trigger); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static VanChartRichEditorModel getRichEditorModel(AttrTooltipRichText richText) { |
|
|
|
|