Browse Source

REPORT-35455 组件移除时数据集应一并移除

feature/big-screen
kerry 4 years ago
parent
commit
d12fcf3d07
  1. 11
      designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java
  2. 17
      designer-base/src/main/java/com/fr/design/data/BasicTableDataUtils.java
  3. 29
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java
  4. 25
      designer-base/src/test/java/com/fr/design/data/BasicTableDataUtilsTest.java
  5. 4
      designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java
  6. 2
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  7. 2
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java

11
designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java

@ -446,7 +446,16 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp
* @param srcName 数据集来源(比如报表块就是报表块的名称) * @param srcName 数据集来源(比如报表块就是报表块的名称)
* @param tableDataSource 数据集 * @param tableDataSource 数据集
*/ */
public Map<String, String> addTableData(String srcName, TableDataSource tableDataSource, boolean isCover) {
return new HashMap<>(0);
}
public Map<String, String> addTableData(String srcName, TableDataSource tableDataSource) { public Map<String, String> addTableData(String srcName, TableDataSource tableDataSource) {
return new HashMap<>(0); return addTableData(srcName, tableDataSource, false);
}
public void removeTableData(String sourceName) {
} }
} }

17
designer-base/src/main/java/com/fr/design/data/BasicTableDataUtils.java

@ -1,5 +1,6 @@
package com.fr.design.data; package com.fr.design.data;
import com.fr.data.TableDataSource;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -10,6 +11,7 @@ import com.fr.stable.StringUtils;
* Created by hades on 2020/4/27 * Created by hades on 2020/4/27
*/ */
public abstract class BasicTableDataUtils { public abstract class BasicTableDataUtils {
private static final String SEPARATOR = "-";
private static final int LEN = 2; private static final int LEN = 2;
@ -33,4 +35,19 @@ public abstract class BasicTableDataUtils {
} }
return false; return false;
} }
public static String getTableDataName(boolean isCover, TableDataSource tds, String tdName, String srcName, boolean isDsNameRepeaded) {
if (isCover) {
return srcName + SEPARATOR + tdName;
}
if (tds.getTableData(tdName) != null || isDsNameRepeaded) {//如果有同名的就拼上来源名称
tdName = srcName + SEPARATOR + tdName;
}
int i = 0;
while (tds.getTableData(tdName) != null) {
i++;//如果拼上名字后依然已经存在就加编号
tdName += i;
}
return tdName;
}
} }

29
designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java

@ -9,6 +9,7 @@ import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.UpdateAction; import com.fr.design.actions.UpdateAction;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.data.BasicTableDataTreePane; import com.fr.design.data.BasicTableDataTreePane;
import com.fr.design.data.BasicTableDataUtils;
import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.tabledata.StoreProcedureWorkerListener; import com.fr.design.data.tabledata.StoreProcedureWorkerListener;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
@ -339,10 +340,11 @@ public class TableDataTreePane extends BasicTableDataTreePane {
/** /**
* 合并数据集 * 合并数据集
* @param srcName 数据集来源(比如报表块就是报表块的名称) *
* @param srcName 数据集来源(比如报表块就是报表块的名称)
* @param tableDataSource 数据集 * @param tableDataSource 数据集
*/ */
public Map<String, String> addTableData(String srcName, TableDataSource tableDataSource) { public Map<String, String> addTableData(String srcName, TableDataSource tableDataSource, boolean isCover) {
Map<String, String> tdNameMap = new HashMap<>(); Map<String, String> tdNameMap = new HashMap<>();
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook()); allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER); DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
@ -352,14 +354,8 @@ public class TableDataTreePane extends BasicTableDataTreePane {
String tdName = (String) tdIterator.next(); String tdName = (String) tdIterator.next();
String oldName = tdName; String oldName = tdName;
TableData td = tableDataSource.getTableData(tdName); TableData td = tableDataSource.getTableData(tdName);
if (tds.getTableData(tdName) != null || isDsNameRepeaded(tdName)) {//如果有同名的就拼上来源名称 boolean isDsNameRepeaded = isDsNameRepeaded(tdName);
tdName = srcName + tdName; tdName = BasicTableDataUtils.getTableDataName(isCover, tds, tdName, srcName, isDsNameRepeaded);
}
int i = 0;
while (tds.getTableData(tdName) != null) {
i++;//如果拼上名字后依然已经存在就加编号
tdName += i;
}
tds.putTableData(tdName, td); tds.putTableData(tdName, td);
if (!ComparatorUtils.equals(oldName, tdName)) { if (!ComparatorUtils.equals(oldName, tdName)) {
tdNameMap.put(oldName, tdName); tdNameMap.put(oldName, tdName);
@ -367,8 +363,19 @@ public class TableDataTreePane extends BasicTableDataTreePane {
} }
tc.parameterChanged(); tc.parameterChanged();
dataTree.refresh(); dataTree.refresh();
return Collections.unmodifiableMap(tdNameMap); return Collections.unmodifiableMap(tdNameMap);
} }
@Override
public void removeTableData(String sourceName) {
TableDataSource tds = tc.getBook();
tds.removeTableData(sourceName);
dataTree.refresh();
}
public void addDataPane(final AbstractTableDataPane<?> uPanel, String paneName) { public void addDataPane(final AbstractTableDataPane<?> uPanel, String paneName) {
final NamePane nPanel = uPanel.asNamePane(); final NamePane nPanel = uPanel.asNamePane();
nPanel.setObjectName(paneName); nPanel.setObjectName(paneName);

25
designer-base/src/test/java/com/fr/design/data/BasicTableDataUtilsTest.java

@ -1,6 +1,9 @@
package com.fr.design.data; package com.fr.design.data;
import com.fr.base.TableData;
import com.fr.data.TableDataSource;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -41,4 +44,26 @@ public class BasicTableDataUtilsTest extends TestCase {
Assert.assertFalse(result12); Assert.assertFalse(result12);
} }
@Test
public void testGetTableDataName() {
TableDataSource source = EasyMock.mock(TableDataSource.class);
TableData tableData = EasyMock.mock(TableData.class);
EasyMock.expect(source.getTableData("ds1")).andReturn(tableData).anyTimes();
EasyMock.expect(source.getTableData("test-ds1")).andReturn(tableData).anyTimes();
EasyMock.expect(source.getTableData("test-ds11")).andReturn(null).anyTimes();
EasyMock.replay(source, tableData);
Assert.assertEquals("test-ds1", BasicTableDataUtils.getTableDataName(true, source, "ds1", "test", false));
Assert.assertEquals("test-ds11", BasicTableDataUtils.getTableDataName(false, source, "ds1", "test", false));
source = EasyMock.mock(TableDataSource.class);
EasyMock.expect(source.getTableData("ds1")).andReturn(null).anyTimes();
EasyMock.expect(source.getTableData("test-ds1")).andReturn(null).anyTimes();
EasyMock.replay(source);
Assert.assertEquals("test-ds1", BasicTableDataUtils.getTableDataName(true, source, "ds1", "test", false));
Assert.assertEquals("ds1", BasicTableDataUtils.getTableDataName(false, source, "ds1", "test", false));
Assert.assertEquals("test-ds1", BasicTableDataUtils.getTableDataName(false, source, "ds1", "test", true));
}
} }

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

@ -306,12 +306,12 @@ public class SelectionModel {
// 清除被选中的组件 // 清除被选中的组件
selection.reset(); selection.reset();
} }
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED);
setSelectedCreator(isInPara ? designer.getParaComponent() : designer.getRootComponent());
setSelectedCreator(isInPara ? designer.getParaComponent() : designer.getRootComponent());
// 触发事件 // 触发事件
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED);
designer.repaint(); designer.repaint();
} }
} }

2
designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java

@ -298,7 +298,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
@Override @Override
public JComponent createToolPane(BaseJForm jform, FormDesigner formEditor) { public JComponent createToolPane(BaseJForm jform, FormDesigner formEditor) {
if (!DesignerMode.isAuthorityEditing()) { if (!DesignerMode.isAuthorityEditing()) {
if (isDedicateContainer()) { if (isDedicateContainer() && this.getComponentCount() > 0) {
// 图表块和报表块由于控件树处不显示,但对应的属性表要显示,此处处理下 // 图表块和报表块由于控件树处不显示,但对应的属性表要显示,此处处理下
XCreator child = ((XLayoutContainer) this).getXCreator(0); XCreator child = ((XLayoutContainer) this).getXCreator(0);
return child.createToolPane(jform, formEditor); return child.createToolPane(jform, formEditor);

2
designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java

@ -105,7 +105,7 @@ public class FormCreatorDropTarget extends DropTarget {
SharableEditorProvider sharableEditor = ShareLoader.getLoader().getSharedElCaseEditorById(shareId); SharableEditorProvider sharableEditor = ShareLoader.getLoader().getSharedElCaseEditorById(shareId);
SharableWidgetProvider bindInfo = ShareLoader.getLoader().getElCaseBindInfoById(shareId); SharableWidgetProvider bindInfo = ShareLoader.getLoader().getElCaseBindInfoById(shareId);
if (sharableEditor != null && bindInfo != null) { if (sharableEditor != null && bindInfo != null) {
Map<String, String> tdNameMap = TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()).addTableData(bindInfo.getName(), sharableEditor.getTableDataSource()); Map<String, String> tdNameMap = TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()).addTableData(bindInfo.getName(), sharableEditor.getTableDataSource(), true);
//合并数据集之后,可能会有数据集名称变化,做一下联动 //合并数据集之后,可能会有数据集名称变化,做一下联动
//共享的组件拿的时候都是克隆的,这边改拖拽中克隆的对象而非新克隆对象,上面这个新克隆的对象只是为了拿数据集 //共享的组件拿的时候都是克隆的,这边改拖拽中克隆的对象而非新克隆对象,上面这个新克隆的对象只是为了拿数据集
for (Map.Entry<String, String> entry : tdNameMap.entrySet()) { for (Map.Entry<String, String> entry : tdNameMap.entrySet()) {

Loading…
Cancel
Save