From 53053c3612efcedbacdc4fe688e931ceec9c9ae9 Mon Sep 17 00:00:00 2001 From: Harrison Date: Wed, 10 Jun 2020 20:08:34 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-32149=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E3=80=91@harrison=E4=B8=A4=E4=B8=AA=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E8=BF=9B=E8=A1=8C=E6=8B=96=E5=85=A5=EF=BC=8C=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E9=A2=84=E8=A7=88=E5=BE=88=E5=A5=87=E6=80=AA=20?= =?UTF-8?q?=E5=90=8D=E5=AD=97=E9=9C=80=E8=A6=81=E9=A6=96=E5=85=88=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E9=BB=98=E8=AE=A4=E5=80=BC=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/beans/models/ModelUtil.java | 5 ++- .../beans/models/AddingModelTest.java | 36 ++++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java index b6f073f10..32d217adc 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java @@ -41,11 +41,14 @@ abstract class ModelUtil { if (StringUtils.isEmpty(widgetName)) { widgetName = xCreator.createDefaultName(); } + //先保存默认名字 String raw = widgetName; int i = 0; + //先初始化加上索引。 + widgetName = widgetName + i; while (form.isNameExist(widgetName) || duplicated.contains(widgetName)) { - widgetName = raw + i; i++; + widgetName = raw + i; } //将名字加入重复集合中 duplicated.add(widgetName); diff --git a/designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java b/designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java index 7f17ef3a2..f7a75b029 100644 --- a/designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java +++ b/designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java @@ -56,6 +56,9 @@ public class AddingModelTest { DaoContext.setEntityDao(null); } + /** + * 默认名字 + i + */ @Test public void testInstantiateCreator() throws Exception { @@ -82,7 +85,7 @@ public class AddingModelTest { AddingModel addingModel = new AddingModel(xCreator1, 20, 20); 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(EasyMock.anyString())).andReturn(false).anyTimes(); EasyMock.replay(form); @@ -93,9 +96,9 @@ public class AddingModelTest { addingModel.instantiateCreator(mock); //没有默认参数, 但已经存在 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 Assert.assertEquals("test030", xCreator3.toData().getWidgetName()); } @@ -104,34 +107,35 @@ public class AddingModelTest { public void testInstantiateCreator_cardLayout() throws Exception { 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("cardlayout1")).andReturn(true).once(); EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes(); EasyMock.replay(form); FormDesigner mock = EasyMock.mock(FormDesigner.class); EasyMock.expect(mock.getTarget()).andReturn(form).anyTimes(); EasyMock.replay(mock); - + WCardLayout wCardLayout = new WCardLayout(20, 20); XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(40, 40)); AddingModel addingModel = new AddingModel(mock, xwCardLayout); - Assert.assertEquals("cardlayout1", xwCardLayout.toData().getWidgetName()); - + Assert.assertEquals("cardlayout2", xwCardLayout.toData().getWidgetName()); + //依赖于 cardlayout 创建 container XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(80); + //组件默认名 tablelayout2 AddingModel parentModel = new AddingModel(mock, parentLayOut); - Assert.assertEquals("tablayout1", parentLayOut.toData().getWidgetName()); - Assert.assertEquals("tabpane1", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName()); - + //经过处理 tablayout20 + Assert.assertEquals("tablayout20", parentLayOut.toData().getWidgetName()); + Assert.assertEquals("tabpane20", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName()); + Assert.assertEquals("cardlayout20", xwCardLayout.toData().getWidgetName()); + } @Test public void testInstantiateCreator_containsNotXCreator() throws Exception { 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.replay(form); @@ -170,16 +174,16 @@ public class AddingModelTest { 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 String widgetName; - - public DemoCreator(Widget ob, Dimension initSize, String widgetName) { + + public DemoCreator(Widget ob, Dimension initSize, String defaultName) { super(ob, initSize); - this.widgetName = widgetName; + this.widgetName = defaultName; } @Override