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();
}
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"));
}
}
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();
}
});
}
Aggregations