Search in sources :

Example 1 with TextEntryModalDialog

use of org.rstudio.core.client.widget.TextEntryModalDialog 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)

Aggregations

Command (com.google.gwt.user.client.Command)1 PromptWithOptionResult (org.rstudio.core.client.MessageDisplay.PromptWithOptionResult)1 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)1 TextEntryModalDialog (org.rstudio.core.client.widget.TextEntryModalDialog)1 Value (org.rstudio.studio.client.common.Value)1