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;
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;
@ -14,11 +14,10 @@ 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);
}
}
@ -27,11 +26,10 @@ 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);
}
}
@ -40,11 +38,10 @@ 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);
}
}

12
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;
@ -28,15 +28,15 @@ public class ClipboardFilterTest {
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();
}

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.stable.StringUtils;
import com.fr.third.javax.annotation.Nonnull;
import org.jetbrains.annotations.Nullable;
import javax.swing.Icon;
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")
private static Class<? extends XCreator> searchXCreatorClass(Class<? extends Widget> 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;

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;
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;
@ -54,21 +55,22 @@ public class SelectionModelTest {
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