Browse Source

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

将逻辑分散到各个组件中。
减少同一个方法中的耦合
feature/big-screen
Harrison 5 years ago
parent
commit
628727d69e
  1. 27
      designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtil.java
  2. 9
      designer-form/src/main/java/com/fr/design/designer/creator/DedicateLayoutContainer.java
  3. 22
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  4. 17
      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

27
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(); //直接遍历出来目标值,然后按需处理
String uniqueName = uniqueName(form, target, duplicated); xCreator.traversalNameRelatedXCreators(nameRelatedCreators);
for (XCreator target : nameRelatedCreators) {
int componentCount = target.getComponentCount(); String uniqueName = uniqueName(form, target, duplicated);
//如果没有子类,说明是刚创建的,直接对自己处理就好啦
if (componentCount == 0) {
target.toData().setWidgetName(uniqueName);
return;
}
//专属容器,直接返回啦
if (target.isDedicateContainer()) {
target.resetCreatorName(uniqueName); target.resetCreatorName(uniqueName);
return;
}
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);
}
} }
} }

9
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,12 +71,18 @@ 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
public void resetVisible(boolean visible){ public void resetVisible(boolean visible) {
super.resetVisible(visible); super.resetVisible(visible);
XCreator child = getXCreator(XWScaleLayout.INDEX); XCreator child = getXCreator(XWScaleLayout.INDEX);
child.toData().setVisible(visible); child.toData().setVisible(visible);

22
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,11 +419,29 @@ 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) {
toData().setVisible(visible); toData().setVisible(visible);
} }

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

@ -433,13 +433,16 @@ 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();
WCardMainBorderLayout border = borderLayout.toData(); //可能为空
WCardTitleLayout titleLayout = border.getTitlePart(); if (borderLayout != null) {
titleLayout.setCardName(cardLayoutName); WCardMainBorderLayout border = borderLayout.toData();
WCardTagLayout tagLayout = titleLayout.getTagPart(); WCardTitleLayout titleLayout = border.getTitlePart();
for (int i = 0, len = tagLayout.getWidgetCount(); i < len; i++) { titleLayout.setCardName(cardLayoutName);
CardSwitchButton button = tagLayout.getSwitchButton(i); WCardTagLayout tagLayout = titleLayout.getTagPart();
button.setCardLayoutName(cardLayoutName); for (int i = 0, len = tagLayout.getWidgetCount(); i < len; i++) {
CardSwitchButton button = tagLayout.getSwitchButton(i);
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