From e548a8301033a7fca009ff76ebe5bd49ea9e4394 Mon Sep 17 00:00:00 2001 From: Yvan Date: Wed, 23 Mar 2022 17:42:29 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-66457=20=E5=8E=9F=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E7=AE=A1=E7=90=86=E4=BC=98=E5=8C=96=201.=20=E8=A1=A5?= =?UTF-8?q?=E5=85=85test=202.=20=E5=88=A0=E6=8E=89=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E4=B8=8D=E8=80=83=E8=99=91=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E4=B8=AD=E7=9A=84=E6=95=B0=E6=8D=AE=E9=9B=86=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E9=97=AE=E9=A2=98=203.=20=E5=88=A0=E6=8E=89=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=97=A5=E5=BF=97=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datapane/TableDataTreePane.java | 2 +- .../search/TableDataTreeSearchManager.java | 1 - .../searcher/TableDataTreeSearcher.java | 23 -- .../paste/TableDataFollowingPasteUtils.java | 56 ++++- .../clip/TableDataTreeClipboardTest.java | 43 ++++ .../TableDataFollowingPasteUtilsTest.java | 201 ++++++++++++++++++ 6 files changed, 294 insertions(+), 32 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboardTest.java create mode 100644 designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java index c99e05766..45897f7ac 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java @@ -1018,7 +1018,7 @@ public class TableDataTreePane extends BasicTableDataTreePane { FineLoggerFactory.getLogger().error("Table Data to remove is null or not selected"); return; } - CheckBoxList checkBoxList = new CheckBoxList(selectedNameObjects, CheckBoxList.SelectedState.ALL, "全选"); + CheckBoxList checkBoxList = new CheckBoxList(selectedNameObjects, CheckBoxList.SelectedState.ALL, Toolkit.i18nText("Fine-Design_Basic_Remove_All_Selected")); UIScrollPane scrollPane = new UIScrollPane(checkBoxList); BasicPane basicPane = new BasicPane() { @Override diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java index 4875a2816..afc28e59f 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java @@ -137,7 +137,6 @@ public class TableDataTreeSearchManager { setTreeSearchStatus(TreeSearchStatus.SEARCHING); rendererHelper.replaceTreeRenderer(getCurrentTableDataTree(), searchText); count = new AtomicInteger(treeSearcher.getNotCalculatedSetsSize()); - System.out.println("count = " + count.intValue()); // 计时开始 TableDataSearchTimer.getInstance().startClock(); treeSearcher.startSearch(searchText); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java index 5a7939987..7569491e9 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java @@ -39,29 +39,6 @@ public class TableDataTreeSearcher implements TreeSearcher { private final Set canExpandSets = new HashSet<>(); public TableDataTreeSearcher() { - initListener(); - } - - private void initListener() { - DesignTableDataManager.addDsChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - allWrappers.keySet().stream().filter(DesignTableDataManager::isDsNameChanged).forEach(new Consumer() { - @Override - public void accept(String key) { - TableDataWrapper oldWrapper = allWrappers.remove(key); - calculatedSets.remove(key); - notCalculatedSets.remove(key); - matchSets.remove(key); - canExpandSets.remove(key); - String newName = DesignTableDataManager.getChangedDsNameByOldDsName(key); - TableDataWrapper newWrapper = DesignTableDataManager.getAllEditingDataSet(DesignTableDataManager.getEditingTableDataSource()).get(newName); - allWrappers.put(newName, newWrapper); - notCalculatedSets.add(newName); - } - }); - } - }); } public boolean isMatchSetsEmpty() { 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 85bc48ebb..ffeb9e5f6 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 @@ -9,8 +9,12 @@ 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.data.DataBinding; +import com.fr.form.data.DataTableConfig; +import com.fr.form.ui.DataControl; import com.fr.form.ui.DictionaryContainer; import com.fr.form.ui.Widget; +import com.fr.form.ui.concept.data.ValueInitializer; import com.fr.report.cell.tabledata.ElementUsedTableDataProvider; import java.util.HashMap; @@ -86,16 +90,54 @@ public class TableDataFollowingPasteUtils { Map templateTableData = getCurrentTemplateTableDataWrapper(); Map resultMap = new HashMap<>(); for (Widget widget : widgets) { - if (widget instanceof DictionaryContainer) { - Set usedTableDataSets = ((DictionaryContainer) widget).getUsedTableDataSets(); - for (String usedTableDataSet : usedTableDataSets) { - if (templateTableData.containsKey(usedTableDataSet)) { - resultMap.put(usedTableDataSet, templateTableData.get(usedTableDataSet).getTableData()); - } + collectTableDataInDictionary(templateTableData, resultMap, widget); + collectTableDataInWidgetValue(templateTableData, resultMap, widget); + } + return resultMap; + } + + /** + * 收集控件值中的TableData + * + * @param templateTableData + * @param resultMap + * @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()); + } + } + if (value instanceof DataTableConfig) { + String tableDataName = ((DataTableConfig) value).getTableDataName(); + if (templateTableData.containsKey(tableDataName)) { + resultMap.put(tableDataName, templateTableData.get(tableDataName).getTableData()); + } + } + } + } + + /** + * 收集控件-数据字典中的TableData + * + * @param templateTableData + * @param resultMap + * @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()); } } } - return resultMap; } private static Map getCurrentTemplateTableDataWrapper() { diff --git a/designer-base/src/test/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboardTest.java b/designer-base/src/test/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboardTest.java new file mode 100644 index 000000000..98871158d --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboardTest.java @@ -0,0 +1,43 @@ +package com.fr.design.data.datapane.management.clip; + +import com.fr.data.impl.EmbeddedTableData; +import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; +import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; +import junit.framework.TestCase; +import org.junit.Assert; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Yvan + */ +public class TableDataTreeClipboardTest extends TestCase { + + public void testAddAndTake() { + Map testMap = new HashMap<>(); + testMap.put("ds1", new TemplateTableDataWrapper(new EmbeddedTableData())); + testMap.put("ds2", new TemplateTableDataWrapper(new EmbeddedTableData())); + + Map anotherTestMap = new HashMap<>(); + anotherTestMap.put("ds3", new TemplateTableDataWrapper(new EmbeddedTableData())); + + Map clip; + TableDataTreeClipboard.getInstance().addToClip(testMap); + clip = TableDataTreeClipboard.getInstance().takeFromClip(); + Assert.assertEquals(2, clip.size()); + Assert.assertTrue(clip.containsKey("ds1")); + Assert.assertTrue(clip.containsKey("ds2")); + + // 验证多次取出 + clip = TableDataTreeClipboard.getInstance().takeFromClip(); + Assert.assertEquals(2, clip.size()); + Assert.assertTrue(clip.containsKey("ds1")); + Assert.assertTrue(clip.containsKey("ds2")); + + TableDataTreeClipboard.getInstance().addToClip(anotherTestMap); + clip = TableDataTreeClipboard.getInstance().takeFromClip(); + Assert.assertEquals(1, clip.size()); + Assert.assertTrue(clip.containsKey("ds3")); + } +} \ No newline at end of file diff --git a/designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java b/designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java new file mode 100644 index 000000000..2435f363f --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtilsTest.java @@ -0,0 +1,201 @@ +package com.fr.design.data.tabledata.paste; + +import com.fr.base.TableData; +import com.fr.data.Dictionary; +import com.fr.data.TableDataSource; +import com.fr.data.impl.EmbeddedTableData; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; +import com.fr.form.data.DataBinding; +import com.fr.form.data.DataTableConfig; +import com.fr.form.ui.AbstractDataControl; +import com.fr.form.ui.DictionaryContainer; +import com.fr.form.ui.Widget; +import com.fr.form.ui.WidgetValue; +import com.fr.report.cell.tabledata.ElementUsedTableDataProvider; +import com.fr.script.Calculator; +import com.fr.stable.script.CalculatorProvider; +import com.fr.stable.script.NameSpace; +import com.fr.web.core.TemplateSessionIDInfo; +import junit.framework.TestCase; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Yvan + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({DesignTableDataManager.class}) +public class TableDataFollowingPasteUtilsTest extends TestCase { + + @Before + public void beforeTest() { + Map templateDataMap = new LinkedHashMap(); + Map serverDataMap = new LinkedHashMap(); + Map storeProcedureMap = new LinkedHashMap(); + templateDataMap.put("ds1", new TemplateTableDataWrapper(new EmbeddedTableData())); + templateDataMap.put("ds2", new TemplateTableDataWrapper(new EmbeddedTableData())); + templateDataMap.put("ds3", new TemplateTableDataWrapper(new EmbeddedTableData())); + templateDataMap.put("ds4", new TemplateTableDataWrapper(new EmbeddedTableData())); + templateDataMap.put("ds5", new TemplateTableDataWrapper(new EmbeddedTableData())); + + List> list = new ArrayList>(); + list.add(templateDataMap); + list.add(serverDataMap); + list.add(storeProcedureMap); + + TableDataSource tableDataSource = EasyMock.mock(TableDataSource.class); + PowerMock.mockStatic(DesignTableDataManager.class); + EasyMock.expect(DesignTableDataManager.getEditingTableDataSource()).andReturn(tableDataSource).anyTimes(); + EasyMock.expect(DesignTableDataManager.getEditingDataSet(tableDataSource)).andReturn(list).anyTimes(); + PowerMock.replayAll(); + } + + public void testTransferProvider2TableDataMap() { + ElementUsedTableDataProvider[] providers = generateElementUsedTableDataProvider(); + Map tableDataMap = TableDataFollowingPasteUtils.transferProvider2TableDataMap(providers); + Assert.assertEquals(2, tableDataMap.size()); + Assert.assertTrue(tableDataMap.containsKey("ds1")); + Assert.assertTrue(tableDataMap.containsKey("ds2")); + } + + private ElementUsedTableDataProvider[] generateElementUsedTableDataProvider() { + ElementUsedTableDataProvider elementUsedTableDataProvider1 = new ElementUsedTableDataProvider() { + @Override + public Set getElementUsedTableDataNames() { + Set set = new HashSet<>(); + set.add("ds1"); + return set; + } + }; + ElementUsedTableDataProvider elementUsedTableDataProvider2 = new ElementUsedTableDataProvider() { + @Override + public Set getElementUsedTableDataNames() { + Set set = new HashSet<>(); + set.add("ds2"); + return set; + } + }; + return new ElementUsedTableDataProvider[]{elementUsedTableDataProvider1, elementUsedTableDataProvider2}; + } + + public void testTransferWidgetArray2TableDataMap() { + Widget[] widgets = generateWidgetArray(); + Map tableDataMap = TableDataFollowingPasteUtils.transferWidgetArray2TableDataMap(widgets); + Assert.assertEquals(3, tableDataMap.size()); + Assert.assertTrue(tableDataMap.containsKey("ds3")); + Assert.assertTrue(tableDataMap.containsKey("ds4")); + Assert.assertTrue(tableDataMap.containsKey("ds5")); + } + + private Widget[] generateWidgetArray() { + Set set = new HashSet<>(); + set.add("ds3"); + MockWidget widget1 = EasyMock.mock(MockWidget.class); + EasyMock.expect(widget1.getUsedTableDataSets()).andReturn(set).anyTimes(); + EasyMock.replay(widget1); + + DataBinding dataBinding = new DataBinding("ds4", ""); + WidgetValue widgetValue2 = new WidgetValue(); + widgetValue2.setValue(dataBinding); + AbstractDataControl widget2 = EasyMock.mock(AbstractDataControl.class); + EasyMock.expect(widget2.getWidgetValue()).andReturn(widgetValue2).anyTimes(); + EasyMock.replay(widget2); + + DataTableConfig dataTableConfig = EasyMock.mock(DataTableConfig.class); + EasyMock.expect(dataTableConfig.getTableDataName()).andReturn("ds5").anyTimes(); + WidgetValue widgetValue3 = new WidgetValue(); + widgetValue3.setValue(dataTableConfig); + AbstractDataControl widget3 = EasyMock.mock(AbstractDataControl.class); + EasyMock.expect(widget3.getWidgetValue()).andReturn(widgetValue3).anyTimes(); + EasyMock.replay(dataTableConfig, widget3); + + Widget[] widgets = new Widget[3]; + widgets[0] = widget1; + widgets[1] = widget2; + widgets[2] = widget3; + return widgets; + } + + private class MockWidget extends Widget implements DictionaryContainer { + + @Override + public String[] supportedEvents() { + return new String[0]; + } + + @Override + public void setDictionary(Dictionary model) { + + } + + @Override + public Dictionary getDictionary() { + return null; + } + + @Override + public Object getViewValue(Object value, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req) { + return null; + } + + @Override + public Object getModuleValue(Object text, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req) { + return null; + } + + @Override + public Object getViewValue(Object value, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req, NameSpace dependenceNameSpace) { + return null; + } + + @Override + public Object getModuleValue(Object text, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req, NameSpace dependenceNameSpace) { + return null; + } + + @Override + public boolean isValueAllInDictionary(Object value, Calculator c, TemplateSessionIDInfo sessionIDInfor, HttpServletRequest req, NameSpace dependenceNameSpace) { + return false; + } + + @Override + public String getXType() { + return null; + } + + @Override + public boolean isEditor() { + return false; + } + + @Override + public void setDependenceMap(Map dependenceMap) { + + } + + @Override + public Map getDependenceMap() { + return null; + } + + @Override + public String[] dependence(CalculatorProvider calculatorProvider) { + return new String[0]; + } + } +} \ No newline at end of file