Search in sources :

Example 1 with IFileChooser

use of org.jowidgets.api.widgets.IFileChooser 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();
    }
}
Also used : IQuestionDialogBluePrint(org.jowidgets.api.widgets.blueprint.IQuestionDialogBluePrint) DialogResult(org.jowidgets.common.types.DialogResult) Some(org.jowidgets.util.maybe.Some) ICsvExportParameter(org.jowidgets.cap.ui.api.table.ICsvExportParameter) IFileChooserBluePrint(org.jowidgets.api.widgets.blueprint.IFileChooserBluePrint) IFileChooser(org.jowidgets.api.widgets.IFileChooser) File(java.io.File) IQuestionDialog(org.jowidgets.api.widgets.IQuestionDialog)

Aggregations

File (java.io.File)1 IFileChooser (org.jowidgets.api.widgets.IFileChooser)1 IQuestionDialog (org.jowidgets.api.widgets.IQuestionDialog)1 IFileChooserBluePrint (org.jowidgets.api.widgets.blueprint.IFileChooserBluePrint)1 IQuestionDialogBluePrint (org.jowidgets.api.widgets.blueprint.IQuestionDialogBluePrint)1 ICsvExportParameter (org.jowidgets.cap.ui.api.table.ICsvExportParameter)1 DialogResult (org.jowidgets.common.types.DialogResult)1 Some (org.jowidgets.util.maybe.Some)1