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