From bedd718a8bd303205683644ff611a33214de54d4 Mon Sep 17 00:00:00 2001 From: Yvan Date: Wed, 6 Apr 2022 17:57:11 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-69169=20&&=20REPORT-69167=20frm=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E6=95=B0=E6=8D=AE=E9=9B=86=E6=9C=AA=E8=B7=9F=E9=9A=8F?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=20&&=20=E5=8D=95=E5=85=83=E6=A0=BC=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E8=BF=87=E7=A8=8B=E6=9C=AA=E8=B7=9F=E9=9A=8F=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=20=E3=80=90=E9=97=AE=E9=A2=98=E5=8E=9F=E5=9B=A0?= =?UTF-8?q?=E3=80=911.frm=E9=87=8C=E6=8E=A7=E4=BB=B6=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=B7=9F=E9=9A=8F=E5=A4=8D=E5=88=B6=E6=98=AF=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?Widget=E6=9C=89=E6=97=B6=E5=80=99=E4=BB=A3=E8=A1=A8WLayout?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=B9=8B=E5=89=8D=E5=86=99=E7=9A=84=E6=94=B6?= =?UTF-8?q?=E9=9B=86=E6=8E=A7=E4=BB=B6=E5=86=85=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91=E5=B0=B1=E6=94=B6=E9=9B=86=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=EF=BC=9B2.=E5=AD=98=E5=82=A8=E8=BF=87=E7=A8=8B?= =?UTF-8?q?=E4=B8=8D=E8=B7=9F=E9=9A=8F=E6=98=AF=E5=9B=A0=E4=B8=BA=E6=94=B6?= =?UTF-8?q?=E9=9B=86=E5=88=B0=E7=9A=84=E6=98=AF"Proc1=5FTable"=EF=BC=8C?= =?UTF-8?q?=E8=80=8C=E5=88=A4=E6=96=AD=E7=9A=84=E6=97=B6=E5=80=99=E7=94=A8?= =?UTF-8?q?=E7=9A=84"Proc1"=20=E3=80=90=E6=94=B9=E5=8A=A8=E6=80=9D?= =?UTF-8?q?=E8=B7=AF=E3=80=911.Widget=E7=9A=84=E6=94=B6=E9=9B=86=E4=B8=AD?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E8=80=83=E8=99=91=E6=8E=A7=E4=BB=B6=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=B8=83=E5=B1=80=EF=BC=9B2.=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E8=BF=87=E7=A8=8B=E7=9A=84=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E3=80=90review=E5=BB=BA=E8=AE=AE=E3=80=91?= =?UTF-8?q?=E6=97=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../paste/TableDataFollowingPasteUtils.java | 253 +++++++++++++++--- .../designer/beans/models/SelectionModel.java | 4 +- .../fr/design/mainframe/FormSelection.java | 5 +- 3 files changed, 222 insertions(+), 40 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java b/designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java index 465c0361a..5884bcbbc 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java +++ b/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 templateTableData = getCurrentTemplateTableDataWrapper(); - Map resultMap = new HashMap<>(); - for (ElementUsedTableDataProvider tableDataProvider : providers) { - Set usedTableDataNames = tableDataProvider.getElementUsedTableDataNames(); - for (String usedTableDataName : usedTableDataNames) { - if (templateTableData.containsKey(usedTableDataName)) { - resultMap.put(usedTableDataName, templateTableData.get(usedTableDataName).getTableData()); + Map templateTableData = getCurrentTemplateTableDataWrapperIncludingProcedure(); + Map tempMap = new HashMap<>(); + try { + for (ElementUsedTableDataProvider tableDataProvider : providers) { + Set 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 dealWithStoreProcedure(Map tableDataMap) { + Map resultMap = new HashMap<>(); + if (tableDataMap == null) { + return resultMap; + } + for (Map.Entry 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 dataWrapperMap = getCurrentTemplateTableDataWrapper(); + // 名称匹配时,直接返回 + if (dataWrapperMap.containsKey(tableDataName)) { + return tableDataName; + } + // 名称不匹配时,判断TableData是否一致 + for (Map.Entry 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 templateTableData = getCurrentTemplateTableDataWrapper(); - Map resultMap = new HashMap<>(); - for (Widget widget : widgets) { - collectTableDataInDictionary(templateTableData, resultMap, widget); - collectTableDataInWidgetValue(templateTableData, resultMap, widget); + Map templateTableData = getCurrentTemplateTableDataWrapperIncludingProcedure(); + Map 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 templateTableData, Map 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 templateTableData, Map 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 floatIterator = ((FormElementCase) elementCase).floatIterator(); + while (floatIterator.hasNext()) { + ElementUsedTableDataProvider floatElement = floatIterator.next(); + collectElement(floatElement); + } + } + } + + private void collectElement(ElementUsedTableDataProvider provider) { + Set 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 templateTableData, Map tempMap, Widget widget) { + List chartCollections = widget.getChartCollections(); + for (BaseChartCollection chartCollection : chartCollections) { + Set 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 templateTableData, Map 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 templateTableData, Map resultMap, Widget widget) { - if (widget instanceof DictionaryContainer) { - Set usedTableDataSets = ((DictionaryContainer) widget).getUsedTableDataSets(); - for (String usedTableDataSet : usedTableDataSets) { - if (templateTableData.containsKey(usedTableDataSet)) { - resultMap.put(usedTableDataSet, templateTableData.get(usedTableDataSet).getTableData()); + private static void collectTableDataInDictionary(Map templateTableData, Map tempMap, Widget widget) { + Form.traversalWidget(widget, new WidgetGather() { + @Override + public void dealWith(Widget widget) { + Set 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 getCurrentTemplateTableDataWrapperIncludingProcedure() { + Map templateTableDataWrapper = getCurrentTemplateTableDataWrapper(); + // 处理存储过程 + Map dataWrapperMap = DesignTableDataManager.getAllDataSetIncludingProcedure(templateTableDataWrapper); + return dataWrapperMap; } + /** + * 获取当前所有的模板数据集,不包括存储过程 + * + * @return + */ private static Map getCurrentTemplateTableDataWrapper() { TableDataSource tableDataSource = DesignTableDataManager.getEditingTableDataSource(); List> editingDataSet = DesignTableDataManager.getEditingDataSet(tableDataSource); - return editingDataSet.get(0); + Map templeteDataSet = editingDataSet.get(0); + return templeteDataSet; } } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index 6aa47474a..997af89c7 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/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(); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java b/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java index 1df1b5d2f..e7b0390e0 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java +++ b/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)); }