Browse Source

REPORT-29912 组件加密

1、复制过滤的 support 判断条件
2、XCreator 的创建条件
feature/big-screen
Harrison 5 years ago
parent
commit
5104b8ddaf
  1. 23
      designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardFilter.java
  2. 18
      designer-base/src/test/java/com/fr/design/base/clipboard/ClipboardFilterTest.java
  3. 34
      designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java
  4. 24
      designer-form/src/test/java/com/fr/design/designer/beans/models/SelectionModelTest.java
  5. 17
      designer-form/src/test/java/com/fr/design/designer/creator/XCreatorUtilsTest.java

23
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> T cut(T selection) {
Class<?> clazz = selection.getClass();
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm);
ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign);
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG);
for (ClipboardHandlerProvider provider : providers) {
if (provider.support(clazz)) {
if (provider.support(selection)) {
selection = ((ClipboardHandlerProvider<T>) provider).cut(selection);
}
}
@ -26,12 +25,11 @@ public abstract class ClipboardFilter {
}
public static <T> T copy(T selection) {
Class<?> clazz = selection.getClass();
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm);
ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign);
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG);
for (ClipboardHandlerProvider provider : providers) {
if (provider.support(clazz)) {
if (provider.support(selection)) {
selection = ((ClipboardHandlerProvider<T>) provider).copy(selection);
}
}
@ -39,12 +37,11 @@ public abstract class ClipboardFilter {
}
public static <T> T paste(T selection) {
Class<?> clazz = selection.getClass();
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm);
ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign);
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG);
for (ClipboardHandlerProvider provider : providers) {
if (provider.support(clazz)) {
if (provider.support(selection)) {
selection = ((ClipboardHandlerProvider<T>) provider).paste(selection);
}
}

18
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<Mutable> providers = new HashSet<>();
providers.add(new TestClipboardHandlerProvider<Object>());
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();
}

34
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<? extends XCreator> similarXCreatorClass(Class<? extends Widget> clazz) {
Class<?> target = clazz;
Class<? extends XCreator> xClazz = null;
//判断条件有两个
//1.还没找到对应的 xClazz
//2.一直到 终极父类-Widget 都找不到
while (xClazz == null && Widget.class.isAssignableFrom(target)) {
xClazz = searchXCreatorClass((Class<? extends Widget>) target);
target = target.getSuperclass();
}
return xClazz;
}
@SuppressWarnings("unchecked")
private static Class<? extends XCreator> searchXCreatorClass(Class<? extends Widget> clazz) {
Class<? extends XCreator> xClazz = (Class<? extends XCreator>) objectMap.get(clazz);
if (xClazz == null) {
xClazz = (Class<? extends XCreator>) 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;

24
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<Mutable> 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<Mutable>())
.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();
}

17
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);
}
}
Loading…
Cancel
Save