From 628727d69e9770c4a10571f43303e23298d1f160 Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 9 Jun 2020 19:19:07 +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=B0=86=E9=80=BB=E8=BE=91=E5=88=86=E6=95=A3=E5=88=B0=E5=90=84?= =?UTF-8?q?=E4=B8=AA=E7=BB=84=E4=BB=B6=E4=B8=AD=E3=80=82=20=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E5=90=8C=E4=B8=80=E4=B8=AA=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E8=80=A6=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/beans/models/ModelUtil.java | 27 ++++-------------- .../creator/DedicateLayoutContainer.java | 11 ++++++-- .../fr/design/designer/creator/XCreator.java | 28 ++++++++++++++++--- .../creator/cardlayout/XWCardLayout.java | 17 ++++++----- .../beans/models/AddingModelTest.java | 7 +++-- 5 files changed, 52 insertions(+), 38 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 ddd9e0e31b..b6f073f10b 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 @@ -22,29 +22,12 @@ abstract class ModelUtil { private static void recursiveRenameWidgetName(Form form, XCreator xCreator, Set duplicated) { - //有可能并不需要对自己处理,而是对其他的组件处理。所以要找到目标值 - XCreator target = xCreator.getXCreator(); - String uniqueName = uniqueName(form, target, duplicated); - - int componentCount = target.getComponentCount(); - //如果没有子类,说明是刚创建的,直接对自己处理就好啦 - if (componentCount == 0) { - target.toData().setWidgetName(uniqueName); - return; - } - //专属容器,直接返回啦 - if (target.isDedicateContainer()) { + Set nameRelatedCreators = new HashSet<>(); + //直接遍历出来目标值,然后按需处理 + xCreator.traversalNameRelatedXCreators(nameRelatedCreators); + for (XCreator target : nameRelatedCreators) { + String uniqueName = uniqueName(form, target, duplicated); 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); - } } } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/DedicateLayoutContainer.java b/designer-form/src/main/java/com/fr/design/designer/creator/DedicateLayoutContainer.java index d7f073b451..c8abd8d39b 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/DedicateLayoutContainer.java +++ b/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.beans.IntrospectionException; import java.util.List; +import java.util.Set; /** * 一些控件专属的容器,如标题容器,sclae容器 @@ -69,13 +70,19 @@ public abstract class DedicateLayoutContainer extends XLayoutContainer { //实现WTitleLayout的SetWidgetName child.toData().setWidgetName(name); } - + + @Override + public void traversalNameRelatedXCreators(Set xCreators) { + xCreators.add(this); + } + /** * 重置组件的可见性 + * * @param visible 可见性 */ @Override - public void resetVisible(boolean visible){ + public void resetVisible(boolean visible) { super.resetVisible(visible); XCreator child = getXCreator(XWScaleLayout.INDEX); child.toData().setVisible(visible); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java index bef18f96f0..a5a59acc86 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java +++ b/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.util.ArrayList; import java.util.List; +import java.util.Set; /** * @author richer @@ -407,24 +408,43 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo public Component getParentShow(){ return this.getParent(); } - + /** * 重置组件的名称 + * * @param name 名称 */ @Override public void resetCreatorName(String name) { toData().setWidgetName(name); } - + + /** + * 遍历所有命名相关的组件到集合中 + * + * @param xCreators 集合 + */ + public void traversalNameRelatedXCreators(Set 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 可见性 */ - public void resetVisible(boolean visible){ + public void resetVisible(boolean visible) { toData().setVisible(visible); } - + /** * 返回编辑的子组件,scale为其内部组件 * @return 组件 diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java index c91d34654c..1ff3f41c55 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java @@ -433,13 +433,16 @@ public class XWCardLayout extends XLayoutContainer { //修改相关SwitchButton所绑定的cardLayout控件名 private void changeRelateSwitchCardName(String cardLayoutName) { XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout) this.getBackupParent(); - WCardMainBorderLayout border = borderLayout.toData(); - WCardTitleLayout titleLayout = border.getTitlePart(); - titleLayout.setCardName(cardLayoutName); - WCardTagLayout tagLayout = titleLayout.getTagPart(); - for (int i = 0, len = tagLayout.getWidgetCount(); i < len; i++) { - CardSwitchButton button = tagLayout.getSwitchButton(i); - button.setCardLayoutName(cardLayoutName); + //可能为空 + if (borderLayout != null) { + WCardMainBorderLayout border = borderLayout.toData(); + WCardTitleLayout titleLayout = border.getTitlePart(); + titleLayout.setCardName(cardLayoutName); + WCardTagLayout tagLayout = titleLayout.getTagPart(); + for (int i = 0, len = tagLayout.getWidgetCount(); i < len; i++) { + CardSwitchButton button = tagLayout.getSwitchButton(i); + button.setCardLayoutName(cardLayoutName); + } } } 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 689044fe9e..a6bd823008 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 @@ -92,20 +92,21 @@ public class AddingModelTest { 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); 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)); + XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(40, 40)); AddingModel addingModel = new AddingModel(mock, xwCardLayout); Assert.assertEquals("cardlayout1", xwCardLayout.toData().getWidgetName()); //依赖于 cardlayout 创建 container - XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(20); + XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(80); AddingModel parentModel = new AddingModel(mock, parentLayOut); Assert.assertEquals("tablayout1", parentLayOut.toData().getWidgetName()); Assert.assertEquals("tabpane1", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName());