From f91fbdb59cd74defbefecab7744c86d1f5f5a44e Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 22 Jul 2019 14:54:09 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-17881=20=E6=96=87=E6=A1=A3=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E9=A2=84=E8=A7=88=E6=8E=A7=E4=BB=B6=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=97=A0=E6=95=88-=E5=A4=96=E9=83=A8=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E8=80=85=E6=8F=92=E4=BB=B6=E9=97=AE=E9=A2=98=20=E8=BF=99?= =?UTF-8?q?=E9=87=8C=E4=BF=9D=E5=AD=98=E7=9A=84=E4=B8=8D=E6=98=AF=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widget/WidgetDefinePaneFactory.java | 29 +++++--- .../widget/WidgetDefinePaneFactoryTest.java | 66 +++++++++++++++++++ 2 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java diff --git a/designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java b/designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java index 756b36ad2..2df2e9f2a 100644 --- a/designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java +++ b/designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java @@ -48,6 +48,7 @@ import com.fr.report.web.button.write.AppendRowButton; import com.fr.report.web.button.write.DeleteRowButton; import com.fr.stable.bridge.BridgeMark; import com.fr.stable.bridge.StableFactory; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -60,7 +61,9 @@ import java.util.Map; * Time : 上午11:17 */ public class WidgetDefinePaneFactory { + private static Map, Appearance> defineMap = new HashMap, Appearance>(); + private static Map, Appearance> pluginDefineMap = ExtraDesignClassManager.getInstance().getCellWidgetOptionsMap(); static { defineMap.put(NumberEditor.class, new Appearance(NumberEditorDefinePane.class, WidgetConstants.NUMBER + "")); @@ -91,24 +94,32 @@ public class WidgetDefinePaneFactory { defineMap.put(AppendRowButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); defineMap.put(DeleteRowButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); defineMap.put(TreeNodeToggleButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); - defineMap.putAll(ExtraDesignClassManager.getInstance().getCellWidgetOptionsMap()); } private WidgetDefinePaneFactory() { } + @Nullable public static RN createWidgetDefinePane(Widget widget, Operator operator) { + Appearance dn = defineMap.get(widget.getClass()); - DataModify definePane = null; - try { - definePane = (DataModify) dn.getDefineClass().newInstance(); - definePane.populateBean(widget); - operator.did(definePane.dataUI(), dn.getDisplayName()); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + // 再走一遍插件。 + if (dn == null) { + dn = pluginDefineMap.get(widget.getClass()); } - return new RN(definePane, dn.getDisplayName()); + if (dn != null) { + DataModify definePane = null; + try { + definePane = (DataModify) dn.getDefineClass().newInstance(); + definePane.populateBean(widget); + operator.did(definePane.dataUI(), dn.getDisplayName()); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return new RN(definePane, dn.getDisplayName()); + } + return null; } public static class RN { diff --git a/designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java b/designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java new file mode 100644 index 000000000..a7b0c46b6 --- /dev/null +++ b/designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java @@ -0,0 +1,66 @@ +package com.fr.design.widget; + +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.data.DataCreatorUI; +import com.fr.design.widget.ui.ButtonDefinePane; +import com.fr.form.ui.Button; +import com.fr.form.ui.Widget; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.HashMap; +import java.util.Map; + +@RunWith(PowerMockRunner.class) +@PowerMockIgnore("javax.swing.*") +public class WidgetDefinePaneFactoryTest { + + @Test + @PrepareForTest({ExtraDesignClassManager.class, WidgetDefinePaneFactory.class}) + public void testCreateWidgetDefinePane() throws Exception { + + Map, Appearance> map = new HashMap<>(); + ExtraDesignClassManager mockDesignManager = EasyMock.mock(ExtraDesignClassManager.class); + EasyMock.expect(mockDesignManager.getCellWidgetOptionsMap()).andReturn(map).anyTimes(); + EasyMock.replay(mockDesignManager); + + PowerMock.mockStatic(ExtraDesignClassManager.class); + EasyMock.expect(ExtraDesignClassManager.getInstance()).andReturn(mockDesignManager).anyTimes(); + PowerMock.replayAll(ExtraDesignClassManager.class); + + Button mockWidget = EasyMock.mock(Button.class); + EasyMock.replay(mockWidget); + + ButtonDefinePane mockPane = EasyMock.mock(ButtonDefinePane.class); + mockPane.populateBean(EasyMock.anyObject(Button.class)); + EasyMock.expectLastCall(); + EasyMock.replay(mockPane); + + + Operator mockOperator = EasyMock.mock(Operator.class); + mockOperator.did(EasyMock.anyObject(DataCreatorUI.class), EasyMock.anyString()); + EasyMock.replay(mockOperator); + + WidgetDefinePaneFactory.RN rn1 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator); + Assert.assertNull(rn1); + + Appearance appearance = new Appearance(ButtonDefinePane.class, "test"); + map.put(mockWidget.getClass(), appearance); + + WidgetDefinePaneFactory.RN rn2 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator); + Assert.assertNotNull(rn2); + + map.clear(); + + WidgetDefinePaneFactory.RN rn3 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator); + Assert.assertNull(rn3); + } + + +} \ No newline at end of file