Browse Source

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

将逻辑分散到各个组件中。
减少同一个方法中的耦合
feature/big-screen
Harrison 5 years ago
parent
commit
628727d69e
  1. 25
      designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java
  2. 7
      designer-form/src/main/java/com/fr/design/designer/creator/DedicateLayoutContainer.java
  3. 20
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  4. 3
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java
  5. 5
      designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

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

@ -22,29 +22,12 @@ 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) {
//有可能并不需要对自己处理,而是对其他的组件处理。所以要找到目标值 Set<XCreator> nameRelatedCreators = new HashSet<>();
XCreator target = xCreator.getXCreator(); //直接遍历出来目标值,然后按需处理
xCreator.traversalNameRelatedXCreators(nameRelatedCreators);
for (XCreator target : nameRelatedCreators) {
String uniqueName = uniqueName(form, target, duplicated); String uniqueName = uniqueName(form, target, duplicated);
int componentCount = target.getComponentCount();
//如果没有子类,说明是刚创建的,直接对自己处理就好啦
if (componentCount == 0) {
target.toData().setWidgetName(uniqueName);
return;
}
//专属容器,直接返回啦
if (target.isDedicateContainer()) {
target.resetCreatorName(uniqueName);
return;
}
target.resetCreatorName(uniqueName); target.resetCreatorName(uniqueName);
int count = target.getComponentCount();
for (int a = 0; a < count; a++) {
if (target.getComponent(a) instanceof XCreator) {
XCreator child = (XCreator) target.getComponent(a);
recursiveRenameWidgetName(form, child, duplicated);
}
} }
} }

7
designer-form/src/main/java/com/fr/design/designer/creator/DedicateLayoutContainer.java

@ -9,6 +9,7 @@ import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* 一些控件专属的容器如标题容器sclae容器 * 一些控件专属的容器如标题容器sclae容器
@ -70,8 +71,14 @@ public abstract class DedicateLayoutContainer extends XLayoutContainer {
child.toData().setWidgetName(name); child.toData().setWidgetName(name);
} }
@Override
public void traversalNameRelatedXCreators(Set<XCreator> xCreators) {
xCreators.add(this);
}
/** /**
* 重置组件的可见性 * 重置组件的可见性
*
* @param visible 可见性 * @param visible 可见性
*/ */
@Override @Override

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

@ -41,6 +41,7 @@ import java.awt.event.MouseEvent;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author richer * @author richer
@ -410,6 +411,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
/** /**
* 重置组件的名称 * 重置组件的名称
*
* @param name 名称 * @param name 名称
*/ */
@Override @Override
@ -417,8 +419,26 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
toData().setWidgetName(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++) {
XCreator xCreator = (XCreator) getComponent(i);
//获取真实的 creator
XCreator realCreator = xCreator.getXCreator();
realCreator.traversalNameRelatedXCreators(xCreators);
}
}
/** /**
* 重置组件的可见性 * 重置组件的可见性
*
* @param visible 可见性 * @param visible 可见性
*/ */
public void resetVisible(boolean visible) { public void resetVisible(boolean visible) {

3
designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java

@ -433,6 +433,8 @@ public class XWCardLayout extends XLayoutContainer {
//修改相关SwitchButton所绑定的cardLayout控件名 //修改相关SwitchButton所绑定的cardLayout控件名
private void changeRelateSwitchCardName(String cardLayoutName) { private void changeRelateSwitchCardName(String cardLayoutName) {
XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout) this.getBackupParent(); XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout) this.getBackupParent();
//可能为空
if (borderLayout != null) {
WCardMainBorderLayout border = borderLayout.toData(); WCardMainBorderLayout border = borderLayout.toData();
WCardTitleLayout titleLayout = border.getTitlePart(); WCardTitleLayout titleLayout = border.getTitlePart();
titleLayout.setCardName(cardLayoutName); titleLayout.setCardName(cardLayoutName);
@ -442,6 +444,7 @@ public class XWCardLayout extends XLayoutContainer {
button.setCardLayoutName(cardLayoutName); button.setCardLayoutName(cardLayoutName);
} }
} }
}
/** /**
* 删除相关组件 * 删除相关组件

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

@ -92,6 +92,7 @@ public class AddingModelTest {
Form form = EasyMock.mock(Form.class); Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("cardlayout")).andReturn(true).once(); 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);
@ -100,12 +101,12 @@ public class AddingModelTest {
EasyMock.replay(mock); EasyMock.replay(mock);
WCardLayout wCardLayout = new WCardLayout(20, 20); WCardLayout wCardLayout = new WCardLayout(20, 20);
XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(20, 20)); 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("cardlayout1", xwCardLayout.toData().getWidgetName());
//依赖于 cardlayout 创建 container //依赖于 cardlayout 创建 container
XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(20); XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(80);
AddingModel parentModel = new AddingModel(mock, parentLayOut); AddingModel parentModel = new AddingModel(mock, parentLayOut);
Assert.assertEquals("tablayout1", parentLayOut.toData().getWidgetName()); Assert.assertEquals("tablayout1", parentLayOut.toData().getWidgetName());
Assert.assertEquals("tabpane1", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName()); Assert.assertEquals("tabpane1", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName());

Loading…
Cancel
Save