From 3fd4e107a3170dd5dc467a7bfebc71a38481f55a Mon Sep 17 00:00:00 2001 From: kerry Date: Tue, 22 Oct 2019 13:38:18 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-23053=E3=80=9010.0.4=E5=9B=9E=E5=BD=92?= =?UTF-8?q?=E3=80=91=E8=BF=9C=E7=A8=8B=E8=AE=BE=E8=AE=A1=E8=BE=93=E5=87=BA?= =?UTF-8?q?Excel=E3=80=81=E5=86=85=E7=BD=AE=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E6=A8=A1=E7=89=88=EF=BC=8C=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80?= =?UTF-8?q?=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JTemplate.java | 15 +----- .../fr/design/module/DesignModuleFactory.java | 5 +- .../java/com/fr/file/FILEChooserPane.java | 48 ++++++++++++++----- .../java/com/fr/file/FILEChooserPaneTest.java | 17 +++---- .../java/com/fr/design/mainframe/JForm.java | 7 +-- .../com/fr/design/mainframe/JWorkBook.java | 10 ++++ 6 files changed, 62 insertions(+), 40 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index b9b08552f2..2b06fb2e93 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -628,22 +628,11 @@ public abstract class JTemplate> } } - private void addChooseFILEFilter(FILEChooserPane fileChooser){ - String appName = ProductConstants.APP_NAME; - if (FileExtension.CPT.matchExtension(this.suffix())){ - fileChooser.addChooseFILEFilter(new ChooseFileFilter(FileExtension.CPT, appName + Toolkit.i18nText("Fine-Design_Report_Template_File"))); - } - if (FileExtension.FRM.matchExtension(this.suffix())) { - // richer:form文件 daniel 改成三个字 - fileChooser.addChooseFILEFilter(new ChooseFileFilter(FileExtension.FRM, appName + Toolkit.i18nText("Fine-Design_Report_Template_File"))); - } - addExtraChooseFILEFilter(fileChooser); - } - - protected void addExtraChooseFILEFilter(FILEChooserPane fileChooser){ + protected void addChooseFILEFilter(FILEChooserPane fileChooser){ } + // 保存新模板时会进入此方法(新建模板直接保存,或者另存为) protected boolean saveNewFile(FILE editingFILE, String oldName) { String originID = StringUtils.EMPTY; diff --git a/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java b/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java index 74cf7cbd35..9669b7cf92 100644 --- a/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java +++ b/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java @@ -15,6 +15,7 @@ import com.fr.design.parameter.ParameterDesignerProvider; import com.fr.design.parameter.ParameterReader; import com.fr.form.ui.Widget; import com.fr.log.FineLoggerFactory; +import com.fr.plugin.solution.sandbox.collection.PluginSandboxCollections; import com.fr.stable.StableUtils; import org.jetbrains.annotations.NotNull; @@ -235,7 +236,7 @@ public class DesignModuleFactory { public static void registerParameterReader(ParameterReader reader) { if (instance.parameterReaderList == null) { - instance.parameterReaderList = new ArrayList(); + instance.parameterReaderList = PluginSandboxCollections.newSandboxList(); } instance.parameterReaderList.add(reader); } @@ -246,4 +247,4 @@ public class DesignModuleFactory { } return instance.parameterReaderList.toArray(new ParameterReader[instance.parameterReaderList.size()]); } -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java index 7f03b6672d..b938845380 100644 --- a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java +++ b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java @@ -4,12 +4,14 @@ import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.base.extension.FileExtension; import com.fr.design.DesignerEnvManager; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.actions.UpdateAction; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.UIDialog; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.fun.ReportSupportedFileUIProvider; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButtonUI; import com.fr.design.gui.icombobox.UIComboBox; @@ -90,6 +92,7 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -475,8 +478,9 @@ public class FILEChooserPane extends BasicPane { @Override public void itemStateChanged(ItemEvent e) { Object ss = postfixComboBox.getSelectedItem(); - if (ss instanceof FILEFilter) { - setFILEFilter((FILEFilter) ss); + if (ss instanceof ChooseFileFilter) { + setFILEFilter((ChooseFileFilter) ss); + fileNameTextField.setText(calProperFileName(fileNameTextField.getText(), (ChooseFileFilter) ss)); } else { setFILEFilter(null); } @@ -484,6 +488,21 @@ public class FILEChooserPane extends BasicPane { }); } + private String calProperFileName(String fileName, ChooseFileFilter fileFilter) { + if(fileFilter == null){ + return fileName; + } + String filterExtension = fileFilter.getExtensionString(); + int lastDotIndex = fileName.lastIndexOf(".") != -1 ? fileName.lastIndexOf(".") : fileName.length(); + String fileNameWithOutExtension = fileName.substring(0, lastDotIndex); + String fileNameExtension = fileName.substring(lastDotIndex); + FileExtension fileExtension = FileExtension.parse(fileNameExtension); + if (StringUtils.isEmpty(fileName) || StringUtils.isEmpty(filterExtension) || fileFilter.containsExtension(fileExtension.getExtension())) { + return fileName; + } + return fileNameWithOutExtension + filterExtension; + } + private void doCancel() { this.locationBtnPane.setPopDir(null); dialogExit(); @@ -720,7 +739,14 @@ public class FILEChooserPane extends BasicPane { if (editing == null || !editing.isChartBook()) { if (type == JFileChooser.OPEN_DIALOG) { - this.addChooseFILEFilter(new ChooseFileFilter(FRContext.getFileNodes().getSupportedTypes(), appName + Toolkit.i18nText("Fine-Design_Report_Template_File"))); + ChooseFileFilter supportedTypes = new ChooseFileFilter(FRContext.getFileNodes().getSupportedTypes(), appName + Toolkit.i18nText("Fine-Design_Report_Template_File")); + Set providers = ExtraDesignClassManager.getInstance().getArray(ReportSupportedFileUIProvider.XML_TAG); + for (ReportSupportedFileUIProvider provider : providers) { + for (FileExtension fileExtension : provider.getFileExtensions()){ + supportedTypes.addExtension(fileExtension.getExtension()); + } + } + this.addChooseFILEFilter(supportedTypes); } // ben:filefilter设置初值为cpt过滤 @@ -728,6 +754,11 @@ public class FILEChooserPane extends BasicPane { // richer:form文件 daniel 改成三个字 this.addChooseFILEFilter(new ChooseFileFilter(FileExtension.FRM, appName + Toolkit.i18nText("Fine-Design_Report_Template_File"))); + + Set providers = ExtraDesignClassManager.getInstance().getArray(ReportSupportedFileUIProvider.XML_TAG); + for (ReportSupportedFileUIProvider provider : providers) { + provider.addChooseFileFilter(this, StringUtils.EMPTY); + } } else { if (type == JFileChooser.OPEN_DIALOG) { this.addChooseFILEFilter(new ChooseFileFilter(EnumSet.of(FileExtension.XLS, FileExtension.XLSX), Toolkit.i18nText("Fine-Design_Basic_Import_Excel_Source"))); @@ -834,7 +865,8 @@ public class FILEChooserPane extends BasicPane { private void saveDialog() { String filename = fileNameTextField.getText(); - fileNameTextField.setText(calFileNameText(filename, (ChooseFileFilter) (postfixComboBox.getSelectedItem()))); + filename = calProperFileName(filename, (ChooseFileFilter) (postfixComboBox.getSelectedItem())); + fileNameTextField.setText(filename); option = OK_OPTION; FILE selectedFile = this.getSelectedFILE(); @@ -860,14 +892,6 @@ public class FILEChooserPane extends BasicPane { } } - private String calFileNameText(String currentValue, ChooseFileFilter selectFileFilter) { - if (selectFileFilter == null || StringUtils.isEmpty(selectFileFilter.getExtensionString())) { - return currentValue + this.suffix; - } else if (!currentValue.endsWith(selectFileFilter.getExtensionString())) { - return currentValue + selectFileFilter.getExtensionString(); - } - return currentValue; - } private boolean access(FILE selectedFile) { boolean access = false; diff --git a/designer-base/src/test/java/com/fr/file/FILEChooserPaneTest.java b/designer-base/src/test/java/com/fr/file/FILEChooserPaneTest.java index d3d601c288..c8431a8621 100644 --- a/designer-base/src/test/java/com/fr/file/FILEChooserPaneTest.java +++ b/designer-base/src/test/java/com/fr/file/FILEChooserPaneTest.java @@ -15,23 +15,24 @@ 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); + Reflect.on(chooserPane).set("suffix", ".cpt"); + String result1 = Reflect.on(chooserPane).call("calProperFileName", "WorkBook1.cpt", null).get(); + Assert.assertEquals("WorkBook1.cpt", result1); ChooseFileFilter chooseFileFilter1 = new ChooseFileFilter(FileExtension.CPT, StringUtils.EMPTY); - String result2 = Reflect.on(chooserPane).call("calFileNameText", "WorkBook1.cpt", chooseFileFilter1).get(); + String result2 = Reflect.on(chooserPane).call("calProperFileName", "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); + String result3 = Reflect.on(chooserPane).call("calProperFileName", "WorkBook1.cpt", chooseFileFilter2).get(); + Assert.assertEquals("WorkBook1.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); + String result4 = Reflect.on(chooserPane).call("calProperFileName", "WorkBook1.cptx", chooseFileFilter3).get(); + Assert.assertEquals("WorkBook1.cpt", result4); ChooseFileFilter chooseFileFilter5 = new ChooseFileFilter(FileExtension.CPTX, StringUtils.EMPTY); - String result5 = Reflect.on(chooserPane).call("calFileNameText", "WorkBook1.cptx", chooseFileFilter5).get(); + String result5 = Reflect.on(chooserPane).call("calProperFileName", "WorkBook1.cptx", chooseFileFilter5).get(); Assert.assertEquals("WorkBook1.cptx", result5); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index 0abafdabdd..a37a1c4665 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -957,10 +957,7 @@ public class JForm extends JTemplate implements BaseJForm { return ViewRequestConstants.REPORT_VIEW_PATH; } + protected void addChooseFILEFilter(FILEChooserPane fileChooser) { + String appName = ProductConstants.APP_NAME; + fileChooser.addChooseFILEFilter(new ChooseFileFilter(FileExtension.CPT, appName + Toolkit.i18nText("Fine-Design_Report_Template_File"))); + addExtraChooseFILEFilter(fileChooser); + } + protected void addExtraChooseFILEFilter(FILEChooserPane fileChooser){ Set providers = ExtraDesignClassManager.getInstance().getArray(ReportSupportedFileUIProvider.XML_TAG); for (ReportSupportedFileUIProvider provider : providers) {