Browse Source

REPORT-69169 && REPORT-69167 frm控件数据集未跟随复制 && 单元格存储过程未跟随复制

【问题原因】1.frm里控件没有跟随复制是因为Widget有时候代表WLayout,用之前写的收集控件内数据集的逻辑就收集不到;2.存储过程不跟随是因为收集到的是"Proc1_Table",而判断的时候用的"Proc1"
【改动思路】1.Widget的收集中同时考虑控件以及布局;2.处理存储过程的名称问题
【review建议】无
bugfix/11.0
Yvan 2 years ago
parent
commit
bedd718a8b
  1. 253
      designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java
  2. 4
      designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java
  3. 5
      designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java

253
designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java

@ -1,6 +1,7 @@
package com.fr.design.data.tabledata.paste;
import com.fr.base.TableData;
import com.fr.base.chart.BaseChartCollection;
import com.fr.data.TableDataSource;
import com.fr.design.DesignModelAdapter;
import com.fr.design.data.DesignTableDataManager;
@ -9,17 +10,26 @@ import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper;
import com.fr.form.FormElementCaseProvider;
import com.fr.form.data.DataBinding;
import com.fr.form.data.DataTableConfig;
import com.fr.form.main.Form;
import com.fr.form.main.WidgetGather;
import com.fr.form.ui.DataControl;
import com.fr.form.ui.DictionaryContainer;
import com.fr.form.ui.ElementCaseEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.concept.data.ValueInitializer;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.report.cell.FloatElement;
import com.fr.report.cell.tabledata.ElementUsedTableDataProvider;
import com.fr.report.worksheet.FormElementCase;
import com.fr.stable.StringUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -31,6 +41,8 @@ import java.util.Set;
*/
public class TableDataFollowingPasteUtils {
private static final String UNDERLINE = "_";
/**
* 粘贴所有Map中的tabledata到当前模板
*
@ -73,19 +85,78 @@ public class TableDataFollowingPasteUtils {
return new HashMap<>();
}
// 获取当前的所有模板数据集
Map<String, TableDataWrapper> templateTableData = getCurrentTemplateTableDataWrapper();
Map<String, TableData> resultMap = new HashMap<>();
for (ElementUsedTableDataProvider tableDataProvider : providers) {
Set<String> usedTableDataNames = tableDataProvider.getElementUsedTableDataNames();
for (String usedTableDataName : usedTableDataNames) {
if (templateTableData.containsKey(usedTableDataName)) {
resultMap.put(usedTableDataName, templateTableData.get(usedTableDataName).getTableData());
Map<String, TableDataWrapper> templateTableData = getCurrentTemplateTableDataWrapperIncludingProcedure();
Map<String, TableData> tempMap = new HashMap<>();
try {
for (ElementUsedTableDataProvider tableDataProvider : providers) {
Set<String> usedTableDataNames = tableDataProvider.getElementUsedTableDataNames();
for (String usedTableDataName : usedTableDataNames) {
if (templateTableData.containsKey(usedTableDataName)) {
tempMap.put(usedTableDataName, templateTableData.get(usedTableDataName).getTableData());
}
}
}
// 处理存储过程名称问题
return dealWithStoreProcedure(tempMap);
} catch (Exception e) {
FineLoggerFactory.getLogger().error("transfer widget tabledata failed", e);
}
return new HashMap<>();
}
/**
* 处理结果集将结果集中的存储过程子表替换为原本的存储过程否则跟随粘贴过去的存储过程名称有问题
*
* @param tableDataMap
*/
public static Map<String, TableData> dealWithStoreProcedure(Map<String, TableData> tableDataMap) {
Map<String, TableData> resultMap = new HashMap<>();
if (tableDataMap == null) {
return resultMap;
}
for (Map.Entry<String, TableData> result : tableDataMap.entrySet()) {
String tableDataName = result.getKey();
TableData tableData = result.getValue();
// 判断名称中存在"_"的
if (tableDataName.contains(UNDERLINE)) {
String matchedName = matchTableDataName(tableDataName, tableData);
resultMap.put(matchedName, tableData);
} else {
resultMap.put(tableDataName, tableData);
}
}
return resultMap;
}
/**
* 存储过程子表名称匹配其存储过程数据集名称其余模板数据集名称不变
*
* @param tableDataName 待匹配的数据集名称
* @param tableData
* @return
*/
private static String matchTableDataName(String tableDataName, TableData tableData) {
if (tableDataName == null) {
return null;
}
// 获取不包括存储过程子表的所有TableDataMap
Map<String, TableDataWrapper> dataWrapperMap = getCurrentTemplateTableDataWrapper();
// 名称匹配时,直接返回
if (dataWrapperMap.containsKey(tableDataName)) {
return tableDataName;
}
// 名称不匹配时,判断TableData是否一致
for (Map.Entry<String, TableDataWrapper> dataWrapperEntry : dataWrapperMap.entrySet()) {
String tdName = dataWrapperEntry.getKey();
TableData td = dataWrapperEntry.getValue().getTableData();
if (ComparatorUtils.equals(td, tableData)) {
return tdName;
}
}
return tableDataName;
}
/**
* 提取控件内使用的数据集转化成Map返回
*
@ -97,63 +168,173 @@ public class TableDataFollowingPasteUtils {
return new HashMap<>();
}
// 获取当前的所有模板数据集
Map<String, TableDataWrapper> templateTableData = getCurrentTemplateTableDataWrapper();
Map<String, TableData> resultMap = new HashMap<>();
for (Widget widget : widgets) {
collectTableDataInDictionary(templateTableData, resultMap, widget);
collectTableDataInWidgetValue(templateTableData, resultMap, widget);
Map<String, TableDataWrapper> templateTableData = getCurrentTemplateTableDataWrapperIncludingProcedure();
Map<String, TableData> tempMap = new HashMap<>();
try {
for (Widget widget : widgets) {
// widget这个接口太大了,布局和子控件互相嵌套,所以只能分情况一个个收集
collectTableDataInDictionary(templateTableData, tempMap, widget);
collectTableDataInWidgetValue(templateTableData, tempMap, widget);
collectTableDataInChartCollection(templateTableData, tempMap, widget);
collectTableDataInElementCaseEditor(templateTableData, tempMap, widget);
}
// 处理存储过程名称问题
return dealWithStoreProcedure(tempMap);
} catch (Exception e) {
FineLoggerFactory.getLogger().error("transfer widget tabledata failed", e);
}
return resultMap;
return new HashMap<>();
}
/**
* 收集控件值中的TableData
* 收集控件-报表块中使用的数据集
*
* @param templateTableData
* @param resultMap
* @param tempMap
* @param widget
*/
private static void collectTableDataInWidgetValue(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> resultMap, Widget widget) {
if (widget instanceof DataControl && ((DataControl) widget).getWidgetValue() != null) {
ValueInitializer widgetValue = ((DataControl) widget).getWidgetValue();
Object value = widgetValue.getValue();
if (value instanceof DataBinding) {
String dataSourceName = ((DataBinding) value).getDataSourceName();
if (templateTableData.containsKey(dataSourceName)) {
resultMap.put(dataSourceName, templateTableData.get(dataSourceName).getTableData());
private static void collectTableDataInElementCaseEditor(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> tempMap, Widget widget) {
Form.traversalWidget(widget, new WidgetGather() {
@Override
public void dealWith(Widget widget) {
ElementCaseEditor elementCaseEditor = (ElementCaseEditor) widget;
FormElementCaseProvider elementCase = elementCaseEditor.getElementCase();
if (elementCase != null) {
// 普通单元格
Iterator cellIterator = elementCase.cellIterator();
while (cellIterator.hasNext()) {
ElementUsedTableDataProvider cellElement = (ElementUsedTableDataProvider) cellIterator.next();
collectElement(cellElement);
}
// 悬浮元素
Iterator<FloatElement> floatIterator = ((FormElementCase) elementCase).floatIterator();
while (floatIterator.hasNext()) {
ElementUsedTableDataProvider floatElement = floatIterator.next();
collectElement(floatElement);
}
}
}
private void collectElement(ElementUsedTableDataProvider provider) {
Set<String> usedTableDataNames = provider.getElementUsedTableDataNames();
for (String usedTableDataName : usedTableDataNames) {
if (templateTableData.containsKey(usedTableDataName)) {
tempMap.put(usedTableDataName, templateTableData.get(usedTableDataName).getTableData());
}
}
}
if (value instanceof DataTableConfig) {
String tableDataName = ((DataTableConfig) value).getTableDataName();
if (templateTableData.containsKey(tableDataName)) {
resultMap.put(tableDataName, templateTableData.get(tableDataName).getTableData());
@Override
public boolean dealWithAllCards() {
return true;
}
}, ElementCaseEditor.class);
}
/**
* 收集控件-图表中的TableData
*
* @param templateTableData
* @param tempMap
* @param widget
*/
private static void collectTableDataInChartCollection(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> tempMap, Widget widget) {
List<BaseChartCollection> chartCollections = widget.getChartCollections();
for (BaseChartCollection chartCollection : chartCollections) {
Set<String> dataSetNames = chartCollection.getDataSetNames();
for (String dataSetName : dataSetNames) {
if (templateTableData.containsKey(dataSetName)) {
tempMap.put(dataSetName, templateTableData.get(dataSetName).getTableData());
}
}
}
}
/**
* 收集控件值中的TableData
*
* @param templateTableData
* @param tempMap
* @param widget
*/
private static void collectTableDataInWidgetValue(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> tempMap, Widget widget) {
Form.traversalWidget(widget, new WidgetGather() {
@Override
public void dealWith(Widget widget) {
if (((DataControl) widget).getWidgetValue() != null) {
ValueInitializer widgetValue = ((DataControl) widget).getWidgetValue();
Object value = widgetValue.getValue();
if (value instanceof DataBinding) {
String dataSourceName = ((DataBinding) value).getDataSourceName();
if (templateTableData.containsKey(dataSourceName)) {
tempMap.put(dataSourceName, templateTableData.get(dataSourceName).getTableData());
}
}
if (value instanceof DataTableConfig) {
String tableDataName = ((DataTableConfig) value).getTableDataName();
if (templateTableData.containsKey(tableDataName)) {
tempMap.put(tableDataName, templateTableData.get(tableDataName).getTableData());
}
}
}
}
@Override
public boolean dealWithAllCards() {
return true;
}
}, DataControl.class);
}
/**
* 收集控件-数据字典中的TableData
*
* @param templateTableData
* @param resultMap
* @param tempMap
* @param widget
*/
private static void collectTableDataInDictionary(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> resultMap, Widget widget) {
if (widget instanceof DictionaryContainer) {
Set<String> usedTableDataSets = ((DictionaryContainer) widget).getUsedTableDataSets();
for (String usedTableDataSet : usedTableDataSets) {
if (templateTableData.containsKey(usedTableDataSet)) {
resultMap.put(usedTableDataSet, templateTableData.get(usedTableDataSet).getTableData());
private static void collectTableDataInDictionary(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> tempMap, Widget widget) {
Form.traversalWidget(widget, new WidgetGather() {
@Override
public void dealWith(Widget widget) {
Set<String> usedTableDataSets = ((DictionaryContainer) widget).getUsedTableDataSets();
for (String usedTableDataSet : usedTableDataSets) {
if (templateTableData.containsKey(usedTableDataSet)) {
tempMap.put(usedTableDataSet, templateTableData.get(usedTableDataSet).getTableData());
}
}
}
}
@Override
public boolean dealWithAllCards() {
return true;
}
}, DictionaryContainer.class);
}
/**
* 获取当前所有的模板数据集包括存储过程
*
* @return
*/
private static Map<String, TableDataWrapper> getCurrentTemplateTableDataWrapperIncludingProcedure() {
Map<String, TableDataWrapper> templateTableDataWrapper = getCurrentTemplateTableDataWrapper();
// 处理存储过程
Map<String, TableDataWrapper> dataWrapperMap = DesignTableDataManager.getAllDataSetIncludingProcedure(templateTableDataWrapper);
return dataWrapperMap;
}
/**
* 获取当前所有的模板数据集不包括存储过程
*
* @return
*/
private static Map<String, TableDataWrapper> getCurrentTemplateTableDataWrapper() {
TableDataSource tableDataSource = DesignTableDataManager.getEditingTableDataSource();
List<Map<String, TableDataWrapper>> editingDataSet = DesignTableDataManager.getEditingDataSet(tableDataSource);
return editingDataSet.get(0);
Map<String, TableDataWrapper> templeteDataSet = editingDataSet.get(0);
return templeteDataSet;
}
}

4
designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java

@ -188,9 +188,9 @@ public class SelectionModel {
} else {
//已选
selectedPaste();
// 粘贴剪切板控件中的数据集
pasteTableDataFromWidget(pasteSelection);
}
// 粘贴剪切板控件中的数据集
pasteTableDataFromWidget(pasteSelection);
} else {
Toolkit.getDefaultToolkit().beep();
}

5
designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java

@ -53,6 +53,7 @@ public class FormSelection {
((XWCardMainBorderLayout) xCreator).setShowOuterShadowBorder(false);
}
selection.clear();
selectionUsedTablaData.clear();
}
/**
@ -393,7 +394,7 @@ public class FormSelection {
XCreator creator = XCreatorUtils.createXCreator(clone);
creator.setBounds(root.getBounds());
clipBoard.selection.add(creator);
// 复制时,添加剪切组件的数据集到usedTablaDataMap中
// 复制时,添加复制组件的数据集到usedTablaDataMap中
clipBoard.addUsedTablaData(clone);
} catch (CloneNotSupportedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
@ -401,7 +402,7 @@ public class FormSelection {
}
}
public void addUsedTablaData(Widget... widget) {
private void addUsedTablaData(Widget widget) {
this.selectionUsedTablaData.putAll(TableDataFollowingPasteUtils.transferWidgetArray2TableDataMap(widget));
}

Loading…
Cancel
Save