From b3ab7ae77341b3978374654dde06a2a47d2edb91 Mon Sep 17 00:00:00 2001 From: neil <459208047@qq.com> Date: Mon, 25 May 2020 16:02:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E4=BB=A3=E7=A0=81=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/creator/XCreatorUtils.java | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java index 433f7c4f70..d14780054a 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java @@ -66,7 +66,8 @@ import com.fr.plugin.manage.PluginFilter; import com.fr.plugin.observer.PluginEvent; import com.fr.plugin.observer.PluginEventListener; import com.fr.stable.StringUtils; -import org.jetbrains.annotations.NotNull; +import com.fr.third.javax.annotation.Nonnull; +import org.jetbrains.annotations.Nullable; import javax.swing.Icon; import java.awt.Container; @@ -164,21 +165,44 @@ public class XCreatorUtils { } private static void reInitExtra() { - + extraObjectMap.clear(); extraObjectMap.putAll(ExtraDesignClassManager.getInstance().getParameterWidgetOptionsMap()); extraObjectMap.putAll(ExtraDesignClassManager.getInstance().getFormWidgetOptionsMap()); } - + private static void putExtraEditor() { if (DesignModuleFactory.getChartEditorClass() != null) { objectMap.put(DesignModuleFactory.getChartEditorClass(), XChartEditor.class); } } - + + /** + * 对于继承的子组件来说,可能并没有对应的 XCreator + * 这个时候,就需要递归的找父类 + * + * @param clazz 组件类 + * @return 创建类 + */ + @SuppressWarnings("unchecked") + @Nullable + private static Class similarXCreatorClass(Class clazz) { + + Class target = clazz; + Class xClazz = null; + //判断条件有两个 + //1.还没找到对应的 xClazz + //2.一直到 终极父类-Widget 都找不到 + while (xClazz == null && Widget.class.isAssignableFrom(target)) { + xClazz = searchXCreatorClass((Class) target); + target = target.getSuperclass(); + } + return xClazz; + } + @SuppressWarnings("unchecked") private static Class searchXCreatorClass(Class clazz) { - + Class xClazz = (Class) objectMap.get(clazz); if (xClazz == null) { xClazz = (Class) extraObjectMap.get(clazz); @@ -214,7 +238,7 @@ public class XCreatorUtils { clazz = NullCreator.class; } else { widgetClass = widget.getClass(); - clazz = XCreatorUtils.searchXCreatorClass(widgetClass); + clazz = XCreatorUtils.similarXCreatorClass(widgetClass); if (clazz == null) { FineLoggerFactory.getLogger().error(widget + "'s" + " xcreator doesn't exsit!"); clazz = NullCreator.class; @@ -286,7 +310,7 @@ public class XCreatorUtils { * @param creator 组件 * @return 返回顶层容器 */ - public static XLayoutContainer getHotspotContainer(@NotNull XCreator creator) { + public static XLayoutContainer getHotspotContainer(@Nonnull XCreator creator) { if (creator.isDedicateContainer()) { return (XLayoutContainer) creator.getParent(); }