From 3ff87754b561898d5647bbe48002ac665c5bf12d Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 10 Sep 2024 16:03:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-132414=20&=20REPORT-132506=20=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8F=9C=E5=8D=95=E5=85=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=BC=B9=E7=AA=97=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tabledata/datacenter/DCTableDataPane.java | 59 ++++++++++++++----- .../tabledatapane/TableDataPaneHelper.java | 46 +++++++++++++++ .../tabledata/wrapper/TableDataFactory.java | 14 ++--- .../gui/controlpane/JControlUpdatePane.java | 17 +----- .../com/fr/design/jxbrowser/JxUIPane.java | 44 ++++++++++---- .../ui/report/ReportServerParamDemo.java | 29 --------- 6 files changed, 131 insertions(+), 78 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/TableDataPaneHelper.java delete mode 100644 designer-base/src/test/java/com/fr/design/ui/report/ReportServerParamDemo.java 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..b08e6dd25d 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 @@ -1,7 +1,6 @@ package com.fr.design.jxbrowser; import com.fr.concurrent.NamedThreadFactory; -import com.fr.design.DesignerEnvManager; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.itoolbar.UIToolbar; @@ -29,6 +28,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; @@ -99,17 +99,17 @@ public class JxUIPane extends BasicPane { */ private void initDebugIfNeeded() { if (DesignerEnvManager.getEnvManager().isOpenDebug()) { - UIToolbar toolbar = new UIToolbar(); - add(toolbar, BorderLayout.NORTH); - UIButton openDebugButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Open_Debug_Window")); - openDebugButton.addActionListener(e -> browser.devTools().show()); - toolbar.add(openDebugButton); - UIButton reloadButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Reload")); - reloadButton.addActionListener(e -> browser.navigation().reloadIgnoringCache()); - toolbar.add(reloadButton); - UIButton closeButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Close_Window")); - closeButton.addActionListener(e -> SwingUtilities.getWindowAncestor(JxUIPane.this).setVisible(false)); - toolbar.add(closeButton); + UIToolbar toolbar = new UIToolbar(); + add(toolbar, BorderLayout.NORTH); + UIButton openDebugButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Open_Debug_Window")); + openDebugButton.addActionListener(e -> browser.devTools().show()); + toolbar.add(openDebugButton); + UIButton reloadButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Reload")); + reloadButton.addActionListener(e -> browser.navigation().reloadIgnoringCache()); + toolbar.add(reloadButton); + UIButton closeButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Close_Window")); + closeButton.addActionListener(e -> SwingUtilities.getWindowAncestor(JxUIPane.this).setVisible(false)); + toolbar.add(closeButton); } } @@ -191,6 +191,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 +243,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); - } -} From eeaf130d80e84a9b67b6034f761fb05d20c7c487 Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 10 Sep 2024 16:12:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=20=E5=88=A0?= =?UTF-8?q?=E5=A4=9A=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/jxbrowser/JxUIPane.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 b08e6dd25d..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 @@ -1,6 +1,7 @@ package com.fr.design.jxbrowser; import com.fr.concurrent.NamedThreadFactory; +import com.fr.design.DesignerEnvManager; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.itoolbar.UIToolbar; @@ -99,17 +100,17 @@ public class JxUIPane extends BasicPane { */ private void initDebugIfNeeded() { if (DesignerEnvManager.getEnvManager().isOpenDebug()) { - UIToolbar toolbar = new UIToolbar(); - add(toolbar, BorderLayout.NORTH); - UIButton openDebugButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Open_Debug_Window")); - openDebugButton.addActionListener(e -> browser.devTools().show()); - toolbar.add(openDebugButton); - UIButton reloadButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Reload")); - reloadButton.addActionListener(e -> browser.navigation().reloadIgnoringCache()); - toolbar.add(reloadButton); - UIButton closeButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Close_Window")); - closeButton.addActionListener(e -> SwingUtilities.getWindowAncestor(JxUIPane.this).setVisible(false)); - toolbar.add(closeButton); + UIToolbar toolbar = new UIToolbar(); + add(toolbar, BorderLayout.NORTH); + UIButton openDebugButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Open_Debug_Window")); + openDebugButton.addActionListener(e -> browser.devTools().show()); + toolbar.add(openDebugButton); + UIButton reloadButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Reload")); + reloadButton.addActionListener(e -> browser.navigation().reloadIgnoringCache()); + toolbar.add(reloadButton); + UIButton closeButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Close_Window")); + closeButton.addActionListener(e -> SwingUtilities.getWindowAncestor(JxUIPane.this).setVisible(false)); + toolbar.add(closeButton); } }