Search in sources :

Example 1 with IQuestionDialog

use of org.jowidgets.api.widgets.IQuestionDialog 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)

Example 2 with IQuestionDialog

use of org.jowidgets.api.widgets.IQuestionDialog in project jo-client-platform by jo-source.

the class DataModelContextImpl method shouldDataBeSaved.

private QuestionResult shouldDataBeSaved() {
    final IQuestionDialogBluePrint dialogBp = BPF.questionDialog();
    dialogBp.setTitle(UNSAVED_DATA_TITLE.get());
    dialogBp.setText(UNSAVED_DATA_TEXT.get());
    dialogBp.setYesButton(BPF.button(UNSAVED_DATA_YES_BTN.get()));
    dialogBp.setNoButton(BPF.button(UNSAVED_DATA_NO_BTN.get()));
    dialogBp.setCancelButton(BPF.button(UNSAVED_DATA_CANCEL_BTN.get()));
    dialogBp.setDefaultResult(QuestionResult.YES);
    final IQuestionDialog dialog = Toolkit.getActiveWindow().createChildWindow(dialogBp);
    return dialog.question();
}
Also used : IQuestionDialogBluePrint(org.jowidgets.api.widgets.blueprint.IQuestionDialogBluePrint) IQuestionDialog(org.jowidgets.api.widgets.IQuestionDialog)

Example 3 with IQuestionDialog

use of org.jowidgets.api.widgets.IQuestionDialog in project jo-client-platform by jo-source.

the class DataModelContextImpl method shouldDataBeRefused.

private boolean shouldDataBeRefused() {
    final IQuestionDialogBluePrint dialogBp = BPF.questionDialog();
    dialogBp.setTitle(UNSAVED_INVALID_DATA_TITLE.get());
    dialogBp.setText(UNSAVED_INVALID_DATA_TEXT.get());
    dialogBp.setYesButton(BPF.button(UNSAVED_INVALID_DATA_YES_BTN.get()));
    dialogBp.setNoButton(BPF.button(UNSAVED_INVALID_DATA_NO_BTN.get()));
    final IQuestionDialog dialog = Toolkit.getActiveWindow().createChildWindow(dialogBp);
    final QuestionResult questionResult = dialog.question();
    if (QuestionResult.YES == questionResult) {
        return true;
    } else {
        return false;
    }
}
Also used : IQuestionDialogBluePrint(org.jowidgets.api.widgets.blueprint.IQuestionDialogBluePrint) IQuestionDialog(org.jowidgets.api.widgets.IQuestionDialog) QuestionResult(org.jowidgets.api.types.QuestionResult)

Aggregations

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