Browse Source

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

Merge in DESIGN/design from ~HARRISON/design:release/10.0 to release/10.0

* commit 'c5b4410d9a231d384cd4bfe23b939351fe739f05':
  沿用之前的命名规则。 只进行 n 对 n 的匹配。
  REPORT-32149【组件加密】@harrison两个组件进行拖入,模板预览很奇怪 [场景] 拖入组件时,组件时绝对画布块,内部有多个组件。此时,不会对内部的多个组件进行检测。 [solution] 递归的对所有组件进行处理。
feature/big-screen
Harrison 5 years ago
parent
commit
61e8ddc2a2
  1. 66
      designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java
  2. 57
      designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

66
designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java

@ -1,18 +1,23 @@
package com.fr.design.designer.beans.models;
import java.awt.Rectangle;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.XWTitleLayout;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.main.Form;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils;
import java.awt.Rectangle;
import java.util.HashSet;
import java.util.Set;
/**
* 添加状态下的model
*/
@ -26,22 +31,20 @@ public class AddingModel {
private boolean added;
public AddingModel(FormDesigner designer, XCreator xCreator) {
String creatorName = getXCreatorName(designer, xCreator);
this.creator = xCreator;
instantiateCreator(designer, creatorName);
instantiateCreator(designer);
// 初始的时候隐藏该组件的图标
currentY = -this.creator.getWidth();
currentX = -this.creator.getHeight();
}
/**
* 待说明
* 初始化创建器
*
* @param designer 设计器
* @param creatorName 组件名
*/
public void instantiateCreator(FormDesigner designer, String creatorName) {
creator.toData().setWidgetName(creatorName);
public void instantiateCreator(FormDesigner designer) {
renameWidgetName(designer.getTarget(), creator);
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator);
adapter.initialize();
creator.addNotify();
@ -65,16 +68,53 @@ public class AddingModel {
currentY = -this.creator.getHeight();
}
public String getXCreatorName(FormDesigner designer, XCreator x) {
/**
* 防止冲突重命名 XCreator 内部的 widget
*
* @param form 表单
* @param xCreator 创建器
*/
private static void renameWidgetName(Form form, XCreator xCreator) {
Set<String> nameSpace = new HashSet<>();
recursiveRenameWidgetName(form, xCreator, nameSpace);
}
private static void recursiveRenameWidgetName(Form form, XCreator xCreator, Set<String> nameSpace) {
String creatorName = uniqueName(form, xCreator, nameSpace);
if (xCreator.toData() instanceof WTitleLayout) {
XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) xCreator.toData(), xCreator.getSize());
xwTitleLayout.resetCreatorName(creatorName);
return;
}
xCreator.resetCreatorName(creatorName);
int count = xCreator.getComponentCount();
for (int a = 0; a < count; a++) {
if (xCreator.getComponent(a) instanceof XCreator) {
XCreator child = (XCreator) xCreator.getComponent(a);
recursiveRenameWidgetName(form, child, nameSpace);
}
}
}
/**
* 组件命名规则
*/
public static String uniqueName(Form form, XCreator x, Set<String> nameSpace) {
String def = x.createDefaultName();
if (x.acceptType(XWParameterLayout.class)) {
return def;
}
int i = 0;
while (designer.getTarget().isNameExist(def + i)) {
String name = def + i;
while (form.isNameExist(name) || nameSpace.contains(name)) {
i++;
name = def + i;
}
return def + i;
return name;
}
public int getCurrentX() {

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

@ -0,0 +1,57 @@
package com.fr.design.designer.beans.models;
import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.FormDesigner;
import com.fr.form.main.Form;
import com.fr.form.ui.ChartEditor;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import javax.swing.JComponent;
import java.awt.Dimension;
import java.beans.IntrospectionException;
public class AddingModelTest {
@Test
public void testInstantiateCreator() throws Exception {
ChartEditor chartEditor = new ChartEditor();
chartEditor.setWidgetName("test01");
XCreator xCreator = new XCreator(chartEditor, new Dimension(20, 20)) {
@Override
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[0];
}
@Override
protected JComponent initEditor() {
return null;
}
@Override
protected void initXCreatorProperties() {
}
@Override
public String createDefaultName() {
return "test";
}
};
AddingModel addingModel = new AddingModel(xCreator, 20, 20);
Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("test0")).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);
addingModel.instantiateCreator(mock);
Assert.assertEquals("test1", xCreator.toData().getWidgetName());
}
}
Loading…
Cancel
Save