Browse Source

Pull request #1721: REPORT-32149【组件加密】@harrison两个组件进行拖入,模板预览很奇怪 组件的默认名字不满足要求。

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

* commit '955559bb4c71dc7c099c1ded390a2838ab1f3fa3':
  REPORT-32149【组件加密】@harrison两个组件进行拖入,模板预览很奇怪 回滚代码,没回滚完
  REPORT-32149【组件加密】@harrison两个组件进行拖入,模板预览很奇怪 代码回滚
  REPORT-32149【组件加密】@harrison两个组件进行拖入,模板预览很奇怪 组件的默认名字不满足要求。 一些组件外面会嵌套 TitileLayout 所以根组件依旧保持之前的逻辑。 子组件使用组件名字递增的方式。
feature/big-screen
Harrison 5 years ago
parent
commit
5a16de71e1
  1. 61
      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

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

@ -7,16 +7,11 @@ 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
@ -31,20 +26,22 @@ public class AddingModel {
private boolean added;
public AddingModel(FormDesigner designer, XCreator xCreator) {
String creatorName = getXCreatorName(designer, xCreator);
this.creator = xCreator;
instantiateCreator(designer);
instantiateCreator(designer, creatorName);
// 初始的时候隐藏该组件的图标
currentY = -this.creator.getWidth();
currentX = -this.creator.getHeight();
}
/**
* 初始化创建器
* 待说明
*
* @param designer 设计器
* @param designer 设计器
* @param creatorName 组件名
*/
public void instantiateCreator(FormDesigner designer) {
renameWidgetName(designer.getTarget(), creator);
public void instantiateCreator(FormDesigner designer, String creatorName) {
creator.toData().setWidgetName(creatorName);
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator);
adapter.initialize();
creator.addNotify();
@ -68,55 +65,19 @@ public class AddingModel {
currentY = -this.creator.getHeight();
}
/**
* 防止冲突重命名 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) {
public String getXCreatorName(FormDesigner designer, XCreator x) {
String def = x.createDefaultName();
if (x.acceptType(XWParameterLayout.class)) {
return def;
}
int i = 0;
String name = def + i;
while (form.isNameExist(name) || nameSpace.contains(name)) {
while (designer.getTarget().isNameExist(def + i)) {
i++;
name = def + i;
}
return name;
return def + i;
}
public int getCurrentX() {
return currentX;
}

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

@ -1,57 +0,0 @@
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