From 5104b8ddaff7dcb34d286342c9c2047fb443358e Mon Sep 17 00:00:00 2001 From: Harrison Date: Wed, 20 May 2020 09:15:19 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-29912=20=E7=BB=84=E4=BB=B6=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=201=E3=80=81=E5=A4=8D=E5=88=B6=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E7=9A=84=20support=20=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=202?= =?UTF-8?q?=E3=80=81XCreator=20=E7=9A=84=E5=88=9B=E5=BB=BA=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/clipboard/ClipboardFilter.java | 23 ++++++------- .../base/clipboard/ClipboardFilterTest.java | 18 +++++----- .../designer/creator/XCreatorUtils.java | 34 ++++++++++++++++--- .../beans/models/SelectionModelTest.java | 24 +++++++------ .../designer/creator/XCreatorUtilsTest.java | 17 ++++++++++ 5 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 designer-form/src/test/java/com/fr/design/designer/creator/XCreatorUtilsTest.java diff --git a/designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardFilter.java b/designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardFilter.java index 377a57e46f..e9b6b3e0f3 100644 --- a/designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardFilter.java +++ b/designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardFilter.java @@ -1,7 +1,7 @@ package com.fr.design.base.clipboard; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.fun.ClipboardHandlerProvider; -import com.fr.form.main.ExtraFormClassManager; import com.fr.plugin.injectable.PluginModule; import java.util.Set; @@ -13,12 +13,11 @@ import java.util.Set; public abstract class ClipboardFilter { public static T cut(T selection) { - - Class clazz = selection.getClass(); - ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm); + + ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign); Set providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); for (ClipboardHandlerProvider provider : providers) { - if (provider.support(clazz)) { + if (provider.support(selection)) { selection = ((ClipboardHandlerProvider) provider).cut(selection); } } @@ -26,12 +25,11 @@ public abstract class ClipboardFilter { } public static T copy(T selection) { - - Class clazz = selection.getClass(); - ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm); + + ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign); Set providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); for (ClipboardHandlerProvider provider : providers) { - if (provider.support(clazz)) { + if (provider.support(selection)) { selection = ((ClipboardHandlerProvider) provider).copy(selection); } } @@ -39,12 +37,11 @@ public abstract class ClipboardFilter { } public static T paste(T selection) { - - Class clazz = selection.getClass(); - ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm); + + ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign); Set providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); for (ClipboardHandlerProvider provider : providers) { - if (provider.support(clazz)) { + if (provider.support(selection)) { selection = ((ClipboardHandlerProvider) provider).paste(selection); } } diff --git a/designer-base/src/test/java/com/fr/design/base/clipboard/ClipboardFilterTest.java b/designer-base/src/test/java/com/fr/design/base/clipboard/ClipboardFilterTest.java index f6b9190eb9..bb254e79c4 100644 --- a/designer-base/src/test/java/com/fr/design/base/clipboard/ClipboardFilterTest.java +++ b/designer-base/src/test/java/com/fr/design/base/clipboard/ClipboardFilterTest.java @@ -1,7 +1,7 @@ package com.fr.design.base.clipboard; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.fun.ClipboardHandlerProvider; -import com.fr.form.main.ExtraFormClassManager; import com.fr.plugin.injectable.PluginModule; import com.fr.stable.fun.mark.Mutable; import org.easymock.EasyMock; @@ -24,19 +24,19 @@ public class ClipboardFilterTest { @Before public void setUp() throws Exception { - + Set providers = new HashSet<>(); providers.add(new TestClipboardHandlerProvider()); - - ExtraFormClassManager formClassManager = EasyMock.mock(ExtraFormClassManager.class); - EasyMock.expect(formClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) + + ExtraDesignClassManager designClassManager = EasyMock.mock(ExtraDesignClassManager.class); + EasyMock.expect(designClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) .andReturn(providers) .anyTimes(); - EasyMock.replay(formClassManager); - + EasyMock.replay(designClassManager); + PowerMock.mockStatic(PluginModule.class); - EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) - .andReturn(formClassManager) + EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraDesign)) + .andReturn(designClassManager) .anyTimes(); PowerMock.replayAll(); } 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 f51f6710bc..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 @@ -67,6 +67,7 @@ import com.fr.plugin.observer.PluginEvent; import com.fr.plugin.observer.PluginEventListener; import com.fr.stable.StringUtils; 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; diff --git a/designer-form/src/test/java/com/fr/design/designer/beans/models/SelectionModelTest.java b/designer-form/src/test/java/com/fr/design/designer/beans/models/SelectionModelTest.java index 921133a215..06f1be65c4 100644 --- a/designer-form/src/test/java/com/fr/design/designer/beans/models/SelectionModelTest.java +++ b/designer-form/src/test/java/com/fr/design/designer/beans/models/SelectionModelTest.java @@ -1,5 +1,6 @@ package com.fr.design.designer.beans.models; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.designer.beans.events.CreatorEventListenerTable; import com.fr.design.designer.creator.XCreator; import com.fr.design.fun.ClipboardHandlerProvider; @@ -50,25 +51,26 @@ public class SelectionModelTest { EasyMock.expect(provider.support(EasyMock.anyObject())).andReturn(true).anyTimes(); EasyMock.expect(provider.paste(EasyMock.anyObject())).andReturn(null).anyTimes(); EasyMock.replay(provider); - + Set providers = new HashSet<>(); providers.add(provider); - - ExtraFormClassManager formClassManager = EasyMock.mock(ExtraFormClassManager.class); - EasyMock.expect(formClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) + + ExtraDesignClassManager designManager = EasyMock.mock(ExtraDesignClassManager.class); + EasyMock.expect(designManager.getArray(ClipboardHandlerProvider.XML_TAG)) .andReturn(providers) .anyTimes(); - EasyMock.expect(formClassManager.getArray("DesignerEditListenerProvider")) + ExtraFormClassManager formManager = EasyMock.mock(ExtraFormClassManager.class); + EasyMock.expect(formManager.getArray("DesignerEditListenerProvider")) .andReturn(new HashSet()) .anyTimes(); - - - EasyMock.replay(formClassManager); - + EasyMock.replay(designManager, formManager); + PowerMock.mockStatic(PluginModule.class); - EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) - .andReturn(formClassManager) + EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraDesign)) + .andReturn(designManager) .anyTimes(); + EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) + .andReturn(formManager).anyTimes(); PowerMock.replayAll(); } diff --git a/designer-form/src/test/java/com/fr/design/designer/creator/XCreatorUtilsTest.java b/designer-form/src/test/java/com/fr/design/designer/creator/XCreatorUtilsTest.java new file mode 100644 index 0000000000..1efd752d13 --- /dev/null +++ b/designer-form/src/test/java/com/fr/design/designer/creator/XCreatorUtilsTest.java @@ -0,0 +1,17 @@ +package com.fr.design.designer.creator; + +import com.fr.form.ui.EditorHolder; +import org.junit.Assert; +import org.junit.Test; + +public class XCreatorUtilsTest { + + @Test + public void testCreateXCreator() throws Exception { + + XCreator xCreator = XCreatorUtils.createXCreator(new EditorHolder() { + }); + + Assert.assertFalse(xCreator instanceof NullCreator); + } +} \ No newline at end of file