Browse Source

Pull request #9799: REPORT-75140 抽象出一个多结果数据集,选中预览的问题

Merge in DESIGN/design from ~RINOUX/design:feature/x to feature/x

* commit '9e87cf47072d6495162e08393249d6fabba4e3ed':
  REPORT-75140 抽象出一个多结果数据集,选中预览的问题
feature/x
rinoux 2 years ago
parent
commit
e8d0f8c5f7
  1. 2
      designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java
  2. 2
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java
  3. 72
      designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java
  4. 35
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java
  5. 71
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java

2
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();

2
designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java

@ -379,7 +379,7 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> {
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;

72
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());

35
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<String> columnNameList;
private List<String> 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<String> 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<String> calculateColumnNameList() {
if (columnNameList != null) {
return columnNameList;
if (childrenList != null) {
return childrenList;
}
columnNameList = new ArrayList<String>();
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);
}
/**

71
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<String> 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());

Loading…
Cancel
Save