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. 53
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java
  4. 27
      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. 16
      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 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) {
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;
import com.fr.data.TableDataSource;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.i18n.Toolkit;
import com.fr.stable.StringUtils;
@ -10,6 +11,7 @@ import com.fr.stable.StringUtils;
* Created by hades on 2020/4/27
*/
public abstract class BasicTableDataUtils {
private static final String SEPARATOR = "-";
private static final int LEN = 2;
@ -33,4 +35,19 @@ public abstract class BasicTableDataUtils {
}
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;
}
}

53
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.constants.UIConstants;
import com.fr.design.data.BasicTableDataTreePane;
import com.fr.design.data.BasicTableDataUtils;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.tabledata.StoreProcedureWorkerListener;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
@ -59,7 +60,7 @@ import java.util.Map;
public class TableDataTreePane extends BasicTableDataTreePane {
private static TableDataTreePane singleton = new TableDataTreePane();
public static final int PLUGIN_LISTENER_PRIORITY = 1;
public synchronized static BasicTableDataTreePane getInstance(DesignModelAdapter<?, ?> tc) {
@ -96,10 +97,10 @@ public class TableDataTreePane extends BasicTableDataTreePane {
addMenuDef.setIconPath(IconPathConstants.ADD_POPMENU_ICON_PATH);
createAddMenuDef();
// 创建插件监听
createPluginListener();
editAction = new EditAction();
removeAction = new RemoveAction();
previewTableDataAction = new PreviewTableDataAction(dataTree);
@ -139,27 +140,27 @@ public class TableDataTreePane extends BasicTableDataTreePane {
new TableDataTreeDragSource(dataTree, DnDConstants.ACTION_COPY);
checkButtonEnabled();
}
private void createPluginListener() {
//菜单栏监听
GeneralContext.listenPluginRunningChanged(new PluginEventListener(PLUGIN_LISTENER_PRIORITY) {
@Override
public void on(PluginEvent event) {
addMenuDef.clearShortCuts();
createAddMenuDef();
}
}, new PluginFilter() {
@Override
public boolean accept(PluginContext context) {
return context.contain(PluginModule.ExtraDesign);
}
});
//监听数据集插件
GeneralContext.listenPluginRunningChanged(new PluginEventListener() {
@Override
@ -188,8 +189,8 @@ public class TableDataTreePane extends BasicTableDataTreePane {
}
});
}
protected void checkButtonEnabled() {
super.checkButtonEnabled(editAction, previewTableDataAction, removeAction, op, dataTree);
}
@ -339,10 +340,11 @@ public class TableDataTreePane extends BasicTableDataTreePane {
/**
* 合并数据集
* @param srcName 数据集来源(比如报表块就是报表块的名称)
*
* @param srcName 数据集来源(比如报表块就是报表块的名称)
* @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<>();
allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook());
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
@ -352,14 +354,8 @@ public class TableDataTreePane extends BasicTableDataTreePane {
String tdName = (String) tdIterator.next();
String oldName = tdName;
TableData td = tableDataSource.getTableData(tdName);
if (tds.getTableData(tdName) != null || isDsNameRepeaded(tdName)) {//如果有同名的就拼上来源名称
tdName = srcName + tdName;
}
int i = 0;
while (tds.getTableData(tdName) != null) {
i++;//如果拼上名字后依然已经存在就加编号
tdName += i;
}
boolean isDsNameRepeaded = isDsNameRepeaded(tdName);
tdName = BasicTableDataUtils.getTableDataName(isCover, tds, tdName, srcName, isDsNameRepeaded);
tds.putTableData(tdName, td);
if (!ComparatorUtils.equals(oldName, tdName)) {
tdNameMap.put(oldName, tdName);
@ -367,8 +363,19 @@ public class TableDataTreePane extends BasicTableDataTreePane {
}
tc.parameterChanged();
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) {
final NamePane nPanel = uPanel.asNamePane();
nPanel.setObjectName(paneName);

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

@ -1,6 +1,9 @@
package com.fr.design.data;
import com.fr.base.TableData;
import com.fr.data.TableDataSource;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
@ -41,4 +44,26 @@ public class BasicTableDataUtilsTest extends TestCase {
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();
}
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();
}
}

16
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
public JComponent createToolPane(BaseJForm jform, FormDesigner formEditor) {
if (!DesignerMode.isAuthorityEditing()) {
if (isDedicateContainer()) {
if (isDedicateContainer() && this.getComponentCount() > 0) {
// 图表块和报表块由于控件树处不显示,但对应的属性表要显示,此处处理下
XCreator child = ((XLayoutContainer) this).getXCreator(0);
return child.createToolPane(jform, formEditor);
@ -408,7 +408,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
public Component getParentShow(){
return this.getParent();
}
/**
* 重置组件的名称
*
@ -418,18 +418,18 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
public void resetCreatorName(String name) {
toData().setWidgetName(name);
}
/**
* 遍历所有命名相关的组件到集合中
*
* @param xCreators 集合
*/
public void traversalNameRelatedXCreators(Set<XCreator> xCreators) {
xCreators.add(this);
int componentCount = getComponentCount();
for (int i = 0; i < componentCount; i++) {
Component component = getComponent(i);
if (component instanceof XCreator) {
XCreator xCreator = (XCreator) component;
@ -439,7 +439,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
}
}
}
/**
* 重置组件的可见性
*
@ -448,7 +448,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
public void resetVisible(boolean visible) {
toData().setVisible(visible);
}
/**
* 返回编辑的子组件scale为其内部组件
* @return 组件
@ -804,4 +804,4 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
return false;
}
}
}

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);
SharableWidgetProvider bindInfo = ShareLoader.getLoader().getElCaseBindInfoById(shareId);
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()) {

Loading…
Cancel
Save