From 9e87cf47072d6495162e08393249d6fabba4e3ed Mon Sep 17 00:00:00 2001 From: rinoux Date: Wed, 17 Aug 2022 10:28:03 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-75140=20=E6=8A=BD=E8=B1=A1=E5=87=BA?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=A4=9A=E7=BB=93=E6=9E=9C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86,=E9=80=89=E4=B8=AD=E9=A2=84=E8=A7=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/data/BasicTableDataTreePane.java | 2 +- .../design/data/datapane/TableDataTree.java | 2 +- .../datapane/preview/PreviewTablePane.java | 72 +++++++++++++------ .../MultiResultTableDataNameWrapper.java | 35 ++++----- .../wrapper/MultiResultTableDataWrapper.java | 71 ++++++++++++------ 5 files changed, 118 insertions(+), 64 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java index 28077f9df2..3dbcf81873 100644 --- a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java @@ -444,7 +444,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp ((MultiResultTableData) (((TableDataWrapper) data).getTableData())).resetDataModelList(); if (data instanceof MultiResultTableDataWrapper) { MultiResultTableDataWrapper oldSdw = ((MultiResultTableDataWrapper) data); - MultiResultTableDataWrapper newSdw = new MultiResultTableDataWrapper((MultiResultTableData) oldSdw.getTableData(), oldSdw.getTableDataName(), oldSdw.getTableDataName()); + MultiResultTableDataWrapper newSdw = new MultiResultTableDataWrapper((MultiResultTableData) oldSdw.getTableData(), oldSdw.getTableDataName(), oldSdw.getDataModelName()); newSdw.previewData(MultiResultTableDataWrapper.PREVIEW_ONE); } else { MultiResultTableData tableData = (MultiResultTableData) ((TableDataWrapper) data).getTableData(); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java index 619c027462..e8ac19fd07 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java @@ -379,7 +379,7 @@ public class TableDataTree extends UserObjectRefreshJTree { return false; } Object userObject = treeNode.getUserObject(); - if (userObject instanceof NameObject && ((NameObject) userObject).getObject() instanceof AbstractTableDataWrapper) { + if (userObject instanceof NameObject && ((NameObject) userObject).getObject() instanceof TableDataWrapper) { return true; } return false; diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java index 330c604d59..5926dcb2df 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java @@ -8,7 +8,6 @@ import com.fr.base.TableData; import com.fr.data.TableDataSource; import com.fr.data.impl.DBTableData; import com.fr.data.impl.EmbeddedTableData; - import com.fr.data.impl.NameDataModel; import com.fr.data.operator.DataOperator; import com.fr.design.DesignerEnvManager; @@ -65,7 +64,7 @@ import java.util.concurrent.CancellationException; */ public class PreviewTablePane extends BasicPane { private TableData tableData; - private NameDataModel dataModel; + private DataModel dataModel; private UINumberField maxPreviewNumberField; private UINumberField currentRowsField; private JTable preveiwTable; @@ -156,7 +155,7 @@ public class PreviewTablePane extends BasicPane { try { populate(tableData); if (dataModel != null) { - populateStoreDataSQL(); + setRowsLimitTableModel(); } } catch (Exception e1) { } @@ -426,6 +425,7 @@ public class PreviewTablePane extends BasicPane { * * @param storeProcedureDataModel storeProcedureDataModel */ + @Deprecated public static void previewStoreData(NameDataModel storeProcedureDataModel) { previewStoreData(storeProcedureDataModel, -1, -1); } @@ -437,13 +437,30 @@ public class PreviewTablePane extends BasicPane { * @param keyIndex 实际值 * @param valueIndex 显示值 */ + @Deprecated public static void previewStoreData(final NameDataModel storeProcedureDataModel, final int keyIndex, final int valueIndex) { + previewDataModel(storeProcedureDataModel, keyIndex, valueIndex); + } + + public static void previewDataModel(DataModel dataModel) { + previewDataModel(dataModel, -1, -1); + } + + + /** + * 直接预览数据集的结果集 + * + * @param dataModel 结果集 + * @param keyIndex + * @param valueIndex + */ + public static void previewDataModel(final DataModel dataModel, final int keyIndex, final int valueIndex) { final PreviewTablePane previewTablePane = new PreviewTablePane(); - previewTablePane.dataModel = storeProcedureDataModel; + previewTablePane.dataModel = dataModel; previewTablePane.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Basic_Data"))); try { - previewTablePane.populateStoreDataSQL(); + previewTablePane.setRowsLimitTableModel(); previewTablePane.resetPreviewTableColumnColor(); if (keyIndex > -1) { @@ -460,27 +477,28 @@ public class PreviewTablePane extends BasicPane { previewTablePane.showWindow(new JFrame()).setVisible(true); } - /** - * 直接预览存储过程的所有返回数据集,没有实际值和显示值 - * - * @param storeProcedureDataModels storeProcedureDataModels - */ - public static void previewStoreDataWithAllDs(NameDataModel[] storeProcedureDataModels) { - UITabbedPane tabPreviewpane = new UITabbedPane(); - int tableSize = storeProcedureDataModels.length; - for (int i = 0; i < tableSize; i++) { + + public static void previewMultiDataModels(NameDataModel[] nameDataModels) { + // tab窗口 + UITabbedPane tabbedPane = new UITabbedPane(); + + for (NameDataModel nameDataModel : nameDataModels) { + // 单个结果集的展示面板 PreviewTablePane previewTablePane = new PreviewTablePane(); - previewTablePane.dataModel = storeProcedureDataModels[i]; + previewTablePane.dataModel = nameDataModel; + // 数据 previewTablePane.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Basic_Data"))); try { - previewTablePane.populateStoreDataSQL(); + // 带行数限制的数据集结果预览对象 + previewTablePane.setRowsLimitTableModel(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } - tabPreviewpane.addTab(storeProcedureDataModels[i].getName(), previewTablePane); + tabbedPane.addTab(nameDataModel.getName(), previewTablePane); } - BasicPane prieviewPane = new BasicPane() { + // 包含整个tab的容器窗口 + BasicPane previewPane = new BasicPane() { @Override protected String title4PopupWindow() { @@ -488,12 +506,22 @@ public class PreviewTablePane extends BasicPane { } }; - prieviewPane.setLayout(FRGUIPaneFactory.createBorderLayout()); - prieviewPane.add(tabPreviewpane, BorderLayout.CENTER); - prieviewPane.showWindow(new JFrame()).setVisible(true); + previewPane.setLayout(FRGUIPaneFactory.createBorderLayout()); + previewPane.add(tabbedPane, BorderLayout.CENTER); + previewPane.showWindow(new JFrame()).setVisible(true); + } + + /** + * 直接预览存储过程的所有返回数据集,没有实际值和显示值 + * + * @param storeProcedureDataModels storeProcedureDataModels + */ + @Deprecated + public static void previewStoreDataWithAllDs(NameDataModel[] storeProcedureDataModels) { + previewMultiDataModels(storeProcedureDataModels); } - private void populateStoreDataSQL() throws Exception { + private void setRowsLimitTableModel() throws Exception { PreviewTableModel previewModel; try { previewModel = new PreviewTableModel(dataModel, (int) maxPreviewNumberField.getValue()); diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java index 05c302e97b..6b42fa03b2 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java @@ -1,6 +1,5 @@ package com.fr.design.data.tabledata.wrapper; -import com.fr.base.BaseUtils; import com.fr.base.TableData; import com.fr.data.MultiResultTableData; import com.fr.data.impl.NameDataModel; @@ -9,6 +8,7 @@ import com.fr.design.data.datapane.TableDataCreatorProducer; import com.fr.design.data.datapane.TableDataNameObjectCreator; import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import com.fr.workspace.WorkContext; @@ -29,15 +29,15 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { private NameDataModel dataModel; private final String name; private final MultiResultTableData tableData; - private List columnNameList; + private List childrenList; /** - * @param name 存储过程本身名字 - * @param storeProcedure 存储过程 + * @param name 数据集名字 + * @param tableData 数据集 */ - public MultiResultTableDataNameWrapper(String name, MultiResultTableData storeProcedure) { + public MultiResultTableDataNameWrapper(String name, MultiResultTableData tableData) { this.name = name; - this.tableData = storeProcedure; + this.tableData = tableData; } /** @@ -46,6 +46,7 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { * @return 子节点 */ public ExpandMutableTreeNode[] load() { + // 生成多数据集结果子节点 List namelist = calculateColumnNameList(); ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[namelist.size()]; for (int i = 0; i < res.length; i++) { @@ -67,17 +68,17 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { @Override public Icon getIcon() { - // TODO for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { if (creator.createObject().getClass() == this.tableData.getClass()) { - return BaseUtils.readIcon(creator.getIconPath()); + return IOUtils.readIcon(creator.getIconPath()); } } - return BaseUtils.readIcon("/com/fr/design/images/data/multi.png"); + return IOUtils.readIcon("/com/fr/design/images/data/multi.png"); } private void createResult(boolean needLoadingBar) { try { + // todo 啥意思? dataModel = DesignTableDataManager.createLazyDataModel(tableData, needLoadingBar)[0]; } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); @@ -92,14 +93,14 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { * @return 字段 */ public List calculateColumnNameList() { - if (columnNameList != null) { - return columnNameList; + if (childrenList != null) { + return childrenList; } - columnNameList = new ArrayList(); + childrenList = new ArrayList<>(); if (!WorkContext.getCurrent().isLocal()) { try { createResult(false); - columnNameList = Arrays.asList(dataModel.getColumnNames()); + childrenList = Arrays.asList(dataModel.getColumnNames()); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } @@ -109,10 +110,10 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { createResult(false); } if (dataModel != null) { - columnNameList = Arrays.asList(dataModel.getColumnNames()); + childrenList = Arrays.asList(dataModel.getColumnNames()); } } - return columnNameList; + return childrenList; } /** @@ -122,7 +123,7 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { if (dataModel == null) { createResult(true); } - PreviewTablePane.previewStoreData(dataModel); + PreviewTablePane.previewDataModel(dataModel); } @@ -136,7 +137,7 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { if (dataModel == null) { createResult(true); } - PreviewTablePane.previewStoreData(dataModel, keyIndex, valueIndex); + PreviewTablePane.previewDataModel(dataModel, keyIndex, valueIndex); } /** diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java index 9b626f5951..698b192208 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java @@ -1,6 +1,5 @@ package com.fr.design.data.tabledata.wrapper; -import com.fr.base.BaseUtils; import com.fr.base.TableData; import com.fr.data.MultiResultTableData; import com.fr.data.impl.NameDataModel; @@ -16,6 +15,7 @@ import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.general.ComparatorUtils; +import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import javax.swing.Icon; @@ -40,7 +40,7 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { public static AutoProgressBar loadingBar; private NameDataModel dataModel; - private final String dsName; + private final String dataModelName; private final String tableDataName; private final MultiResultTableData tableData; private List columnNameList; @@ -49,29 +49,45 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { private SwingWorker worker; private int previewModel; - public MultiResultTableDataWrapper(MultiResultTableData tableData, String tableDataName, String dsName) { - this(null, tableData, tableDataName, dsName, true); + /** + * @param tableData 数据集 + * @param tableDataName 数据集名称 + * @param dataModelName 数据集的一个结果的名称(全限定名称) + */ + public MultiResultTableDataWrapper(MultiResultTableData tableData, String tableDataName, String dataModelName) { + this(null, tableData, tableDataName, dataModelName, true); } - public MultiResultTableDataWrapper(MultiResultTableData tableData, String tableDataName, String dsName, boolean needLoad) { - this(null, tableData, tableDataName, dsName, needLoad); + /** + * @param tableData 数据集 + * @param tableDataName 数据集名称 + * @param dataModelName 数据集的一个结果的名称(全限定名称) + * @param needLoad 是否需要加载 + */ + public MultiResultTableDataWrapper(MultiResultTableData tableData, String tableDataName, String dataModelName, boolean needLoad) { + this(null, tableData, tableDataName, dataModelName, needLoad); } - public MultiResultTableDataWrapper(Component component, MultiResultTableData tableData, String tableDataName, String dsName) { - this(component, tableData, tableDataName, dsName, true); + /** + * @param component 父容器 + * @param tableData 数据集 + * @param tableDataName 数据集名称 + * @param dataModelName 数据集的一个结果的名称(全限定名称) + */ + public MultiResultTableDataWrapper(Component component, MultiResultTableData tableData, String tableDataName, String dataModelName) { + this(component, tableData, tableDataName, dataModelName, true); } /** * @param component loadingBar的父弹框(如果不设置父弹框的话,可能出现loadingBar隐藏在一个弹框后的情况) - * @param tableData 存储过程 - * @param tableDataName 存储过程的名字(某些情况下可以为空) - * @param dsName 存储过程一个返回数据集的名字 + * @param tableData 多结果数据集 + * @param tableDataName 多结果数据集的名字(某些情况下可以为空) + * @param dataModelName 多结果数据集一个返回数据集的名字 * @param needLoad 是否要加载 **/ - public MultiResultTableDataWrapper(Component component, MultiResultTableData tableData, String tableDataName, String dsName, boolean needLoad) { - this.dsName = dsName; + public MultiResultTableDataWrapper(Component component, MultiResultTableData tableData, String tableDataName, String dataModelName, boolean needLoad) { + this.dataModelName = dataModelName; this.tableData = tableData; - /*this.tableData.setCalculating(false);*/ this.tableDataName = tableDataName; if (component == null) { component = new JFrame(); @@ -133,10 +149,11 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { private void createResults(boolean needLoadingBar) throws Exception { + this.dataModel = null; dataModels = DesignTableDataManager.createLazyDataModel(tableData, needLoadingBar); if (dataModels != null && dataModels.length != 0) { for (NameDataModel dataModel : dataModels) { - if (ComparatorUtils.equals(this.dsName, tableDataName + "_" + dataModel.getName())) { + if (ComparatorUtils.equals(this.dataModelName, tableDataName + MultiResultTableData.GROUP_MARKER + dataModel.getName())) { this.dataModel = dataModel; break; } @@ -148,10 +165,10 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { public Icon getIcon() { for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { if (creator.createObject().getClass() == this.tableData.getClass()) { - return BaseUtils.readIcon(creator.getIconPath()); + return IOUtils.readIcon(creator.getIconPath()); } } - return BaseUtils.readIcon("/com/fr/design/images/data/multi.png"); + return IOUtils.readIcon("/com/fr/design/images/data/multi.png"); } /** @@ -179,6 +196,8 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { loadingBar.close(); PreviewTablePane.resetPreviewTable(); connectionBar.start(); + + // 存储过程需要先测试一下连接 if (tableData instanceof StoreProcedure) { boolean status = DataOperator.getInstance().testConnection(((StoreProcedure) getTableData()).getDatabaseConnection()); if (!status) { @@ -189,6 +208,8 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { connectionBar.close(); tableData.resetDataModelList(); + + // 获取结果 createResults(true); return null; } @@ -200,7 +221,7 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { loadingBar.close(); switch (previewModel) { case MultiResultTableDataWrapper.PREVIEW_ALL: - PreviewTablePane.previewStoreDataWithAllDs(dataModels); + PreviewTablePane.previewMultiDataModels(dataModels); break; case MultiResultTableDataWrapper.PREVIEW_ONE: previewData(); @@ -246,12 +267,12 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { */ @Override public void previewData(final int keyIndex, final int valueIndex) { - PreviewTablePane.previewStoreData(dataModel, keyIndex, valueIndex); + PreviewTablePane.previewDataModel(dataModel, keyIndex, valueIndex); } /** - * 预览返回的所有数据集,只有在编辑存储过程时才用到 + * 预览返回的所有数据集,只有在编辑多结果数据集时才用到 */ public void previewAllTable() { if (dataModel == null) { @@ -261,12 +282,16 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { return; } } - PreviewTablePane.previewStoreDataWithAllDs(dataModels); + PreviewTablePane.previewMultiDataModels(dataModels); } @Override public String getTableDataName() { - return dsName; + return tableDataName; + } + + public String getDataModelName() { + return dataModelName; } @Override @@ -287,7 +312,7 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { @Override public boolean equals(Object obj) { return obj instanceof MultiResultTableDataWrapper - && ComparatorUtils.equals(this.dsName, ((MultiResultTableDataWrapper) obj).getTableDataName()) + && ComparatorUtils.equals(this.dataModelName, ((MultiResultTableDataWrapper) obj).getTableDataName()) && ComparatorUtils.equals(this.tableData, ((MultiResultTableDataWrapper) obj).getTableData()) && ComparatorUtils.equals(this.tableDataName, ((MultiResultTableDataWrapper) obj).getTableDataName());