diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/datacenter/DCTableDataPane.java b/designer-base/src/main/java/com/fr/design/data/tabledata/datacenter/DCTableDataPane.java index 766e57ec20..c5950ae57d 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/datacenter/DCTableDataPane.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/datacenter/DCTableDataPane.java @@ -6,8 +6,6 @@ import com.fr.datacenters.tabledata.bean.DCNameBean; import com.fr.datacenters.tabledata.bean.DCTableDataBean; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; -import com.fr.design.dialog.DialogActionListener; -import com.fr.design.dialog.UIDialog; import com.fr.design.i18n.Toolkit; import com.fr.design.jxbrowser.JxEngine; import com.fr.design.jxbrowser.JxUIPane; @@ -15,15 +13,13 @@ import com.fr.json.revise.EmbedJson; import com.fr.stable.StringUtils; import com.fr.third.guava.collect.ImmutableMap; import com.fr.workspace.WorkContext; -import com.teamdev.jxbrowser.browser.callback.InjectJsCallback; -import javax.swing.SwingUtilities; import java.awt.BorderLayout; -import java.awt.Window; import java.util.Arrays; import static com.fr.design.ui.ModernUIConstants.DOT; -import static com.fr.design.ui.ModernUIConstants.WINDOW; +import static com.fr.design.ui.ModernUIConstants.EMB_TAG; +import static com.fr.design.ui.ModernUIConstants.SCHEME_HEADER; /** * 数据中心数据集面板 @@ -38,26 +34,40 @@ public class DCTableDataPane extends AbstractTableDataPane { private static final String DATA_CENTER = "dc"; private static final String DATA_CENTER_HELPER = "dcHelper"; + private static final String DATA_CENTER_INJECT_URL = "fineServletURL"; + private static final String DC_INDEX_HTML = "com/fr/design/data/tabledata/datacenter/web/data-choose.prod.html"; private final JxUIPane dataCenterJxUIPane; - private JxTableDataNamePane namePane; + private final JxTableDataNamePane namePane = new JxTableDataNamePane(this); // 用于复制粘贴场景 private DCTableData dcTableData; + /** + * 用于创建带有名称的面板 + * + * @param name 名称 + */ + public DCTableDataPane(String name) { + this(); + namePane.setObjectName(name); + } + public DCTableDataPane() { setLayout(new BorderLayout()); dataCenterJxUIPane = getJxUIPane(); add(dataCenterJxUIPane, BorderLayout.CENTER); dataCenterJxUIPane.addXHRHeaders(ImmutableMap.of("Authorization", WorkContext.getCurrent().getConnection().getToken())); + // 关联 bridge 和 pane + DCTableDataJSBridge.relationPanel(this); } private static JxUIPane getJxUIPane() { + return new JxUIPane.Builder() .engine(JX_ENGINE) .namespace(DATA_CENTER) .bindWindow(DATA_CENTER_HELPER, DCTableDataJSBridge::getBridge) - .withEMB("com/fr/design/data/tabledata/datacenter/web/data-choose.prod.html", - ImmutableMap.of("fineServletURL", getDatacentersUrl())) + .withEMB(DC_INDEX_HTML, ImmutableMap.of(DATA_CENTER_INJECT_URL, getDatacentersUrl())) .build(); } @@ -72,17 +82,37 @@ public class DCTableDataPane extends AbstractTableDataPane { @Override public NamePane asNamePane() { - return namePane = new JxTableDataNamePane(this); + return namePane; } @Override public void populateBean(DCTableData ob) { - DCTableDataJSBridge.relationPanel(this); + reload(); dcTableData = ob; - dataCenterJxUIPane.populate(EmbedJson.encode(ob.toBean())); + updateTableDataName(dcTableData, namePane.getObjectName()); + dataCenterJxUIPane.populate(EmbedJson.encode(dcTableData.toBean())); + setDatasetNames(dcTableData); + } + + private void reload() { + dataCenterJxUIPane.redirect(EMB_TAG + SCHEME_HEADER + DC_INDEX_HTML, + ImmutableMap.of(DATA_CENTER_INJECT_URL, getDatacentersUrl())); + } + + private static void updateTableDataName(DCTableData dcTableData, String name) { + if (StringUtils.isNotBlank(name)) { + dcTableData.setDsName(name); + dcTableData.setName(name); + } + } + + private void setDatasetNames(DCTableData ob) { String[] allDSNames = DesignTableDataManager.getAllDSNames(DesignTableDataManager.getEditingTableDataSource()); - dataCenterJxUIPane.executeJS(DATA_CENTER + DOT + "datasetNames=" + EmbedJson.encode(allDSNames)); + String[] allName = Arrays.stream(allDSNames) + .filter(name -> !ob.getDsName().equals(name)) + .toArray(String[]::new); + dataCenterJxUIPane.executeJS(DATA_CENTER + DOT + "datasetNames=" + EmbedJson.encode(allName)); } @@ -95,8 +125,7 @@ public class DCTableDataPane extends AbstractTableDataPane { return DCTableData.fromBean(tableDataBean); } else { // 复制的场景下,不打开界面需要返回数据集,需同步面板的名称 - dcTableData.setDsName(namePane.getObjectName()); - dcTableData.setName(namePane.getObjectName()); + updateTableDataName(dcTableData, namePane.getObjectName()); return dcTableData; } } diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/TableDataPaneHelper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/TableDataPaneHelper.java new file mode 100644 index 0000000000..86534aa0b3 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/TableDataPaneHelper.java @@ -0,0 +1,46 @@ +package com.fr.design.data.tabledata.tabledatapane; + +import com.fr.base.AbstractTableData; +import com.fr.design.data.tabledata.datacenter.DCTableDataPane; +import com.fr.third.guava.collect.Sets; + +import java.util.Set; + +/** + * 数据集面板帮助类 + * + * @author vito + * @since 11.0 + * Created on 2024/9/10 + */ +public class TableDataPaneHelper { + /** + * 标记优先使用带名称的构造方法 + */ + private final static Set>> NAMED_TABLE_DATA_PANE = + Sets.newHashSet( + MultiTDTableDataPane.class, + GlobalMultiTDTableDataPane.class, + TreeTableDataPane.class, + GlobalTreeTableDataPane.class, + DCTableDataPane.class); + + /** + * 是否为带名称的数据集面板 + * + * @param tableDataPaneClass 数据集面板类 + * @return 是否为带名称的数据集面板 + */ + public static boolean isNamedTableDataPane(Class tableDataPaneClass) { + return NAMED_TABLE_DATA_PANE.contains(tableDataPaneClass); + } + + /** + * 注册需要名称的数据集面板 + * + * @param tableDataPaneClass 数据集面板类 + */ + public static void registerNamedTableDataPane(Class> tableDataPaneClass) { + NAMED_TABLE_DATA_PANE.add(tableDataPaneClass); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java index 2b419f90a6..5cd4893572 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java @@ -16,6 +16,7 @@ import com.fr.datacenters.tabledata.DCTableData; import com.fr.decision.webservice.bean.dataset.ServerDataSetBean; import com.fr.design.data.datapane.TableDataNameObjectCreator; import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper; +import com.fr.design.data.datapane.preview.TableDataBeanHelper; import com.fr.design.data.tabledata.datacenter.DCTableDataPane; import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; import com.fr.design.data.tabledata.tabledatapane.ClassTableDataPane; @@ -25,13 +26,12 @@ import com.fr.design.data.tabledata.tabledatapane.EmbeddedTableDataPane; import com.fr.design.data.tabledata.tabledatapane.FileTableDataPane; import com.fr.design.data.tabledata.tabledatapane.MultiTDTableDataPane; import com.fr.design.data.tabledata.tabledatapane.ProcedureDataPane; +import com.fr.design.data.tabledata.tabledatapane.TableDataPaneHelper; import com.fr.design.data.tabledata.tabledatapane.TreeTableDataPane; -import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.StringUtils; import com.fr.workspace.server.repository.connection.ConnectionRepository; -import com.fr.design.data.datapane.preview.TableDataBeanHelper; import com.fr.workspace.server.repository.tabledata.TableDataRepository; import javax.swing.Icon; @@ -56,7 +56,7 @@ public abstract class TableDataFactory { /** * 有顺序的,用来排序用 */ - private static Map map = new java.util.LinkedHashMap<>(); + private static Map map = new LinkedHashMap<>(); private static Map defaultMap = new LinkedHashMap<>(); @@ -129,12 +129,12 @@ public abstract class TableDataFactory { AbstractTableDataPane datapane = null; TableDataNameObjectCreator tableDataNameObjectCreator = getTableDataNameObjectCreator(tabledata); Class> creatorClass = (Class>) tableDataNameObjectCreator.getUpdatePane(); - if (tableDataNameObjectCreator != null && creatorClass != null) { + if (creatorClass != null) { try { - if (ComparatorUtils.equals(creatorClass, MultiTDTableDataPane.class) || ComparatorUtils.equals(creatorClass, TreeTableDataPane.class)) { - Constructor constructor = creatorClass.getDeclaredConstructor(new Class[]{String.class}); + if (TableDataPaneHelper.isNamedTableDataPane(creatorClass)) { + Constructor> constructor = creatorClass.getDeclaredConstructor(String.class); constructor.setAccessible(true); - datapane = (AbstractTableDataPane) constructor.newInstance(name); + datapane = constructor.newInstance(name); } else { datapane = creatorClass.newInstance(); } diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java index b1bf63bcfe..88d29f82e7 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java @@ -3,16 +3,12 @@ package com.fr.design.gui.controlpane; import com.fr.data.impl.Connection; import com.fr.design.DesignerEnvManager; import com.fr.design.beans.BasicBeanPane; -import com.fr.design.data.tabledata.tabledatapane.GlobalMultiTDTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.GlobalTreeTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.MultiTDTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.TreeTableDataPane; +import com.fr.design.data.tabledata.tabledatapane.TableDataPaneHelper; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.RemoteDesignerWorkspaceInfo; import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.form.event.Listener; -import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import javax.swing.JPanel; @@ -70,7 +66,7 @@ class JControlUpdatePane extends JPanel { Object ob2Populate = creators[i].acceptObject2Populate(el.wrapper); if (ob2Populate != null) { if (updatePanes[i] == null) { - if (isMulti(creators[i].getUpdatePane()) || isTree(creators[i].getUpdatePane())) { + if (TableDataPaneHelper.isNamedTableDataPane(creators[i].getUpdatePane())) { updatePanes[i] = listControlPane.createPaneByCreators(creators[i], el.wrapper.getName()); } else { updatePanes[i] = listControlPane.createPaneByCreators(creators[i]); @@ -94,15 +90,6 @@ class JControlUpdatePane extends JPanel { } } - - public boolean isMulti(Class _class) { - return ComparatorUtils.equals(_class, GlobalMultiTDTableDataPane.class) || ComparatorUtils.equals(_class, MultiTDTableDataPane.class); - } - - public boolean isTree(Class _class) { - return ComparatorUtils.equals(_class, GlobalTreeTableDataPane.class) || ComparatorUtils.equals(_class, TreeTableDataPane.class); - } - public void update() { NameableCreator[] creators = listControlPane.creators(); for (int i = 0; i < updatePanes.length; i++) { diff --git a/designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java b/designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java index 9aea89d465..a40a11e3bc 100644 --- a/designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java +++ b/designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java @@ -29,6 +29,7 @@ import java.util.Objects; import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.function.Consumer; import static com.fr.design.ui.ModernUIConstants.COMPONENT_TAG; import static com.fr.design.ui.ModernUIConstants.DEFAULT_EXPRESSION; @@ -191,6 +192,14 @@ public class JxUIPane extends BasicPane { .ifPresent(ns -> ns.putProperty(variable, t)); return InjectJsCallback.Response.proceed(); }); + if (browser.mainFrame().isPresent()) { + executeJavaScript(WINDOW + DOT + namespace, + (Consumer) jsObject -> { + if (Objects.nonNull(jsObject)) { + jsObject.putProperty(variable, t); + } + }); + } } @Nullable @@ -235,6 +244,18 @@ public class JxUIPane extends BasicPane { } } + /** + * 执行一段js + * + * @param javaScript 待执行的js脚本 + * @see JxUIPane#executeJS(String) + */ + public void executeJavaScript(String javaScript, Consumer consumer) { + if (browser != null) { + browser.mainFrame().ifPresent(frame -> frame.executeJavaScript(javaScript, consumer)); + } + } + /** * 获取js对象 * 注意:类内部使用,用于简化编码,提供 Optional 包装 diff --git a/designer-base/src/test/java/com/fr/design/ui/report/ReportServerParamDemo.java b/designer-base/src/test/java/com/fr/design/ui/report/ReportServerParamDemo.java deleted file mode 100644 index 42199134dc..0000000000 --- a/designer-base/src/test/java/com/fr/design/ui/report/ReportServerParamDemo.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.fr.design.ui.report; - -import com.fr.design.DesignerEnvManager; -import com.fr.design.ui.ModernUIPane; -import com.fr.design.ui.ModernUIPaneTest; - -import javax.swing.*; -import java.awt.*; - -/** - * Created by windy on 2019/3/25. - * 报表服务器参数demo - */ -public class ReportServerParamDemo { - - public static void main(String... args) { - final JFrame frame = new JFrame(); - frame.setSize(660, 600); - JPanel contentPane = (JPanel) frame.getContentPane(); - // 是否需要开启调试窗口 - DesignerEnvManager.getEnvManager().setOpenDebug(true); - - final ModernUIPane pane = new ModernUIPane.Builder() - .withComponent(ReportServerParamComponent.KEY).build(); - contentPane.add(pane, BorderLayout.CENTER); - frame.setVisible(true); - frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - } -}