Harrison
5 years ago
2 changed files with 21 additions and 106 deletions
@ -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…
Reference in new issue