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 c99e057663..45897f7ac0 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 4875a28163..afc28e59f9 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 5a79399873..7569491e99 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 85bc48ebb1..ffeb9e5f62 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 0000000000..98871158d3 --- /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 0000000000..2435f363fc --- /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