Browse Source

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

考虑专属容器 + cardLayout
feature/big-screen
Harrison 5 years ago
parent
commit
c8eea04ce7
  1. 22
      designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java
  2. 53
      designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

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

@ -21,14 +21,24 @@ abstract class ModelUtil {
} }
private static void recursiveRenameWidgetName(Form form, XCreator xCreator, Set<String> duplicated) { private static void recursiveRenameWidgetName(Form form, XCreator xCreator, Set<String> duplicated) {
//有可能并不需要对自己处理,而是对其他的组件处理。所以要找到目标值 //有可能并不需要对自己处理,而是对其他的组件处理。所以要找到目标值
XCreator target = xCreator.getXCreator(); XCreator target = xCreator.getXCreator();
String uniqueName = uniqueName(form, target, duplicated); String uniqueName = uniqueName(form, target, duplicated);
target.toData().setWidgetName(uniqueName);
//将名字加入重复集合中 int componentCount = target.getComponentCount();
duplicated.add(uniqueName); //如果没有子类,说明是刚创建的,直接对自己处理就好啦
if (componentCount == 0) {
target.toData().setWidgetName(uniqueName);
return;
}
//专属容器,直接返回啦
if (target.isDedicateContainer()) {
target.resetCreatorName(uniqueName);
return;
}
target.resetCreatorName(uniqueName);
int count = target.getComponentCount(); int count = target.getComponentCount();
for (int a = 0; a < count; a++) { for (int a = 0; a < count; a++) {
if (target.getComponent(a) instanceof XCreator) { if (target.getComponent(a) instanceof XCreator) {
@ -54,6 +64,8 @@ abstract class ModelUtil {
widgetName = raw + i; widgetName = raw + i;
i++; i++;
} }
//将名字加入重复集合中
duplicated.add(widgetName);
return widgetName; return widgetName;
} }

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

@ -1,15 +1,25 @@
package com.fr.design.designer.beans.models; package com.fr.design.designer.beans.models;
import com.fr.config.dao.DaoContext;
import com.fr.config.dao.impl.LocalClassHelperDao;
import com.fr.config.dao.impl.LocalEntityDao;
import com.fr.config.dao.impl.LocalXmlEntityDao;
import com.fr.design.designer.creator.CRPropertyDescriptor; import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWTitleLayout;
import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.form.main.Form; import com.fr.form.main.Form;
import com.fr.form.ui.ChartEditor; import com.fr.form.ui.ChartEditor;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WCardLayout;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import org.easymock.EasyMock; import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import javax.swing.JComponent; import javax.swing.JComponent;
@ -19,6 +29,20 @@ import java.beans.IntrospectionException;
public class AddingModelTest { public class AddingModelTest {
@Before
public void setUp() {
DaoContext.setXmlEntityDao(new LocalXmlEntityDao());
DaoContext.setClassHelperDao(new LocalClassHelperDao());
DaoContext.setEntityDao(new LocalEntityDao());
}
@After
public void tearDown() {
DaoContext.setXmlEntityDao(null);
DaoContext.setClassHelperDao(null);
DaoContext.setEntityDao(null);
}
@Test @Test
public void testInstantiateCreator() throws Exception { public void testInstantiateCreator() throws Exception {
@ -37,7 +61,9 @@ public class AddingModelTest {
WAbsoluteLayout.BoundsWidget boundsWidget = new WAbsoluteLayout.BoundsWidget(chartEditor3, new Rectangle(dimension)); WAbsoluteLayout.BoundsWidget boundsWidget = new WAbsoluteLayout.BoundsWidget(chartEditor3, new Rectangle(dimension));
WTitleLayout wTitleLayout03 = new WTitleLayout(); WTitleLayout wTitleLayout03 = new WTitleLayout();
wTitleLayout03.addWidget(boundsWidget); wTitleLayout03.addWidget(boundsWidget);
DemoCreator xCreator3 = new DemoCreator(wTitleLayout03, dimension, "test03"); //需要和内部的 widget 一样
wTitleLayout03.setWidgetName("test03");
XWTitleLayout xCreator3 = new XWTitleLayout(wTitleLayout03, dimension);
xCreator1.add(xCreator3); xCreator1.add(xCreator3);
AddingModel addingModel = new AddingModel(xCreator1, 20, 20); AddingModel addingModel = new AddingModel(xCreator1, 20, 20);
@ -61,6 +87,31 @@ public class AddingModelTest {
Assert.assertEquals("test030", xCreator3.toData().getWidgetName()); Assert.assertEquals("test030", xCreator3.toData().getWidgetName());
} }
@Test
public void testInstantiateCreator_cardLayout() throws Exception {
Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("cardlayout")).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(20, 20));
AddingModel addingModel = new AddingModel(mock, xwCardLayout);
Assert.assertEquals("cardlayout1", xwCardLayout.toData().getWidgetName());
//依赖于 cardlayout 创建 container
XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(20);
AddingModel parentModel = new AddingModel(mock, parentLayOut);
Assert.assertEquals("tablayout1", parentLayOut.toData().getWidgetName());
Assert.assertEquals("tabpane1", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName());
}
private static class DemoCreator extends XCreator { private static class DemoCreator extends XCreator {
private String widgetName; private String widgetName;

Loading…
Cancel
Save