Search in sources :

Example 1 with PromptWithOptionResult

use of org.rstudio.core.client.MessageDisplay.PromptWithOptionResult in project rstudio by rstudio.

the class WebTextInput method promptForTextWithOption.

@Override
public void promptForTextWithOption(String title, String label, String initialValue, final boolean usePasswordMask, String extraOptionPrompt, boolean extraOptionDefault, int selectionStart, int selectionLength, String okButtonCaption, final ProgressOperationWithInput<PromptWithOptionResult> okOperation, Operation cancelOperation) {
    // This variable introduces a level of pointer indirection that lets us
    // get around passing TextEntryModalDialog a reference to itself in its
    // own constructor.
    final Value<TextEntryModalDialog> pDialog = new Value<TextEntryModalDialog>(null);
    final TextEntryModalDialog dialog = new TextEntryModalDialog(title, label, initialValue, usePasswordMask, extraOptionPrompt, extraOptionDefault, false, selectionStart, selectionLength, okButtonCaption, 300, new ProgressOperationWithInput<String>() {

        @Override
        public void execute(String input, ProgressIndicator indicator) {
            PromptWithOptionResult result = new PromptWithOptionResult();
            result.input = input;
            result.extraOption = pDialog.getValue().getExtraOption();
            okOperation.execute(result, indicator);
        }
    }, cancelOperation) {

        @Override
        protected void positionAndShowDialog(final Command onCompleted) {
            setPopupPositionAndShow(new PositionCallback() {

                @Override
                public void setPosition(int offsetWidth, int offsetHeight) {
                    int left = (Window.getClientWidth() / 2) - (offsetWidth / 2);
                    int top = (Window.getClientHeight() / 2) - (offsetHeight / 2);
                    if (usePasswordMask)
                        top = 50;
                    setPopupPosition(left, top);
                    onCompleted.execute();
                }
            });
        }
    };
    pDialog.setValue(dialog, false);
    dialog.showModal();
}
Also used : TextEntryModalDialog(org.rstudio.core.client.widget.TextEntryModalDialog) Command(com.google.gwt.user.client.Command) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) Value(org.rstudio.studio.client.common.Value) PromptWithOptionResult(org.rstudio.core.client.MessageDisplay.PromptWithOptionResult)

Example 2 with PromptWithOptionResult

use of org.rstudio.core.client.MessageDisplay.PromptWithOptionResult in project rstudio by rstudio.

the class DesktopTextInput method promptForTextWithOption.

@Override
public void promptForTextWithOption(String title, String label, String initialValue, boolean usePasswordMask, String extraOptionPrompt, boolean extraOptionDefault, int selectionStart, int selectionLength, String okButtonCaption, ProgressOperationWithInput<PromptWithOptionResult> okOperation, Operation cancelOperation) {
    String result = Desktop.getFrame().promptForText(title, label, initialValue, usePasswordMask, extraOptionPrompt, extraOptionDefault, false, selectionStart, selectionLength, okButtonCaption);
    if (StringUtil.isNullOrEmpty(result)) {
        if (cancelOperation != null)
            cancelOperation.execute();
    } else {
        PromptWithOptionResult presult = new PromptWithOptionResult();
        String[] lines = result.split("\\n");
        presult.input = lines[0];
        presult.extraOption = "1".equals(lines[1]);
        okOperation.execute(presult, RStudioGinjector.INSTANCE.getGlobalDisplay().getProgressIndicator("Error"));
    }
}
Also used : PromptWithOptionResult(org.rstudio.core.client.MessageDisplay.PromptWithOptionResult)

Example 3 with PromptWithOptionResult

use of org.rstudio.core.client.MessageDisplay.PromptWithOptionResult in project rstudio by rstudio.

the class DataImportOptionsUiCsv method initEvents.

void initEvents() {
    ValueChangeHandler<String> valueChangeHandler = new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> arg0) {
            updateEnabled();
            triggerChange();
        }
    };
    ChangeHandler changeHandler = new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent arg0) {
            updateEnabled();
            triggerChange();
        }
    };
    ChangeHandler delimChangeHandler = new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent arg0) {
            if (delimiterListBox_.getSelectedValue() == "other") {
                globalDisplay_.promptForTextWithOption("Other Delimiter", "Please enter a single character delimiter.", "", false, "", false, new ProgressOperationWithInput<PromptWithOptionResult>() {

                    private void dismissAndUpdate(ProgressIndicator indicator, int newSelectIndex) {
                        lastDelimiterListBoxIndex_ = newSelectIndex;
                        delimiterListBox_.setSelectedIndex(newSelectIndex);
                        indicator.onCompleted();
                        updateEnabled();
                        triggerChange();
                    }

                    @Override
                    public void execute(PromptWithOptionResult result, ProgressIndicator indicator) {
                        String otherDelimiter = result.input;
                        if (otherDelimiter.length() != 1) {
                            globalDisplay_.showErrorMessage("Incorrect Delimiter", "The specified delimiter is not valid.");
                        } else {
                            for (int idxDelimiter = 0; idxDelimiter < delimiterListBox_.getItemCount(); idxDelimiter++) {
                                if (delimiterListBox_.getValue(idxDelimiter) == otherDelimiter) {
                                    dismissAndUpdate(indicator, idxDelimiter);
                                    return;
                                }
                            }
                            int selectedIndex = delimiterListBox_.getSelectedIndex();
                            delimiterListBox_.insertItem("Character " + otherDelimiter, otherDelimiter, selectedIndex - 1);
                            dismissAndUpdate(indicator, selectedIndex - 1);
                        }
                    }
                }, new Operation() {

                    @Override
                    public void execute() {
                        delimiterListBox_.setSelectedIndex(lastDelimiterListBoxIndex_);
                        updateEnabled();
                        triggerChange();
                    }
                });
            } else {
                lastDelimiterListBoxIndex_ = delimiterListBox_.getSelectedIndex();
                updateEnabled();
                triggerChange();
            }
        }
    };
    ValueChangeHandler<Boolean> booleanValueChangeHandler = new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
            updateEnabled();
            triggerChange();
        }
    };
    nameTextBox_.addValueChangeHandler(valueChangeHandler);
    delimiterListBox_.addChangeHandler(delimChangeHandler);
    quotesListBox_.addChangeHandler(changeHandler);
    escapeListBox_.addChangeHandler(changeHandler);
    columnNamesCheckBox_.addValueChangeHandler(booleanValueChangeHandler);
    trimSpacesCheckBox_.addValueChangeHandler(booleanValueChangeHandler);
    openDataViewerCheckBox_.addValueChangeHandler(booleanValueChangeHandler);
    naListBox_.addChangeHandler(changeHandler);
    commentListBox_.addChangeHandler(changeHandler);
    skipTextBox_.addValueChangeHandler(valueChangeHandler);
    localeButton_.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            new DataImportOptionsUiCsvLocale(new OperationWithInput<DataImportOptionsCsvLocale>() {

                @Override
                public void execute(final DataImportOptionsCsvLocale result) {
                    localeInfo_ = result;
                    updateEnabled();
                    triggerChange();
                }
            }, localeInfo_).showModal();
        }
    });
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) Operation(org.rstudio.core.client.widget.Operation) PromptWithOptionResult(org.rstudio.core.client.MessageDisplay.PromptWithOptionResult) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator)

Aggregations

PromptWithOptionResult (org.rstudio.core.client.MessageDisplay.PromptWithOptionResult)3 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 Command (com.google.gwt.user.client.Command)1 Operation (org.rstudio.core.client.widget.Operation)1 TextEntryModalDialog (org.rstudio.core.client.widget.TextEntryModalDialog)1 Value (org.rstudio.studio.client.common.Value)1