rinoux
2 years ago
11 changed files with 584 additions and 93 deletions
@ -0,0 +1,150 @@
|
||||
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; |
||||
import com.fr.design.data.DesignTableDataManager; |
||||
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.log.FineLoggerFactory; |
||||
import com.fr.workspace.WorkContext; |
||||
|
||||
import javax.swing.Icon; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* 多结果数据集-结果包装 |
||||
* |
||||
* @author rinoux |
||||
* @version 11.0 |
||||
* Created by rinoux on 2022/8/12 |
||||
*/ |
||||
public final class MultiResultTableDataNameWrapper implements TableDataWrapper { |
||||
private NameDataModel dataModel; |
||||
private final String name; |
||||
private final MultiResultTableData<?> tableData; |
||||
private List<String> columnNameList; |
||||
|
||||
/** |
||||
* @param name 存储过程本身名字 |
||||
* @param storeProcedure 存储过程 |
||||
*/ |
||||
public MultiResultTableDataNameWrapper(String name, MultiResultTableData<?> storeProcedure) { |
||||
this.name = name; |
||||
this.tableData = storeProcedure; |
||||
} |
||||
|
||||
/** |
||||
* 生成子节点 |
||||
* |
||||
* @return 子节点 |
||||
*/ |
||||
public ExpandMutableTreeNode[] load() { |
||||
List<String> namelist = calculateColumnNameList(); |
||||
ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[namelist.size()]; |
||||
for (int i = 0; i < res.length; i++) { |
||||
res[i] = new ExpandMutableTreeNode(namelist.get(i)); |
||||
} |
||||
|
||||
return res; |
||||
} |
||||
|
||||
@Override |
||||
public String getTableDataName() { |
||||
return name; |
||||
} |
||||
|
||||
@Override |
||||
public TableData getTableData() { |
||||
return tableData; |
||||
} |
||||
|
||||
@Override |
||||
public Icon getIcon() { |
||||
// TODO
|
||||
for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { |
||||
if (creator.createObject().getClass() == this.tableData.getClass()) { |
||||
return BaseUtils.readIcon(creator.getIconPath()); |
||||
} |
||||
} |
||||
return BaseUtils.readIcon("/com/fr/design/images/data/store_procedure.png"); |
||||
} |
||||
|
||||
private void createResult(boolean needLoadingBar) { |
||||
try { |
||||
dataModel = DesignTableDataManager.createLazyDataModel(tableData, needLoadingBar)[0]; |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 数据集执行结果返回的所有字段 |
||||
* <p/> |
||||
* TODO:要不要加上Exception呢?个人感觉很有必要 |
||||
* |
||||
* @return 字段 |
||||
*/ |
||||
public List<String> calculateColumnNameList() { |
||||
if (columnNameList != null) { |
||||
return columnNameList; |
||||
} |
||||
columnNameList = new ArrayList<String>(); |
||||
if (!WorkContext.getCurrent().isLocal()) { |
||||
try { |
||||
createResult(false); |
||||
columnNameList = Arrays.asList(dataModel.getColumnNames()); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
|
||||
} else { |
||||
if (dataModel == null) { |
||||
createResult(false); |
||||
} |
||||
if (dataModel != null) { |
||||
columnNameList = Arrays.asList(dataModel.getColumnNames()); |
||||
} |
||||
} |
||||
return columnNameList; |
||||
} |
||||
|
||||
/** |
||||
* 预览数据集 |
||||
*/ |
||||
public void previewData() { |
||||
if (dataModel == null) { |
||||
createResult(true); |
||||
} |
||||
PreviewTablePane.previewStoreData(dataModel); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 预览数据集,带有显示值和实际值的标记结果 |
||||
* |
||||
* @param keyIndex 显示值Index |
||||
* @param valueIndex 实际值index |
||||
*/ |
||||
public void previewData(int keyIndex, int valueIndex) { |
||||
if (dataModel == null) { |
||||
createResult(true); |
||||
} |
||||
PreviewTablePane.previewStoreData(dataModel, keyIndex, valueIndex); |
||||
} |
||||
|
||||
/** |
||||
* 是否异常 |
||||
* |
||||
* @return 异常返回true |
||||
*/ |
||||
public boolean isUnusual() { |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,296 @@
|
||||
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; |
||||
import com.fr.data.impl.storeproc.StoreProcedure; |
||||
import com.fr.data.operator.DataOperator; |
||||
import com.fr.design.data.DesignTableDataManager; |
||||
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.dialog.FineJOptionPane; |
||||
import com.fr.design.gui.iprogressbar.AutoProgressBar; |
||||
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.log.FineLoggerFactory; |
||||
|
||||
import javax.swing.Icon; |
||||
import javax.swing.JFrame; |
||||
import javax.swing.SwingWorker; |
||||
import java.awt.Component; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.concurrent.CancellationException; |
||||
|
||||
/** |
||||
* 多结果数据集包装 |
||||
* |
||||
* @author rinoux |
||||
* @version 11.0 |
||||
* Created by rinoux on 2022/8/12 |
||||
*/ |
||||
public final class MultiResultTableDataWrapper implements TableDataWrapper { |
||||
public static final int PREVIEW_ALL = 0; |
||||
public static final int PREVIEW_ONE = 1; |
||||
public static AutoProgressBar loadingBar; |
||||
|
||||
private NameDataModel dataModel; |
||||
private final String dsName; |
||||
private final String tableDataName; |
||||
private final MultiResultTableData<?> tableData; |
||||
private List<String> columnNameList; |
||||
private AutoProgressBar connectionBar; |
||||
private NameDataModel[] dataModels; |
||||
private SwingWorker<?, ?> worker; |
||||
private int previewModel; |
||||
|
||||
public MultiResultTableDataWrapper(MultiResultTableData<?> tableData, String tableDataName, String dsName) { |
||||
this(null, tableData, tableDataName, dsName, true); |
||||
} |
||||
|
||||
public MultiResultTableDataWrapper(MultiResultTableData<?> tableData, String tableDataName, String dsName, boolean needLoad) { |
||||
this(null, tableData, tableDataName, dsName, needLoad); |
||||
} |
||||
|
||||
public MultiResultTableDataWrapper(Component component, MultiResultTableData<?> tableData, String tableDataName, String dsName) { |
||||
this(component, tableData, tableDataName, dsName, true); |
||||
} |
||||
|
||||
/** |
||||
* @param component loadingBar的父弹框(如果不设置父弹框的话,可能出现loadingBar隐藏在一个弹框后的情况) |
||||
* @param tableData 存储过程 |
||||
* @param tableDataName 存储过程的名字(某些情况下可以为空) |
||||
* @param dsName 存储过程一个返回数据集的名字 |
||||
* @param needLoad 是否要加载 |
||||
**/ |
||||
public MultiResultTableDataWrapper(Component component, MultiResultTableData<?> tableData, String tableDataName, String dsName, boolean needLoad) { |
||||
this.dsName = dsName; |
||||
this.tableData = tableData; |
||||
this.tableData.setCalculating(false); |
||||
this.tableDataName = tableDataName; |
||||
if (component == null) { |
||||
component = new JFrame(); |
||||
} |
||||
if (needLoad) { |
||||
setWorker(component); |
||||
} |
||||
loadingBar = new AutoProgressBar(component, Toolkit.i18nText("Fine-Design_Basic_Loading_Data"), "", 0, 100) { |
||||
@Override |
||||
public void doMonitorCanceled() { |
||||
getWorker().cancel(true); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* 数据集执行结果返回的所有字段 |
||||
* |
||||
* @return 数据集执行结果返回的所有字段 |
||||
* @date 2014-12-3-下午7:43:17 |
||||
*/ |
||||
@Override |
||||
public List<String> calculateColumnNameList() { |
||||
if (columnNameList != null) { |
||||
return columnNameList; |
||||
} |
||||
|
||||
try { |
||||
createResults(false); |
||||
} catch (Exception e) { |
||||
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Engine_No_TableData")); |
||||
return new ArrayList<String>(); |
||||
} |
||||
columnNameList = Arrays.asList(dataModel.getColumnNames()); |
||||
return columnNameList; |
||||
} |
||||
|
||||
/** |
||||
* 生成子节点 |
||||
* |
||||
* @return 节点数组 |
||||
* @date 2014-12-3-下午7:06:47 |
||||
*/ |
||||
@Override |
||||
public ExpandMutableTreeNode[] load() { |
||||
List<String> namelist; |
||||
if (tableData.isCalculating()) { |
||||
namelist = Arrays.asList(new String[0]); |
||||
} else { |
||||
namelist = calculateColumnNameList(); |
||||
} |
||||
ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[namelist.size()]; |
||||
for (int i = 0; i < res.length; i++) { |
||||
res[i] = new ExpandMutableTreeNode(namelist.get(i)); |
||||
} |
||||
|
||||
return res; |
||||
} |
||||
|
||||
private void createResults(boolean needLoadingBar) throws Exception { |
||||
|
||||
dataModels = DesignTableDataManager.createLazyDataModel(tableData, needLoadingBar); |
||||
if (dataModels != null && dataModels.length != 0) { |
||||
for (NameDataModel dataModel : dataModels) { |
||||
if (ComparatorUtils.equals(this.dsName, tableDataName + "_" + dataModel.getName())) { |
||||
this.dataModel = dataModel; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Icon getIcon() { |
||||
for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { |
||||
if (creator.createObject().getClass() == this.tableData.getClass()) { |
||||
return BaseUtils.readIcon(creator.getIconPath()); |
||||
} |
||||
} |
||||
return BaseUtils.readIcon("/com/fr/design/images/data/store_procedure.png"); |
||||
} |
||||
|
||||
/** |
||||
* 预览数据 |
||||
* |
||||
* @param previewModel 预览模式, 全部还是一个 |
||||
* @date 2014-12-3-下午7:05:50 |
||||
*/ |
||||
public void previewData(final int previewModel) { |
||||
this.previewModel = previewModel; |
||||
connectionBar = new AutoProgressBar(new JFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Now_Create_Connection"), "", 0, 100) { |
||||
@Override |
||||
public void doMonitorCanceled() { |
||||
connectionBar.close(); |
||||
worker.cancel(true); |
||||
} |
||||
}; |
||||
worker.execute(); |
||||
} |
||||
|
||||
private void setWorker(final Component parent) { |
||||
worker = new SwingWorker<Void, Void>() { |
||||
@Override |
||||
protected Void doInBackground() throws Exception { |
||||
loadingBar.close(); |
||||
PreviewTablePane.resetPreviewTable(); |
||||
connectionBar.start(); |
||||
if (tableData instanceof StoreProcedure) { |
||||
boolean status = DataOperator.getInstance().testConnection(((StoreProcedure) getTableData()).getDatabaseConnection()); |
||||
if (!status) { |
||||
connectionBar.close(); |
||||
throw new Exception(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed")); |
||||
} |
||||
} |
||||
|
||||
connectionBar.close(); |
||||
tableData.resetDataModelList(); |
||||
createResults(true); |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void done() { |
||||
try { |
||||
get(); |
||||
loadingBar.close(); |
||||
switch (previewModel) { |
||||
case MultiResultTableDataWrapper.PREVIEW_ALL: |
||||
PreviewTablePane.previewStoreDataWithAllDs(dataModels); |
||||
break; |
||||
case MultiResultTableDataWrapper.PREVIEW_ONE: |
||||
previewData(); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} catch (Exception e) { |
||||
loadingBar.close(); |
||||
if (!(e instanceof CancellationException)) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
FineJOptionPane.showMessageDialog(parent, e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
private SwingWorker getWorker() { |
||||
return this.worker; |
||||
} |
||||
|
||||
// august:这个只是预览返回的一个数据集
|
||||
|
||||
/** |
||||
* 预览返回的一个数据集 |
||||
* |
||||
* @date 2014-12-3-下午7:42:53 |
||||
*/ |
||||
@Override |
||||
public void previewData() { |
||||
previewData(-1, -1); |
||||
} |
||||
|
||||
// august:这个只是预览返回的一个数据集
|
||||
|
||||
/** |
||||
* 预览返回的一个数据集,带有显示值和实际值的标记结果 |
||||
* |
||||
* @param keyIndex 实际值 |
||||
* @param valueIndex 显示值 |
||||
* @date 2014-12-3-下午7:42:27 |
||||
*/ |
||||
@Override |
||||
public void previewData(final int keyIndex, final int valueIndex) { |
||||
PreviewTablePane.previewStoreData(dataModel, keyIndex, valueIndex); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 预览返回的所有数据集,只有在编辑存储过程时才用到 |
||||
*/ |
||||
public void previewAllTable() { |
||||
if (dataModel == null) { |
||||
try { |
||||
createResults(true); |
||||
} catch (Exception e) { |
||||
return; |
||||
} |
||||
} |
||||
PreviewTablePane.previewStoreDataWithAllDs(dataModels); |
||||
} |
||||
|
||||
@Override |
||||
public String getTableDataName() { |
||||
return dsName; |
||||
} |
||||
|
||||
@Override |
||||
public TableData getTableData() { |
||||
return tableData; |
||||
} |
||||
|
||||
/** |
||||
* 是否异常 |
||||
* |
||||
* @return 是否异常 |
||||
*/ |
||||
@Override |
||||
public boolean isUnusual() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
return obj instanceof MultiResultTableDataWrapper |
||||
&& ComparatorUtils.equals(this.dsName, ((MultiResultTableDataWrapper) obj).getTableDataName()) |
||||
&& ComparatorUtils.equals(this.tableData, ((MultiResultTableDataWrapper) obj).getTableData()) |
||||
&& ComparatorUtils.equals(this.tableDataName, ((MultiResultTableDataWrapper) obj).getTableDataName()); |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue