Browse Source

Pull request #1679: REPORT-29912 组件加密

Merge in DESIGN/design from ~HARRISON/design:release/10.0 to release/10.0

* commit 'a9baef150c8938a565e9080e8763bb5bb0195e1c':
  REPORT-29912 组件加密 1、复制过滤的 support 判断条件 2、XCreator 的创建条件
feature/big-screen
Harrison 5 years ago
parent
commit
854151aa30
  1. 17
      designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardFilter.java
  2. 12
      designer-base/src/test/java/com/fr/design/base/clipboard/ClipboardFilterTest.java
  3. 26
      designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java
  4. 18
      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

17
designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardFilter.java

@ -1,7 +1,7 @@
package com.fr.design.base.clipboard; package com.fr.design.base.clipboard;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.ClipboardHandlerProvider; import com.fr.design.fun.ClipboardHandlerProvider;
import com.fr.form.main.ExtraFormClassManager;
import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.injectable.PluginModule;
import java.util.Set; import java.util.Set;
@ -14,11 +14,10 @@ public abstract class ClipboardFilter {
public static <T> T cut(T selection) { public static <T> T cut(T selection) {
Class<?> clazz = selection.getClass(); ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign);
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm);
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG);
for (ClipboardHandlerProvider provider : providers) { for (ClipboardHandlerProvider provider : providers) {
if (provider.support(clazz)) { if (provider.support(selection)) {
selection = ((ClipboardHandlerProvider<T>) provider).cut(selection); selection = ((ClipboardHandlerProvider<T>) provider).cut(selection);
} }
} }
@ -27,11 +26,10 @@ public abstract class ClipboardFilter {
public static <T> T copy(T selection) { public static <T> T copy(T selection) {
Class<?> clazz = selection.getClass(); ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign);
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm);
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG);
for (ClipboardHandlerProvider provider : providers) { for (ClipboardHandlerProvider provider : providers) {
if (provider.support(clazz)) { if (provider.support(selection)) {
selection = ((ClipboardHandlerProvider<T>) provider).copy(selection); selection = ((ClipboardHandlerProvider<T>) provider).copy(selection);
} }
} }
@ -40,11 +38,10 @@ public abstract class ClipboardFilter {
public static <T> T paste(T selection) { public static <T> T paste(T selection) {
Class<?> clazz = selection.getClass(); ExtraDesignClassManager manager = PluginModule.getAgent(PluginModule.ExtraDesign);
ExtraFormClassManager manager = PluginModule.getAgent(PluginModule.ExtraForm);
Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG); Set<ClipboardHandlerProvider> providers = manager.getArray(ClipboardHandlerProvider.XML_TAG);
for (ClipboardHandlerProvider provider : providers) { for (ClipboardHandlerProvider provider : providers) {
if (provider.support(clazz)) { if (provider.support(selection)) {
selection = ((ClipboardHandlerProvider<T>) provider).paste(selection); selection = ((ClipboardHandlerProvider<T>) provider).paste(selection);
} }
} }

12
designer-base/src/test/java/com/fr/design/base/clipboard/ClipboardFilterTest.java

@ -1,7 +1,7 @@
package com.fr.design.base.clipboard; package com.fr.design.base.clipboard;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.ClipboardHandlerProvider; import com.fr.design.fun.ClipboardHandlerProvider;
import com.fr.form.main.ExtraFormClassManager;
import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.injectable.PluginModule;
import com.fr.stable.fun.mark.Mutable; import com.fr.stable.fun.mark.Mutable;
import org.easymock.EasyMock; import org.easymock.EasyMock;
@ -28,15 +28,15 @@ public class ClipboardFilterTest {
Set<Mutable> providers = new HashSet<>(); Set<Mutable> providers = new HashSet<>();
providers.add(new TestClipboardHandlerProvider<Object>()); providers.add(new TestClipboardHandlerProvider<Object>());
ExtraFormClassManager formClassManager = EasyMock.mock(ExtraFormClassManager.class); ExtraDesignClassManager designClassManager = EasyMock.mock(ExtraDesignClassManager.class);
EasyMock.expect(formClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) EasyMock.expect(designClassManager.getArray(ClipboardHandlerProvider.XML_TAG))
.andReturn(providers) .andReturn(providers)
.anyTimes(); .anyTimes();
EasyMock.replay(formClassManager); EasyMock.replay(designClassManager);
PowerMock.mockStatic(PluginModule.class); PowerMock.mockStatic(PluginModule.class);
EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraDesign))
.andReturn(formClassManager) .andReturn(designClassManager)
.anyTimes(); .anyTimes();
PowerMock.replayAll(); PowerMock.replayAll();
} }

26
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.plugin.observer.PluginEventListener;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.third.javax.annotation.Nonnull; import com.fr.third.javax.annotation.Nonnull;
import org.jetbrains.annotations.Nullable;
import javax.swing.Icon; import javax.swing.Icon;
import java.awt.Container; import java.awt.Container;
@ -176,6 +177,29 @@ public class XCreatorUtils {
} }
} }
/**
* 对于继承的子组件来说可能并没有对应的 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") @SuppressWarnings("unchecked")
private static Class<? extends XCreator> searchXCreatorClass(Class<? extends Widget> clazz) { private static Class<? extends XCreator> searchXCreatorClass(Class<? extends Widget> clazz) {
@ -214,7 +238,7 @@ public class XCreatorUtils {
clazz = NullCreator.class; clazz = NullCreator.class;
} else { } else {
widgetClass = widget.getClass(); widgetClass = widget.getClass();
clazz = XCreatorUtils.searchXCreatorClass(widgetClass); clazz = XCreatorUtils.similarXCreatorClass(widgetClass);
if (clazz == null) { if (clazz == null) {
FineLoggerFactory.getLogger().error(widget + "'s" + " xcreator doesn't exsit!"); FineLoggerFactory.getLogger().error(widget + "'s" + " xcreator doesn't exsit!");
clazz = NullCreator.class; clazz = NullCreator.class;

18
designer-form/src/test/java/com/fr/design/designer/beans/models/SelectionModelTest.java

@ -1,5 +1,6 @@
package com.fr.design.designer.beans.models; 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.beans.events.CreatorEventListenerTable;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.fun.ClipboardHandlerProvider; import com.fr.design.fun.ClipboardHandlerProvider;
@ -54,21 +55,22 @@ public class SelectionModelTest {
Set<Mutable> providers = new HashSet<>(); Set<Mutable> providers = new HashSet<>();
providers.add(provider); providers.add(provider);
ExtraFormClassManager formClassManager = EasyMock.mock(ExtraFormClassManager.class); ExtraDesignClassManager designManager = EasyMock.mock(ExtraDesignClassManager.class);
EasyMock.expect(formClassManager.getArray(ClipboardHandlerProvider.XML_TAG)) EasyMock.expect(designManager.getArray(ClipboardHandlerProvider.XML_TAG))
.andReturn(providers) .andReturn(providers)
.anyTimes(); .anyTimes();
EasyMock.expect(formClassManager.getArray("DesignerEditListenerProvider")) ExtraFormClassManager formManager = EasyMock.mock(ExtraFormClassManager.class);
EasyMock.expect(formManager.getArray("DesignerEditListenerProvider"))
.andReturn(new HashSet<Mutable>()) .andReturn(new HashSet<Mutable>())
.anyTimes(); .anyTimes();
EasyMock.replay(designManager, formManager);
EasyMock.replay(formClassManager);
PowerMock.mockStatic(PluginModule.class); PowerMock.mockStatic(PluginModule.class);
EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm)) EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraDesign))
.andReturn(formClassManager) .andReturn(designManager)
.anyTimes(); .anyTimes();
EasyMock.expect(PluginModule.getAgent(PluginModule.ExtraForm))
.andReturn(formManager).anyTimes();
PowerMock.replayAll(); 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