Browse Source
* commit '5442e99400376bf94c2718f43c39553527241229': file extension 适配多线程同步 模块代码质量 module代码质量 文件名处理 决策报表输出后缀名 导出开关 改一下命名 异常处理 file choose pane 添加多个本地环境时的展示 f 导出参数和保存问题 fix 远程导出research/10.0
yaoh.wu
6 years ago
29 changed files with 728 additions and 633 deletions
@ -0,0 +1,223 @@
|
||||
package com.fr.design.actions.file.export; |
||||
|
||||
import com.fr.base.vcs.DesignerMode; |
||||
import com.fr.design.actions.JTemplateAction; |
||||
import com.fr.design.gui.iprogressbar.FRProgressBar; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.exception.RemoteDesignPermissionDeniedException; |
||||
import com.fr.file.FILE; |
||||
import com.fr.file.FILEChooserPane; |
||||
import com.fr.io.exporter.ExporterKey; |
||||
import com.fr.file.filter.ChooseFileFilter; |
||||
import com.fr.io.exporter.DesignExportType; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.ProductConstants; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.jodd.io.FileNameUtil; |
||||
import com.fr.workspace.WorkContext; |
||||
import com.fr.workspace.server.exporter.TemplateExportOperator; |
||||
|
||||
import javax.swing.JOptionPane; |
||||
import javax.swing.SwingWorker; |
||||
import javax.swing.UIManager; |
||||
import java.awt.event.ActionEvent; |
||||
import java.io.OutputStream; |
||||
import java.util.Map; |
||||
|
||||
public abstract class AbstractExportAction<E extends JTemplate<?, ?>> extends JTemplateAction<E> { |
||||
|
||||
private FRProgressBar progressbar; |
||||
|
||||
public AbstractExportAction(E t) { |
||||
super(t); |
||||
} |
||||
|
||||
/** |
||||
* 导出接口名 |
||||
* |
||||
* @return String scopeName |
||||
*/ |
||||
public abstract ExporterKey exportKey(); |
||||
|
||||
/** |
||||
* 导出类型 |
||||
* |
||||
* @return DesignExportType tyoe |
||||
*/ |
||||
public abstract DesignExportType exportType(); |
||||
|
||||
/** |
||||
* 目标文件过滤器 |
||||
* |
||||
* @return ChooseFileFilter filter |
||||
*/ |
||||
protected abstract ChooseFileFilter getChooseFileFilter(); |
||||
|
||||
/** |
||||
* 目标文件扩展名 |
||||
* |
||||
* @return String extensionName |
||||
*/ |
||||
protected abstract String getDefaultExtension(); |
||||
|
||||
/** |
||||
* 处理参数 |
||||
* |
||||
* @return Map para |
||||
*/ |
||||
protected abstract Map<String, Object> processParameter(); |
||||
|
||||
|
||||
/** |
||||
* 执行方法 |
||||
*/ |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
|
||||
if (!processNotSaved()) { |
||||
return; |
||||
} |
||||
|
||||
Map<String, Object> para = processParameter(); |
||||
|
||||
// 选择输入的文件
|
||||
FILEChooserPane fileChooserPane = FILEChooserPane.getMultiEnvInstance(true, false); |
||||
fileChooserPane.addChooseFILEFilter(this.getChooseFileFilter()); |
||||
|
||||
|
||||
String fileName = getTargetFileName(); |
||||
fileChooserPane.setFileNameTextField(fileName, "." + this.getDefaultExtension()); |
||||
int saveValue = fileChooserPane.showSaveDialog(DesignerContext.getDesignerFrame(), "." + this.getDefaultExtension()); |
||||
if (saveValue == FILEChooserPane.JOPTIONPANE_OK_OPTION || saveValue == FILEChooserPane.OK_OPTION) { |
||||
FILE target = fileChooserPane.getSelectedFILE(); |
||||
try { |
||||
target.mkfile(); |
||||
} catch (Exception exp) { |
||||
FineLoggerFactory.getLogger().error("Error In Make New File", exp); |
||||
} |
||||
FineLoggerFactory.getLogger().info("\"" + target.getName() + "\"" + Toolkit.i18nText("Fine-Design_Report_Prepare_Export") + "!"); |
||||
|
||||
progressbar = new FRProgressBar( |
||||
createExportWork(getSource(), target, para), |
||||
DesignerContext.getDesignerFrame(), |
||||
Toolkit.i18nText("Fine-Design_Report_Exporting"), |
||||
StringUtils.EMPTY, |
||||
0, |
||||
100); |
||||
|
||||
progressbar.start(); |
||||
} |
||||
} |
||||
|
||||
private FILE getSource() { |
||||
return this.getEditingComponent().getEditingFILE(); |
||||
} |
||||
|
||||
private String getTargetFileName() { |
||||
FILE source = getSource(); |
||||
String fileName = source.getName(); |
||||
return FileNameUtil.removeExtension(fileName); |
||||
} |
||||
|
||||
private boolean processNotSaved() { |
||||
//当前编辑的模板
|
||||
E e = getEditingComponent(); |
||||
if (!e.isALLSaved() && !DesignerMode.isVcsMode()) { |
||||
e.stopEditing(); |
||||
int returnVal = JOptionPane.showConfirmDialog( |
||||
DesignerContext.getDesignerFrame(), |
||||
Toolkit.i18nText("Fine-Design_Basic_Utils_Would_You_Like_To_Save") + " \"" + e.getEditingFILE() + "\" ?", |
||||
ProductConstants.PRODUCT_NAME, |
||||
JOptionPane.YES_NO_CANCEL_OPTION, |
||||
JOptionPane.QUESTION_MESSAGE |
||||
); |
||||
if (returnVal == JOptionPane.YES_OPTION) { |
||||
e.saveTemplate(); |
||||
FineLoggerFactory.getLogger().info( |
||||
Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", e.getEditingFILE().getName()) |
||||
); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} else { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
private SwingWorker createExportWork(final FILE source, final FILE target, final Map<String, Object> parameterMap) { |
||||
final String path = source.getPath(); |
||||
final String name = target.getName(); |
||||
|
||||
return new SwingWorker<Void, Void>() { |
||||
|
||||
@Override |
||||
protected Void doInBackground() throws Exception { |
||||
//bug 10516
|
||||
Thread.sleep(100); |
||||
try (OutputStream outputStream = target.asOutputStream()) { |
||||
this.setProgress(10); |
||||
dealExporter(outputStream, path, parameterMap); |
||||
this.setProgress(80); |
||||
outputStream.flush(); |
||||
outputStream.close(); |
||||
this.setProgress(100); |
||||
|
||||
FineLoggerFactory.getLogger().info("\"" + name + "\"" + Toolkit.i18nText("Fine-Design_Report_Finish_Export") + "!"); |
||||
JOptionPane.showMessageDialog( |
||||
DesignerContext.getDesignerFrame(), |
||||
Toolkit.i18nText("Fine-Design_Report_Exported_Successfully") + "\n" + name); |
||||
|
||||
|
||||
} catch (RemoteDesignPermissionDeniedException exp) { |
||||
this.setProgress(100); |
||||
target.closeTemplate(); |
||||
FineLoggerFactory.getLogger().error(exp.getMessage(), exp); |
||||
JOptionPane.showMessageDialog( |
||||
DesignerContext.getDesignerFrame(), |
||||
Toolkit.i18nText("Fine-Engine_Remote_Design_Permission_Denied"), |
||||
null, |
||||
JOptionPane.ERROR_MESSAGE, |
||||
UIManager.getIcon("OptionPane.errorIcon") |
||||
); |
||||
} catch (Exception exp) { |
||||
this.setProgress(100); |
||||
target.closeTemplate(); |
||||
FineLoggerFactory.getLogger().error(exp.getMessage(), exp); |
||||
JOptionPane.showMessageDialog( |
||||
DesignerContext.getDesignerFrame(), |
||||
Toolkit.i18nText("Fine-Design_Report_Export_Failed") + "\n" + path, |
||||
null, |
||||
JOptionPane.ERROR_MESSAGE, |
||||
UIManager.getIcon("OptionPane.errorIcon") |
||||
); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void done() { |
||||
progressbar.close(); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
private void dealExporter(OutputStream outputStream, String path, final Map<String, Object> para) throws Exception { |
||||
|
||||
// 没有办法处理这个 isLocal 判断,因为一个是修改参数传递结果,一个是返回值做结果
|
||||
// todo 后续想想办法
|
||||
if (WorkContext.getCurrent().isLocal()) { |
||||
WorkContext.getCurrent().get(TemplateExportOperator.class) |
||||
.export(exportKey(), exportType(), outputStream, path, para); |
||||
} else { |
||||
byte[] contents = |
||||
WorkContext.getCurrent().get(TemplateExportOperator.class) |
||||
.export(exportKey(), exportType(), null, path, para); |
||||
|
||||
outputStream.write(contents); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,4 +1,4 @@
|
||||
package com.fr.design.mainframe.actions; |
||||
package com.fr.design.actions; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.iofile.attr.MobileOnlyTemplateAttrMark; |
@ -1,4 +1,4 @@
|
||||
package com.fr.design.mainframe.actions; |
||||
package com.fr.design.actions; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.actions.UpdateAction; |
@ -1,4 +1,4 @@
|
||||
package com.fr.design.mainframe.actions; |
||||
package com.fr.design.actions; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.Parameter; |
@ -0,0 +1,77 @@
|
||||
package com.fr.design.actions.file.export; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.Parameter; |
||||
import com.fr.base.extension.FileExtension; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.JForm; |
||||
import com.fr.design.menu.KeySetUtils; |
||||
import com.fr.design.parameter.ParameterInputPane; |
||||
import com.fr.file.filter.ChooseFileFilter; |
||||
import com.fr.form.main.Form; |
||||
import com.fr.io.exporter.DesignExportScope; |
||||
import com.fr.io.exporter.DesignExportType; |
||||
import com.fr.io.exporter.ExporterKey; |
||||
import com.fr.stable.ArrayUtils; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Export Embedded. |
||||
*/ |
||||
public class EmbeddedFormExportExportAction extends AbstractExportAction<JForm> { |
||||
|
||||
|
||||
public EmbeddedFormExportExportAction(JForm jwb) { |
||||
super(jwb); |
||||
this.setMenuKeySet(KeySetUtils.EMBEDDED_EXPORT); |
||||
this.setName(getMenuKeySet().getMenuKeySetName() + "..."); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/oem/logo.png")); |
||||
} |
||||
|
||||
@Override |
||||
public ExporterKey exportKey() { |
||||
return DesignExportScope.FINE_FORM; |
||||
} |
||||
|
||||
@Override |
||||
protected String getDefaultExtension() { |
||||
return getEditingComponent().suffix().substring(1); |
||||
} |
||||
|
||||
@Override |
||||
public DesignExportType exportType() { |
||||
return DesignExportType.EMBEDDED_FORM; |
||||
} |
||||
|
||||
@Override |
||||
protected Map<String, Object> processParameter() { |
||||
// 输入参数
|
||||
final Map<String, Object> parameterMap = new HashMap<String, Object>(); |
||||
Form tpl = this.getEditingComponent().getTarget(); |
||||
|
||||
Parameter[] parameters = tpl.getParameters(); |
||||
// 检查Parameter.
|
||||
if (ArrayUtils.isNotEmpty(parameters)) { |
||||
final ParameterInputPane pPane = new ParameterInputPane(parameters); |
||||
pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { |
||||
|
||||
@Override |
||||
public void doOk() { |
||||
parameterMap.putAll(pPane.update()); |
||||
} |
||||
}).setVisible(true); |
||||
} |
||||
return parameterMap; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected ChooseFileFilter getChooseFileFilter() { |
||||
return new ChooseFileFilter(FileExtension.FRM.getExtensions(), Toolkit.i18nText("Fine-Design_Form_EmbeddedTD")); |
||||
} |
||||
} |
@ -1,155 +0,0 @@
|
||||
package com.fr.design.mainframe.actions; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.Parameter; |
||||
import com.fr.design.actions.JTemplateAction; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.gui.iprogressbar.FRProgressBar; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrame; |
||||
import com.fr.design.mainframe.JForm; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.menu.KeySetUtils; |
||||
import com.fr.design.parameter.ParameterInputPane; |
||||
import com.fr.file.FILE; |
||||
import com.fr.file.FILEChooserPane; |
||||
import com.fr.file.filter.ChooseFileFilter; |
||||
import com.fr.form.main.Form; |
||||
import com.fr.form.main.FormEmbeddedTableDataExporter; |
||||
import com.fr.log.FineLoggerFactory; |
||||
|
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.io.FileOutputStream; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Export Embedded. |
||||
*/ |
||||
public class EmbeddedFormExportExportAction extends JTemplateAction<JForm>{ |
||||
|
||||
private FRProgressBar progressbar; |
||||
/** |
||||
* Constructor |
||||
*/ |
||||
public EmbeddedFormExportExportAction(JForm jwb) { |
||||
super(jwb); |
||||
this.setMenuKeySet(KeySetUtils.EMBEDDED_EXPORT); |
||||
this.setName(getMenuKeySet().getMenuKeySetName() + "..."); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/oem/logo.png")); |
||||
} |
||||
|
||||
/** |
||||
* Action触发事件 |
||||
* |
||||
* @param e 触发事件 |
||||
* |
||||
*/ |
||||
public void actionPerformed(ActionEvent e) { |
||||
JTemplate jwb = this.getEditingComponent(); |
||||
FILE editingFILE = jwb.getEditingFILE(); |
||||
DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); |
||||
|
||||
final Map<String, Object> parameterMap = new HashMap<String, Object>(); |
||||
final Form tpl = this.getEditingComponent().getTarget(); |
||||
inputParameter(parameterMap, tpl, designerFrame); |
||||
|
||||
FILEChooserPane fileChooserPane = FILEChooserPane.getInstance(false, true); |
||||
fileChooserPane.setFILEFilter(this.getChooseFileFilter()); |
||||
|
||||
String filenName = editingFILE.getName(); |
||||
fileChooserPane.setFileNameTextField(filenName, ProjectConstants.FRM_SUFFIX); |
||||
int saveValue = fileChooserPane.showSaveDialog(designerFrame, ProjectConstants.FRM_SUFFIX); |
||||
if (isCancel(saveValue)) { |
||||
fileChooserPane = null; |
||||
return; |
||||
} |
||||
|
||||
if (isOk(saveValue)) { |
||||
startExport(parameterMap, tpl, designerFrame, fileChooserPane); |
||||
} |
||||
} |
||||
|
||||
private void startExport(Map<String, Object> parameterMap, Form tpl, DesignerFrame designerFrame, |
||||
FILEChooserPane fileChooserPane){ |
||||
FILE file = fileChooserPane.getSelectedFILE(); |
||||
try { |
||||
file.mkfile(); |
||||
} catch (Exception e1) { |
||||
FineLoggerFactory.getLogger().error("Error In Make New File"); |
||||
} |
||||
fileChooserPane = null; |
||||
FRContext.getLogger().info("\"" + file.getName() + "\"" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Prepare_Export") + "!"); |
||||
|
||||
(progressbar = new FRProgressBar(createExportWork(file, tpl, parameterMap), designerFrame, |
||||
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Exporting"), "", 0, 100)).start(); |
||||
} |
||||
|
||||
private boolean isOk(int saveValue){ |
||||
return saveValue == FILEChooserPane.JOPTIONPANE_OK_OPTION || saveValue == FILEChooserPane.OK_OPTION; |
||||
} |
||||
|
||||
private boolean isCancel(int saveValue){ |
||||
return saveValue == FILEChooserPane.CANCEL_OPTION || saveValue == FILEChooserPane.JOPTIONPANE_CANCEL_OPTION; |
||||
} |
||||
|
||||
private void inputParameter(final Map<String, Object> parameterMap, final Form tpl, DesignerFrame designerFrame){ |
||||
Parameter[] parameters = tpl.getParameters(); |
||||
if (ArrayUtils.isNotEmpty(parameters)) {// 检查Parameter.
|
||||
final ParameterInputPane pPane = new ParameterInputPane(parameters); |
||||
pPane.showSmallWindow(designerFrame, new DialogActionAdapter() { |
||||
|
||||
@Override |
||||
public void doOk() { |
||||
parameterMap.putAll(pPane.update()); |
||||
} |
||||
}).setVisible(true); |
||||
} |
||||
} |
||||
|
||||
protected ChooseFileFilter getChooseFileFilter() { |
||||
return new ChooseFileFilter(new String[]{"frm"}, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_EmbeddedTD")); |
||||
} |
||||
|
||||
private SwingWorker createExportWork(FILE file, final Form tpl, final Map parameterMap) { |
||||
final String filePath = file.getPath(); |
||||
final String fileGetName = file.getName(); |
||||
|
||||
SwingWorker exportWorker = new SwingWorker<Void, Void>() { |
||||
protected Void doInBackground() throws Exception { |
||||
Thread.sleep(100); |
||||
try { |
||||
final FileOutputStream fileOutputStream = new FileOutputStream(filePath); |
||||
|
||||
this.setProgress(10); |
||||
FormEmbeddedTableDataExporter exporter = new FormEmbeddedTableDataExporter(); |
||||
exporter.export(fileOutputStream, tpl, parameterMap); |
||||
this.setProgress(80); |
||||
fileOutputStream.close(); |
||||
this.setProgress(100); |
||||
|
||||
FRContext.getLogger().info("\"" + fileGetName + "\"" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Finish_Export") + "!"); |
||||
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), |
||||
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Exported_Successfully") + "\n" + fileGetName); |
||||
} catch (Exception exp) { |
||||
this.setProgress(100); |
||||
FineLoggerFactory.getLogger().error(exp.getMessage(), exp); |
||||
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Export_Failed") + "\n" + filePath); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public void done() { |
||||
progressbar.close(); |
||||
} |
||||
}; |
||||
return exportWorker; |
||||
} |
||||
|
||||
} |
@ -1,196 +0,0 @@
|
||||
/* |
||||
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||
*/ |
||||
package com.fr.design.actions.file.export; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.Parameter; |
||||
import com.fr.design.actions.JWorkBookAction; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.gui.iprogressbar.FRProgressBar; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrame; |
||||
import com.fr.design.mainframe.JWorkBook; |
||||
import com.fr.design.parameter.ParameterInputPane; |
||||
import com.fr.file.FILE; |
||||
import com.fr.file.FILEChooserPane; |
||||
import com.fr.file.filter.ChooseFileFilter; |
||||
import com.fr.log.FineLoggerFactory; |
||||
|
||||
import com.fr.io.exporter.AppExporter; |
||||
import com.fr.io.exporter.CSVExporter; |
||||
import com.fr.io.exporter.EmbeddedTableDataExporter; |
||||
import com.fr.io.exporter.ExcelExporter; |
||||
import com.fr.io.exporter.Exporter; |
||||
import com.fr.io.exporter.PDFExporterProcessor; |
||||
import com.fr.io.exporter.WordExporter; |
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.main.impl.WorkBook; |
||||
import com.fr.page.PageSetProvider; |
||||
import com.fr.report.ReportHelper; |
||||
import com.fr.report.core.ReportUtils; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.worksheet.WorkSheet; |
||||
import com.fr.stable.ActorConstants; |
||||
import com.fr.stable.ActorFactory; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.io.OutputStream; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Abstract export action. |
||||
*/ |
||||
public abstract class AbstractExportAction extends JWorkBookAction { |
||||
protected AbstractExportAction(JWorkBook jwb) { |
||||
super(jwb); |
||||
} |
||||
|
||||
private FRProgressBar progressbar; |
||||
|
||||
protected WorkBook getTemplateWorkBook() { |
||||
return this.getEditingComponent().getTarget(); |
||||
} |
||||
|
||||
/** |
||||
* 执行方法 |
||||
*/ |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
JWorkBook jwb = this.getEditingComponent(); |
||||
FILE editingFILE = jwb.getEditingFILE(); |
||||
DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); |
||||
|
||||
// 弹出参数
|
||||
final java.util.Map parameterMap = new java.util.HashMap(); |
||||
final TemplateWorkBook tpl = getTemplateWorkBook(); |
||||
Parameter[] parameters = tpl.getParameters(); |
||||
if (parameters != null && parameters.length > 0) {// 检查Parameter.
|
||||
final ParameterInputPane pPane = new ParameterInputPane( |
||||
parameters); |
||||
pPane.showSmallWindow(designerFrame, new DialogActionAdapter() { |
||||
|
||||
@Override |
||||
public void doOk() { |
||||
parameterMap.putAll(pPane.update()); |
||||
} |
||||
}).setVisible(true); |
||||
} |
||||
|
||||
// Choose a file name....
|
||||
FILEChooserPane fileChooserPane = FILEChooserPane.getInstance(true, true); |
||||
fileChooserPane.addChooseFILEFilter(this.getChooseFileFilter()); |
||||
|
||||
// 打开文件后输出文件名修改,eg:w.cpt.doc / w.svg.doc,去掉中间的后缀名~~ w.doc
|
||||
String filenName = editingFILE.getName(); |
||||
if (filenName.indexOf('.') != -1) { |
||||
filenName = filenName.substring(0, editingFILE.getName().lastIndexOf('.')); |
||||
} |
||||
fileChooserPane.setFileNameTextField(filenName, "." + this.getDefaultExtension()); |
||||
int saveValue = fileChooserPane.showSaveDialog(designerFrame, "." + this.getDefaultExtension()); |
||||
if (saveValue == FILEChooserPane.CANCEL_OPTION || saveValue == FILEChooserPane.JOPTIONPANE_CANCEL_OPTION) { |
||||
fileChooserPane = null; |
||||
return; |
||||
} else if (saveValue == FILEChooserPane.JOPTIONPANE_OK_OPTION || saveValue == FILEChooserPane.OK_OPTION) { |
||||
FILE file = fileChooserPane.getSelectedFILE(); |
||||
try { |
||||
file.mkfile(); |
||||
} catch (Exception e1) { |
||||
FineLoggerFactory.getLogger().error("Error In Make New File"); |
||||
} |
||||
fileChooserPane = null; |
||||
FRContext.getLogger().info("\"" + file.getName() + "\"" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Prepare_Export") + "!"); |
||||
|
||||
(progressbar = new FRProgressBar(createExportWork(file, tpl, parameterMap), designerFrame, |
||||
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Exporting"), "", 0, 100)).start(); |
||||
} |
||||
} |
||||
|
||||
private SwingWorker createExportWork(final FILE file, final TemplateWorkBook tpl, final Map parameterMap) { |
||||
final String filePath = file.getPath(); |
||||
final String fileGetName = file.getName(); |
||||
|
||||
SwingWorker exportWorker = new SwingWorker<Void, Void>() { |
||||
|
||||
@Override |
||||
protected Void doInBackground() throws Exception { |
||||
Thread.sleep(100); //bug 10516
|
||||
try { |
||||
OutputStream outputStream = file.asOutputStream(); |
||||
|
||||
this.setProgress(10); |
||||
dealExporter(outputStream, tpl, parameterMap); |
||||
this.setProgress(80); |
||||
outputStream.flush(); |
||||
outputStream.close(); |
||||
this.setProgress(100); |
||||
|
||||
FRContext.getLogger().info("\"" + fileGetName + "\"" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Finish_Export") + "!"); |
||||
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), |
||||
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Exported_Successfully") + "\n" + fileGetName); |
||||
} catch (Exception exp) { |
||||
this.setProgress(100); |
||||
FineLoggerFactory.getLogger().error(exp.getMessage(), exp); |
||||
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Export_Failed") + "\n" + filePath, |
||||
null, 0, UIManager.getIcon("OptionPane.errorIcon")); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void done() { |
||||
progressbar.close(); |
||||
} |
||||
}; |
||||
return exportWorker; |
||||
} |
||||
|
||||
private void dealExporter(OutputStream outputStream, final TemplateWorkBook tpl, final Map parameterMap) throws Exception { |
||||
final Exporter exporter = AbstractExportAction.this.getExporter(); |
||||
if (exporter instanceof AppExporter) { |
||||
AppExporter appExporter = (AppExporter) exporter; |
||||
if (exporter instanceof ExcelExporter || exporter instanceof CSVExporter |
||||
|| exporter instanceof PDFExporterProcessor || exporter instanceof WordExporter) { |
||||
ReportHelper.clearFormulaResult(tpl);// 清空rpt中的公式计算结果
|
||||
|
||||
appExporter.export(outputStream, tpl.execute(parameterMap, ActorFactory.getActor(ActorConstants.TYPE_PAGE) |
||||
)); |
||||
} else { |
||||
ReportHelper.clearFormulaResult(tpl);// 清空currentReport中的公式计算结果
|
||||
|
||||
PageSetProvider pageSet = tpl.execute(parameterMap, ActorFactory.getActor(ActorConstants.TYPE_PAGE)).generateReportPageSet( |
||||
ReportUtils.getPaperSettingListFromWorkBook(tpl)).traverse4Export(); |
||||
appExporter.export(outputStream, pageSet); |
||||
pageSet.release(); |
||||
} |
||||
} else if (exporter instanceof EmbeddedTableDataExporter) { |
||||
((EmbeddedTableDataExporter) exporter).export(outputStream, (WorkBook) tpl, parameterMap); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* 这边判断是否有层式报表,有层式需要使用大数据量导出 |
||||
*/ |
||||
protected boolean hasLayerReport(TemplateWorkBook tpl) { |
||||
if (tpl == null) { |
||||
return false; |
||||
} |
||||
for (int i = 0; i < tpl.getReportCount(); i++) { |
||||
Report r = tpl.getReport(i); |
||||
if (r instanceof WorkSheet) { |
||||
if (((WorkSheet) r).getLayerReportAttr() != null) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
protected abstract ChooseFileFilter getChooseFileFilter(); |
||||
|
||||
protected abstract String getDefaultExtension(); |
||||
|
||||
protected abstract Exporter getExporter(); |
||||
} |
@ -0,0 +1,57 @@
|
||||
/* |
||||
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||
*/ |
||||
package com.fr.design.actions.file.export; |
||||
|
||||
import com.fr.base.Parameter; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.JWorkBook; |
||||
import com.fr.design.parameter.ParameterInputPane; |
||||
import com.fr.io.exporter.ExporterKey; |
||||
import com.fr.io.exporter.DesignExportScope; |
||||
import com.fr.main.TemplateWorkBook; |
||||
import com.fr.main.impl.WorkBook; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Abstract export action. |
||||
*/ |
||||
public abstract class AbstractWorkBookExportAction extends AbstractExportAction<JWorkBook> { |
||||
|
||||
|
||||
protected AbstractWorkBookExportAction(JWorkBook jwb) { |
||||
super(jwb); |
||||
} |
||||
|
||||
|
||||
protected WorkBook getTemplateWorkBook() { |
||||
return this.getEditingComponent().getTarget(); |
||||
} |
||||
|
||||
public ExporterKey exportKey() { |
||||
return DesignExportScope.FINE_BOOK; |
||||
} |
||||
|
||||
@Override |
||||
protected Map<String, Object> processParameter() { |
||||
// 弹出参数
|
||||
final Map<String, Object> parameterMap = new HashMap<>(); |
||||
final TemplateWorkBook tpl = getTemplateWorkBook(); |
||||
Parameter[] parameters = tpl.getParameters(); |
||||
// 检查Parameter
|
||||
if (parameters != null && parameters.length > 0) { |
||||
final ParameterInputPane pPane = new ParameterInputPane( |
||||
parameters); |
||||
pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { |
||||
@Override |
||||
public void doOk() { |
||||
parameterMap.putAll(pPane.update()); |
||||
} |
||||
}).setVisible(true); |
||||
} |
||||
return parameterMap; |
||||
} |
||||
} |
Loading…
Reference in new issue