Browse Source

Pull request #1740: REPORT-32149【组件加密】@harrison两个组件进行拖入,模板预览很奇怪

Merge in DESIGN/design from ~HARRISON/design:release/10.0 to release/10.0

* commit '53053c3612efcedbacdc4fe688e931ceec9c9ae9':
  REPORT-32149【组件加密】@harrison两个组件进行拖入,模板预览很奇怪 名字需要首先加上默认值 0
feature/big-screen
Harrison 4 years ago
parent
commit
f780dd8286
  1. 5
      designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java
  2. 28
      designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

5
designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java

@ -41,11 +41,14 @@ abstract class ModelUtil {
if (StringUtils.isEmpty(widgetName)) { if (StringUtils.isEmpty(widgetName)) {
widgetName = xCreator.createDefaultName(); widgetName = xCreator.createDefaultName();
} }
//先保存默认名字
String raw = widgetName; String raw = widgetName;
int i = 0; int i = 0;
//先初始化加上索引。
widgetName = widgetName + i;
while (form.isNameExist(widgetName) || duplicated.contains(widgetName)) { while (form.isNameExist(widgetName) || duplicated.contains(widgetName)) {
widgetName = raw + i;
i++; i++;
widgetName = raw + i;
} }
//将名字加入重复集合中 //将名字加入重复集合中
duplicated.add(widgetName); duplicated.add(widgetName);

28
designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

@ -56,6 +56,9 @@ public class AddingModelTest {
DaoContext.setEntityDao(null); DaoContext.setEntityDao(null);
} }
/**
* 默认名字 + i
*/
@Test @Test
public void testInstantiateCreator() throws Exception { public void testInstantiateCreator() throws Exception {
@ -82,7 +85,7 @@ public class AddingModelTest {
AddingModel addingModel = new AddingModel(xCreator1, 20, 20); AddingModel addingModel = new AddingModel(xCreator1, 20, 20);
Form form = EasyMock.mock(Form.class); Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("test")).andReturn(true).once(); EasyMock.expect(form.isNameExist("test0")).andReturn(true).once();
EasyMock.expect(form.isNameExist("test03")).andReturn(true).once(); EasyMock.expect(form.isNameExist("test03")).andReturn(true).once();
EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes(); EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(form); EasyMock.replay(form);
@ -93,9 +96,9 @@ public class AddingModelTest {
addingModel.instantiateCreator(mock); addingModel.instantiateCreator(mock);
//没有默认参数, 但已经存在 test //没有默认参数, 但已经存在 test
Assert.assertEquals("test0", xCreator1.toData().getWidgetName()); Assert.assertEquals("test1", xCreator1.toData().getWidgetName());
//直接返回 //直接返回
Assert.assertEquals("test02", xCreator2.toData().getWidgetName()); Assert.assertEquals("test020", xCreator2.toData().getWidgetName());
//已经存在,后接0 //已经存在,后接0
Assert.assertEquals("test030", xCreator3.toData().getWidgetName()); Assert.assertEquals("test030", xCreator3.toData().getWidgetName());
} }
@ -104,8 +107,8 @@ public class AddingModelTest {
public void testInstantiateCreator_cardLayout() throws Exception { public void testInstantiateCreator_cardLayout() throws Exception {
Form form = EasyMock.mock(Form.class); Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("cardlayout")).andReturn(true).once();
EasyMock.expect(form.isNameExist("cardlayout0")).andReturn(true).once(); EasyMock.expect(form.isNameExist("cardlayout0")).andReturn(true).once();
EasyMock.expect(form.isNameExist("cardlayout1")).andReturn(true).once();
EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes(); EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(form); EasyMock.replay(form);
@ -116,13 +119,16 @@ public class AddingModelTest {
WCardLayout wCardLayout = new WCardLayout(20, 20); WCardLayout wCardLayout = new WCardLayout(20, 20);
XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(40, 40)); XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(40, 40));
AddingModel addingModel = new AddingModel(mock, xwCardLayout); AddingModel addingModel = new AddingModel(mock, xwCardLayout);
Assert.assertEquals("cardlayout1", xwCardLayout.toData().getWidgetName()); Assert.assertEquals("cardlayout2", xwCardLayout.toData().getWidgetName());
//依赖于 cardlayout 创建 container //依赖于 cardlayout 创建 container
XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(80); XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(80);
//组件默认名 tablelayout2
AddingModel parentModel = new AddingModel(mock, parentLayOut); AddingModel parentModel = new AddingModel(mock, parentLayOut);
Assert.assertEquals("tablayout1", parentLayOut.toData().getWidgetName()); //经过处理 tablayout20
Assert.assertEquals("tabpane1", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName()); Assert.assertEquals("tablayout20", parentLayOut.toData().getWidgetName());
Assert.assertEquals("tabpane20", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName());
Assert.assertEquals("cardlayout20", xwCardLayout.toData().getWidgetName());
} }
@ -130,8 +136,6 @@ public class AddingModelTest {
public void testInstantiateCreator_containsNotXCreator() throws Exception { public void testInstantiateCreator_containsNotXCreator() throws Exception {
Form form = EasyMock.mock(Form.class); Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("cardlayout")).andReturn(true).once();
EasyMock.expect(form.isNameExist("cardlayout0")).andReturn(true).once();
EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes(); EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(form); EasyMock.replay(form);
@ -170,16 +174,16 @@ public class AddingModelTest {
AddingModel chartModel = new AddingModel(mock, xCreator1); AddingModel chartModel = new AddingModel(mock, xCreator1);
Assert.assertEquals("chart", xCreator1.toData().getWidgetName()); Assert.assertEquals("chart0", xCreator1.toData().getWidgetName());
} }
private static class DemoCreator extends XCreator { private static class DemoCreator extends XCreator {
private String widgetName; private String widgetName;
public DemoCreator(Widget ob, Dimension initSize, String widgetName) { public DemoCreator(Widget ob, Dimension initSize, String defaultName) {
super(ob, initSize); super(ob, initSize);
this.widgetName = widgetName; this.widgetName = defaultName;
} }
@Override @Override

Loading…
Cancel
Save