Browse Source

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

代码回滚
feature/big-screen
Harrison 4 years ago
parent
commit
97649d7f51
  1. 26
      designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java
  2. 101
      designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtils.java

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

@ -6,6 +6,7 @@ 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.mainframe.FormDesigner;
import com.fr.design.utils.ComponentUtils;
import com.fr.general.ComparatorUtils;
@ -25,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) {
ModelUtils.recursiveRenameWidgetName(designer.getTarget(), creator);
public void instantiateCreator(FormDesigner designer, String creatorName) {
creator.toData().setWidgetName(creatorName);
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator);
adapter.initialize();
creator.addNotify();
@ -62,6 +65,19 @@ public class AddingModel {
currentY = -this.creator.getHeight();
}
public String getXCreatorName(FormDesigner designer, XCreator x) {
String def = x.createDefaultName();
if (x.acceptType(XWParameterLayout.class)) {
return def;
}
int i = 0;
while (designer.getTarget().isNameExist(def + i)) {
i++;
}
return def + i;
}
public int getCurrentX() {
return currentX;
}

101
designer-form/src/main/java/com/fr/design/designer/beans/models/ModelUtils.java

@ -1,101 +0,0 @@
package com.fr.design.designer.beans.models;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.XWTitleLayout;
import com.fr.form.main.Form;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.stable.StringUtils;
import java.util.HashSet;
import java.util.Set;
/**
* created by Harrison on 2020/06/04
**/
public class ModelUtils {
/**
* 防止冲突重命名 XCreator 内部的 widget
*
* @param form 表单
* @param xCreator 创建器
*/
public static void recursiveRenameWidgetName(Form form, XCreator xCreator) {
Set<String> nameSpace = new HashSet<>();
//重命名根名字
//这里主要是为了兼容老的命名规则。
renameRootName(form, xCreator, nameSpace);
//这里要用新的命名规则
recursiveRenameChildName(form, xCreator, nameSpace);
}
private static void renameRootName(Form form, XCreator xCreator, Set<String> nameSpace) {
String creatorName = getNameByXCreator(form, xCreator, nameSpace);
xCreator.resetCreatorName(creatorName);
}
private static void recursiveRenameChildName(Form form, XCreator xCreator, Set<String> nameSpace) {
int count = xCreator.getComponentCount();
for (int a = 0; a < count; a++) {
if (xCreator.getComponent(a) instanceof XCreator) {
XCreator child = (XCreator) xCreator.getComponent(a);
String childName = getNameByWidget(form, child, nameSpace);
if (child.toData() instanceof WTitleLayout) {
XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) child.toData(), child.getSize());
xwTitleLayout.resetCreatorName(childName);
continue;
}
child.resetCreatorName(childName);
recursiveRenameChildName(form, child, nameSpace);
}
}
}
/**
* 组件命名规则
* 根据组件的名字如果组件没有名字就用 XCreator 的对应名字
*/
private static String getNameByWidget(Form form, XCreator xCreator, Set<String> nameSpace) {
Widget widget = xCreator.toData();
String name = widget.getWidgetName();
//没有 widgetName, 就创建默认的
if (StringUtils.isEmpty(name)) {
return getNameByXCreator(form, xCreator, nameSpace);
}
return getNameByDefault(form, xCreator, nameSpace, name);
}
/**
* 组件命名规则
* 根据组件的默认名
*/
private static String getNameByXCreator(Form form, XCreator x, Set<String> nameSpace) {
String defaultName = x.createDefaultName();
return getNameByDefault(form, x, nameSpace, defaultName);
}
private static String getNameByDefault(Form form, XCreator xCreator, Set<String> nameSpace, String defaultName) {
String name = defaultName;
if (xCreator.acceptType(XWParameterLayout.class)) {
return name;
}
int i = 0;
//保留第一次的值
String raw = name;
while (form.isNameExist(name) || nameSpace.contains(name)) {
name = raw + i;
i++;
}
nameSpace.add(name);
return name;
}
}
Loading…
Cancel
Save