use of org.jowidgets.common.types.DialogResult in project jo-client-platform by jo-source.
the class CsvExportFileParameterProvider method getParameter.
@Override
public IMaybe<ICsvExportParameter> getParameter(final IExecutionContext executionContext, final List<IBeanProxy<BEAN_TYPE>> beans, final ICsvExportParameter defaultParameter) throws Exception {
final IFileChooserBluePrint fileChooserBp = BPF.fileChooser(FileChooserType.SAVE).setFilterList(filterList);
final IFileChooser fileChooser = Toolkit.getActiveWindow().createChildWindow(fileChooserBp);
fileChooser.setSelectedFile(new File(filename));
final DialogResult result = fileChooser.open();
if (result == DialogResult.OK) {
for (final File file : fileChooser.getSelectedFiles()) {
filename = file.getAbsolutePath();
}
if (!filename.contains(fileChooser.getSelectedFilter().getExtensions().get(0))) {
filename = filename + "." + fileChooser.getSelectedFilter().getExtensions().get(0);
}
if (EmptyCheck.isEmpty(filename)) {
Toolkit.getMessagePane().showInfo(executionContext, Messages.getString("CsvExportFileParameterProvider.no_file_choosen"));
return Nothing.getInstance();
}
if (!checkFileType(filename.substring(filename.length() - 3))) {
Toolkit.getMessagePane().showError(executionContext, Messages.getString("CsvExportFileParameterProvider.incompatible_file"));
return Nothing.getInstance();
}
final File file = new File(filename);
if (file.exists()) {
final String question = Messages.getString("CsvExportFileParameterProvider.file_overwritten");
final IQuestionDialogBluePrint dialogBp = BPF.questionDialog();
dialogBp.setTitle(executionContext.getAction().getText());
dialogBp.setIcon(executionContext.getAction().getIcon());
dialogBp.setIcon(Icons.WARNING);
dialogBp.setText(MessageReplacer.replace(question, file.getName()));
dialogBp.setDefaultResult(QuestionResult.NO);
final IQuestionDialog dialog = Toolkit.getActiveWindow().createChildWindow(dialogBp);
if (!QuestionResult.YES.equals(dialog.question())) {
return Nothing.getInstance();
}
}
return new Some<ICsvExportParameter>(new CsvExportParameter(defaultParameter.getExportType(), defaultParameter.isExportHeader(), defaultParameter.isExportInvisibleProperties(), defaultParameter.getSeparator(), defaultParameter.getMask(), defaultParameter.getEncoding(), filename));
} else {
return Nothing.getInstance();
}
}
Aggregations