Browse Source
# Conflicts: # designer-realize/src/main/java/com/fr/start/module/DesignerActivator.javafinal/10.0
jeo
5 years ago
38 changed files with 597 additions and 202 deletions
@ -0,0 +1,77 @@
|
||||
package com.fr.design.gui.itree.filetree; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.ExtraDesignClassManager; |
||||
import com.fr.design.mainframe.App; |
||||
import com.fr.general.GeneralContext; |
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.injectable.PluginModule; |
||||
import com.fr.plugin.manage.PluginFilter; |
||||
import com.fr.plugin.observer.PluginEvent; |
||||
import com.fr.plugin.observer.PluginEventListener; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
import java.util.concurrent.locks.ReadWriteLock; |
||||
import java.util.concurrent.locks.ReentrantReadWriteLock; |
||||
|
||||
/** |
||||
* Created by alex sung on 2019/7/23. |
||||
*/ |
||||
public class FileNodeConstants { |
||||
|
||||
private static List<String> supportFileType; |
||||
private static ReadWriteLock rwl = new ReentrantReadWriteLock(); |
||||
|
||||
private FileNodeConstants() { |
||||
} |
||||
|
||||
static { |
||||
initSupportedTypes(); |
||||
|
||||
GeneralContext.listenPluginRunningChanged(new PluginEventListener() { |
||||
@Override |
||||
public void on(PluginEvent pluginEvent) { |
||||
initSupportedTypes(); |
||||
} |
||||
}, new PluginFilter() { |
||||
@Override |
||||
public boolean accept(PluginContext pluginContext) { |
||||
return pluginContext.contain(PluginModule.ExtraDesign); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private static void addAppExtensions(String[] extensions) { |
||||
for (int i = 0, size = extensions.length; i < size; i++) { |
||||
if (!supportFileType.contains(extensions[i])) { |
||||
supportFileType.add(extensions[i]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static void initSupportedTypes() { |
||||
try { |
||||
rwl.writeLock().lock(); |
||||
supportFileType = new ArrayList<>(Arrays.asList(FRContext.getFileNodes().getSupportedTypes())); |
||||
//通过插件扩展的
|
||||
Set<App> apps = ExtraDesignClassManager.getInstance().getArray(App.MARK_STRING); |
||||
for (App app : apps) { |
||||
addAppExtensions(app.defaultExtensions()); |
||||
} |
||||
} finally { |
||||
rwl.writeLock().unlock(); |
||||
} |
||||
} |
||||
|
||||
public static String[] getSupportFileTypes() { |
||||
try { |
||||
rwl.readLock().lock(); |
||||
return supportFileType.toArray(new String[0]); |
||||
} finally { |
||||
rwl.readLock().unlock(); |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 284 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 6.8 KiB |
@ -0,0 +1,51 @@
|
||||
package com.fr.design.gui.itree.filetree; |
||||
|
||||
import com.fr.base.extension.FileExtension; |
||||
import com.fr.base.io.BaseBook; |
||||
import com.fr.design.ExtraDesignClassManager; |
||||
import com.fr.design.mainframe.AbstractAppProvider; |
||||
import com.fr.design.mainframe.App; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.file.FILE; |
||||
import com.fr.stable.fun.mark.Mutable; |
||||
import org.easymock.EasyMock; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* Created by alex sung on 2019/7/25. |
||||
*/ |
||||
public class FileNodeConstantsTest { |
||||
@Test |
||||
public void supportFileTypesTest(){ |
||||
ExtraDesignClassManager extra = EasyMock.mock(ExtraDesignClassManager.class); |
||||
Set<Mutable> apps = new HashSet<Mutable>(){{add(new MockCptxApp());}}; |
||||
EasyMock.expect(extra.getArray(App.MARK_STRING)).andReturn(apps).anyTimes(); |
||||
EasyMock.replay(extra); |
||||
|
||||
Assert.assertEquals(1, extra.getArray(App.MARK_STRING).size()); |
||||
App app = (App) extra.getArray(App.MARK_STRING).iterator().next(); |
||||
Assert.assertEquals("cptx", app.defaultExtensions()[0]); |
||||
} |
||||
|
||||
private class MockCptxApp extends AbstractAppProvider{ |
||||
@Override |
||||
public String[] defaultExtensions() { |
||||
return new String[] {FileExtension.CPTX.getExtension()}; |
||||
} |
||||
|
||||
@Override |
||||
public JTemplate openTemplate(FILE tplFile) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public BaseBook asIOFile(FILE tplFile) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.fr.design.mainframe.alphafine; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.actions.help.alphafine.AlphaFineConfigManager; |
||||
import com.fr.general.GeneralContext; |
||||
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.PrepareForTest; |
||||
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; |
||||
import org.powermock.modules.junit4.PowerMockRunner; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
@RunWith(PowerMockRunner.class) |
||||
public class AlphaFineHelperTest { |
||||
|
||||
@Test |
||||
@PrepareForTest({GeneralContext.class, DesignerEnvManager.class}) |
||||
@SuppressStaticInitializationFor("com.fr.design.mainframe.alphafine.AlphaFineHelper") |
||||
public void testSwitchConfig4Locale() throws Exception { |
||||
|
||||
PowerMock.mockStatic(GeneralContext.class); |
||||
EasyMock.expect(GeneralContext.isChineseEnv()).andReturn(true).times(1).andReturn(false).times(1); |
||||
|
||||
DesignerEnvManager manager = EasyMock.mock(DesignerEnvManager.class); |
||||
EasyMock.expect(manager.getAlphaFineConfigManager()).andReturn(new AlphaFineConfigManager()).anyTimes(); |
||||
EasyMock.replay(manager); |
||||
|
||||
PowerMock.mockStatic(DesignerEnvManager.class); |
||||
EasyMock.expect(DesignerEnvManager.getEnvManager()).andReturn(manager).anyTimes(); |
||||
|
||||
PowerMock.replayAll(); |
||||
|
||||
AlphaFineHelper.switchConfig4Locale(); |
||||
AlphaFineConfigManager config = manager.getAlphaFineConfigManager(); |
||||
Assert.assertEquals(true, config.isSearchOnLine()); |
||||
|
||||
AlphaFineHelper.switchConfig4Locale(); |
||||
Assert.assertEquals(false, config.isSearchOnLine()); |
||||
|
||||
|
||||
} |
||||
} |
@ -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<Class<? extends Widget>, 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); |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue