forked from fanruan/design
Bryant
5 years ago
10 changed files with 278 additions and 53 deletions
@ -0,0 +1,47 @@
|
||||
package com.fr.design.fun; |
||||
|
||||
import com.fr.decision.extension.report.ReportSupportedFileProvider; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.file.FILEChooserPane; |
||||
import com.fr.stable.fun.mark.Mutable; |
||||
|
||||
import javax.swing.Icon; |
||||
|
||||
/** |
||||
* Created by kerry on 2019-10-11 |
||||
*/ |
||||
public interface ReportSupportedFileUIProvider extends Mutable { |
||||
|
||||
int CURRENT_LEVEL = 1; |
||||
|
||||
String XML_TAG = "ReportSupportedFileUIProvider"; |
||||
|
||||
/** |
||||
* 向文件选择器中添加指定文件类型过滤器 |
||||
* @param fileChooser 文件选择器 |
||||
* @param suffix 文件后缀 |
||||
*/ |
||||
void addChooseFileFilter(FILEChooserPane fileChooser, String suffix); |
||||
|
||||
|
||||
/** |
||||
* 获取对应的新增的支持文件类型 |
||||
* @return ReportTemplateFileProvider |
||||
*/ |
||||
ReportSupportedFileProvider getSupportedFile(); |
||||
|
||||
/** |
||||
* 获取文件关联的icon |
||||
* @param path 文件路径 |
||||
* @param isShowLock 是否显示被锁住 |
||||
* @return 对应的图标 |
||||
*/ |
||||
Icon getFileIcon(String path,boolean isShowLock); |
||||
|
||||
/** |
||||
* 保存为新类型文件 |
||||
* @param targetPath 目标路径 |
||||
* @param jTemplate 模板对象 |
||||
*/ |
||||
boolean saveToNewFile(String targetPath, JTemplate jTemplate); |
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.fr.design.fun.impl; |
||||
|
||||
import com.fr.decision.extension.report.ReportSupportedFileProvider; |
||||
import com.fr.design.fun.ReportSupportedFileUIProvider; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.file.FILEChooserPane; |
||||
import com.fr.stable.fun.impl.AbstractProvider; |
||||
import com.fr.stable.fun.mark.API; |
||||
|
||||
import javax.swing.Icon; |
||||
|
||||
/** |
||||
* Created by kerry on 2019-10-14 |
||||
*/ |
||||
@API(level = ReportSupportedFileUIProvider.CURRENT_LEVEL) |
||||
public abstract class AbstractReportSupportedFileUIProvider extends AbstractProvider implements ReportSupportedFileUIProvider { |
||||
@Override |
||||
public void addChooseFileFilter(FILEChooserPane fileChooser, String suffix) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public ReportSupportedFileProvider getSupportedFile() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public Icon getFileIcon(String path, boolean isShowLock) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public boolean saveToNewFile(String targetPath, JTemplate jTemplate) { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
|
||||
@Override |
||||
public String mark4Provider() { |
||||
return getClass().getName(); |
||||
} |
||||
} |
@ -1,51 +1,67 @@
|
||||
package com.fr.design.gui.itree.filetree; |
||||
|
||||
import com.fr.base.extension.FileExtension; |
||||
import com.fr.base.io.BaseBook; |
||||
import com.fr.decision.extension.report.ReportSupportedFileProvider; |
||||
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.design.fun.ReportSupportedFileUIProvider; |
||||
import com.fr.design.fun.impl.AbstractReportSupportedFileUIProvider; |
||||
import com.fr.stable.fun.mark.Mutable; |
||||
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.modules.junit4.PowerMockRunner; |
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* Created by alex sung on 2019/7/25. |
||||
*/ |
||||
@RunWith(PowerMockRunner.class) |
||||
@PrepareForTest(ExtraDesignClassManager.class) |
||||
public class FileNodeConstantsTest { |
||||
@Test |
||||
public void supportFileTypesTest(){ |
||||
public void supportFileTypesTest() { |
||||
ExtraDesignClassManager extra = mockExtraDesignClassManager(); |
||||
Assert.assertEquals(1, extra.getArray(ReportSupportedFileUIProvider.XML_TAG).size()); |
||||
ReportSupportedFileUIProvider option = (ReportSupportedFileUIProvider) extra.getArray(ReportSupportedFileUIProvider.XML_TAG).iterator().next(); |
||||
Assert.assertEquals(FileExtension.CPTX, option.getSupportedFile().getFileExtensions()[0]); |
||||
} |
||||
|
||||
@Test |
||||
public void testSupportFileTypesOrder() { |
||||
ExtraDesignClassManager extra = mockExtraDesignClassManager(); |
||||
PowerMock.mockStatic(ExtraDesignClassManager.class); |
||||
EasyMock.expect(ExtraDesignClassManager.getInstance()).andReturn(extra).once(); |
||||
PowerMock.replayAll(); |
||||
String[] fileTypes = FileNodeConstants.getSupportFileTypes(); |
||||
Assert.assertEquals("cptx", fileTypes[0]); |
||||
Assert.assertEquals("cpt", fileTypes[1]); |
||||
} |
||||
|
||||
private ExtraDesignClassManager mockExtraDesignClassManager() { |
||||
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(); |
||||
Set<Mutable> options = new HashSet<Mutable>() {{ |
||||
add(new MockNewTemplateFileOption()); |
||||
}}; |
||||
EasyMock.expect(extra.getArray(ReportSupportedFileUIProvider.XML_TAG)).andReturn(options).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]); |
||||
return extra; |
||||
} |
||||
|
||||
private class MockCptxApp extends AbstractAppProvider{ |
||||
@Override |
||||
public String[] defaultExtensions() { |
||||
return new String[] {FileExtension.CPTX.getExtension()}; |
||||
} |
||||
private class MockNewTemplateFileOption extends AbstractReportSupportedFileUIProvider { |
||||
|
||||
@Override |
||||
public JTemplate openTemplate(FILE tplFile) { |
||||
return null; |
||||
public ReportSupportedFileProvider getSupportedFile() { |
||||
ReportSupportedFileProvider supportedFileProvider = EasyMock.mock(ReportSupportedFileProvider.class); |
||||
EasyMock.expect(supportedFileProvider.getFileExtensions()).andReturn(new FileExtension[]{FileExtension.CPTX}).anyTimes(); |
||||
EasyMock.replay(supportedFileProvider); |
||||
return supportedFileProvider; |
||||
} |
||||
|
||||
@Override |
||||
public BaseBook asIOFile(FILE tplFile) { |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,38 @@
|
||||
package com.fr.file; |
||||
|
||||
import com.fr.base.extension.FileExtension; |
||||
import com.fr.file.filter.ChooseFileFilter; |
||||
import com.fr.invoke.Reflect; |
||||
import com.fr.stable.StringUtils; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Created by kerry on 2019-10-15 |
||||
*/ |
||||
|
||||
public class FILEChooserPaneTest { |
||||
@Test |
||||
public void testAddChooseFileFilter() { |
||||
FILEChooserPane chooserPane = Reflect.on(FILEChooserPane.class).field("INSTANCE").get(); |
||||
String result1 = Reflect.on(chooserPane).call("calFileNameText", "WorkBook1.cpt", null).get(); |
||||
Assert.assertEquals("WorkBook1.cptnull", result1); |
||||
|
||||
ChooseFileFilter chooseFileFilter1 = new ChooseFileFilter(FileExtension.CPT, StringUtils.EMPTY); |
||||
String result2 = Reflect.on(chooserPane).call("calFileNameText", "WorkBook1.cpt", chooseFileFilter1).get(); |
||||
Assert.assertEquals("WorkBook1.cpt", result2); |
||||
|
||||
ChooseFileFilter chooseFileFilter2 = new ChooseFileFilter(FileExtension.CPTX, StringUtils.EMPTY); |
||||
String result3 = Reflect.on(chooserPane).call("calFileNameText", "WorkBook1.cpt", chooseFileFilter2).get(); |
||||
Assert.assertEquals("WorkBook1.cpt.cptx", result3); |
||||
|
||||
ChooseFileFilter chooseFileFilter3 = new ChooseFileFilter(FileExtension.CPT, StringUtils.EMPTY); |
||||
String result4 = Reflect.on(chooserPane).call("calFileNameText", "WorkBook1.cptx", chooseFileFilter3).get(); |
||||
Assert.assertEquals("WorkBook1.cptx.cpt", result4); |
||||
|
||||
ChooseFileFilter chooseFileFilter5 = new ChooseFileFilter(FileExtension.CPTX, StringUtils.EMPTY); |
||||
String result5 = Reflect.on(chooserPane).call("calFileNameText", "WorkBook1.cptx", chooseFileFilter5).get(); |
||||
Assert.assertEquals("WorkBook1.cptx", result5); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue