Browse Source

导出参数和保存问题

research/10.0
yaoh.wu 6 years ago
parent
commit
89f1c7b2f9
  1. 192
      designer-base/src/main/java/com/fr/design/actions/file/export/AbstractExportAction.java
  2. 128
      designer-form/src/main/java/com/fr/design/actions/file/export/EmbeddedFormExportExportAction.java
  3. 131
      designer-realize/src/main/java/com/fr/design/actions/file/export/AbstractJWorkBookExportAction.java

192
designer-base/src/main/java/com/fr/design/actions/file/export/AbstractExportAction.java

@ -1,20 +1,212 @@
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.file.FILE;
import com.fr.file.FILEChooserPane;
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.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 String exportScopeName();
/**
* 导出类型
*
* @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.getInstance(true, true);
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();
// 打开文件后输出文件名修改,eg:w.cpt.doc / w.svg.doc,去掉中间的后缀名~~ w.doc
String fileName = source.getName();
if (fileName.indexOf('.') != -1) {
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
}
return 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 (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(exportScopeName(), exportType(), outputStream, path, para);
} else {
byte[] contents =
WorkContext.getCurrent().get(TemplateExportOperator.class)
.export(exportScopeName(), exportType(), null, path, para);
outputStream.write(contents);
}
}
}

128
designer-form/src/main/java/com/fr/design/actions/file/export/EmbeddedFormExportExportAction.java

@ -3,30 +3,17 @@ package com.fr.design.actions.file.export;
import com.fr.base.BaseUtils;
import com.fr.base.Parameter;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.iprogressbar.FRProgressBar;
import com.fr.design.i18n.Toolkit;
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.io.exporter.DesignExportType;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.exporter.TemplateExportOperator;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import java.awt.event.ActionEvent;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
@ -35,7 +22,6 @@ import java.util.Map;
*/
public class EmbeddedFormExportExportAction extends AbstractExportAction<JForm> {
private FRProgressBar progressbar;
public EmbeddedFormExportExportAction(JForm jwb) {
super(jwb);
@ -50,72 +36,27 @@ public class EmbeddedFormExportExportAction extends AbstractExportAction<JForm>
return "FINE_FORM";
}
@Override
protected String getDefaultExtension() {
return ProjectConstants.FRM_SUFFIX;
}
@Override
public DesignExportType exportType() {
return DesignExportType.EMBEDDED_FORM;
}
/**
* Action触发事件
*
* @param e 触发事件
*/
@Override
public void actionPerformed(ActionEvent e) {
// todo 提示保存
JTemplate jwb = this.getEditingComponent();
FILE source = jwb.getEditingFILE();
protected Map<String, Object> processParameter() {
// 输入参数
final Map<String, Object> parameterMap = new HashMap<String, Object>();
final Form tpl = this.getEditingComponent().getTarget();
inputParameter(parameterMap, tpl, DesignerContext.getDesignerFrame());
FILEChooserPane fileChooserPane = FILEChooserPane.getInstance(false, true);
fileChooserPane.setFILEFilter(this.getChooseFileFilter());
String fileName = source.getName();
fileChooserPane.setFileNameTextField(fileName, ProjectConstants.FRM_SUFFIX);
int saveValue = fileChooserPane.showSaveDialog(DesignerContext.getDesignerFrame(), ProjectConstants.FRM_SUFFIX);
if (isOk(saveValue)) {
startExport(source, parameterMap, fileChooserPane);
}
}
private void startExport(FILE source, Map<String, Object> parameterMap,
FILEChooserPane fileChooserPane) {
FILE target = fileChooserPane.getSelectedFILE();
try {
target.mkfile();
} catch (Exception e1) {
FineLoggerFactory.getLogger().error("Error In Make New File");
}
FineLoggerFactory.getLogger().info("\"" + target.getName() + "\"" + Toolkit.i18nText("Fine-Design_Report_Prepare_Export") + "!");
(progressbar =
new FRProgressBar(
createExportWork(source, target, parameterMap),
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Report_Exporting"),
StringUtils.EMPTY,
0,
100)
).start();
}
private boolean isOk(int saveValue) {
return saveValue == FILEChooserPane.JOPTIONPANE_OK_OPTION || saveValue == FILEChooserPane.OK_OPTION;
}
Form tpl = this.getEditingComponent().getTarget();
private void inputParameter(final Map<String, Object> parameterMap, final Form tpl, DesignerFrame designerFrame) {
Parameter[] parameters = tpl.getParameters();
// 检查Parameter.
if (ArrayUtils.isNotEmpty(parameters)) {
final ParameterInputPane pPane = new ParameterInputPane(parameters);
pPane.showSmallWindow(designerFrame, new DialogActionAdapter() {
pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() {
@Override
public void doOk() {
@ -123,61 +64,12 @@ public class EmbeddedFormExportExportAction extends AbstractExportAction<JForm>
}
}).setVisible(true);
}
return parameterMap;
}
@Override
protected ChooseFileFilter getChooseFileFilter() {
return new ChooseFileFilter(new String[]{"frm"}, Toolkit.i18nText("Fine-Design_Form_EmbeddedTD"));
}
private SwingWorker createExportWork(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 {
Thread.sleep(100);
try (OutputStream fileOutputStream = target.asOutputStream()) {
this.setProgress(10);
dealExporter(fileOutputStream, path, parameterMap);
this.setProgress(80);
fileOutputStream.flush();
fileOutputStream.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 (Exception exp) {
this.setProgress(100);
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Report_Export_Failed") + "\n" + path);
}
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(exportScopeName(), exportType(), outputStream, path, para);
} else {
byte[] contents =
WorkContext.getCurrent().get(TemplateExportOperator.class)
.export(exportScopeName(), exportType(), null, path, para);
outputStream.write(contents);
}
}
}

131
designer-realize/src/main/java/com/fr/design/actions/file/export/AbstractJWorkBookExportAction.java

@ -5,25 +5,12 @@ package com.fr.design.actions.file.export;
import com.fr.base.Parameter;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.iprogressbar.FRProgressBar;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
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.log.FineLoggerFactory;
import com.fr.main.TemplateWorkBook;
import com.fr.main.impl.WorkBook;
import com.fr.stable.StringUtils;
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.HashMap;
import java.util.Map;
@ -32,7 +19,6 @@ import java.util.Map;
*/
public abstract class AbstractJWorkBookExportAction extends AbstractExportAction<JWorkBook> {
private FRProgressBar progressbar;
protected AbstractJWorkBookExportAction(JWorkBook jwb) {
super(jwb);
@ -43,128 +29,27 @@ public abstract class AbstractJWorkBookExportAction extends AbstractExportAction
return this.getEditingComponent().getTarget();
}
/**
* 执行方法
*/
@Override
public void actionPerformed(ActionEvent e) {
// todo 弹出提醒保存,如果没保存。。。
JWorkBook jwb = this.getEditingComponent();
FILE source = jwb.getEditingFILE();
public String exportScopeName() {
return "FINE_BOOK";
}
@Override
protected Map<String, Object> processParameter() {
// 弹出参数
final Map<String, Object> parameterMap = new HashMap<>();
final TemplateWorkBook tpl = getTemplateWorkBook();
Parameter[] parameters = tpl.getParameters();
if (parameters != null && parameters.length > 0) {// 检查Parameter.
// 检查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);
}
// file choose
FILEChooserPane fileChooserPane = FILEChooserPane.getInstance(true, true);
fileChooserPane.addChooseFILEFilter(this.getChooseFileFilter());
// 打开文件后输出文件名修改,eg:w.cpt.doc / w.svg.doc,去掉中间的后缀名~~ w.doc
String fileName = source.getName();
if (fileName.indexOf('.') != -1) {
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
}
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(source, target, parameterMap),
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Report_Exporting"),
StringUtils.EMPTY,
0,
100)
).start();
}
}
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 (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(exportScopeName(), exportType(), outputStream, path, para);
} else {
byte[] contents =
WorkContext.getCurrent().get(TemplateExportOperator.class)
.export(exportScopeName(), exportType(), null, path, para);
outputStream.write(contents);
}
}
protected abstract String getDefaultExtension();
public String exportScopeName() {
return "FINE_BOOK";
return parameterMap;
}
}

Loading…
Cancel
Save