use of org.rstudio.core.client.widget.Operation 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();
}
});
}
use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class EnvironmentObjects method fillEntryContents.
@Override
public void fillEntryContents(final RObjectEntry entry, final int idx, boolean drawProgress) {
entry.expanded = false;
entry.isExpanding = true;
if (drawProgress)
redrawRowSafely(idx);
observer_.fillObjectContents(entry.rObject, new Operation() {
public void execute() {
entry.expanded = true;
entry.isExpanding = false;
redrawRowSafely(idx);
}
});
}
use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class Packages method onInstallPackage.
void onInstallPackage() {
withPackageInstallContext(new OperationWithInput<PackageInstallContext>() {
@Override
public void execute(final PackageInstallContext installContext) {
if (installContext.isDefaultLibraryWriteable()) {
continueInstallPackage(installContext);
} else {
globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Create Package Library", "Would you like to create a personal library '" + installContext.getDefaultUserLibraryPath() + "' " + "to install packages into?", false, new // Yes operation
Operation() {
@Override
public void execute() {
ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error Creating Library");
server_.initDefaultUserLibrary(new VoidServerRequestCallback(indicator) {
@Override
protected void onSuccess() {
// call this function back recursively
// so we can retrieve the updated
// PackageInstallContext from the server
onInstallPackage();
}
});
}
}, new // No operation
Operation() {
@Override
public void execute() {
globalDisplay_.showMessage(MessageDialog.WARNING, "Install Packages", "Unable to install packages (default library '" + installContext.getDefaultLibraryPath() + "' is " + "not writeable)");
}
}, true);
}
}
});
}
use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class Packages method removePackage.
public void removePackage(final PackageInfo packageInfo) {
withPackageInstallContext(new OperationWithInput<PackageInstallContext>() {
@Override
public void execute(final PackageInstallContext installContext) {
final boolean usingDefaultLibrary = packageInfo.getLibrary().equals(installContext.getDefaultLibraryPath());
StringBuilder message = new StringBuilder();
message.append("Are you sure you wish to permanently uninstall the '");
message.append(packageInfo.getName() + "' package");
if (!usingDefaultLibrary) {
message.append(" from library '");
message.append(packageInfo.getLibrary());
message.append("'");
}
message.append("? This action cannot be undone.");
globalDisplay_.showYesNoMessage(MessageDialog.WARNING, "Uninstall Package ", message.toString(), new Operation() {
@Override
public void execute() {
StringBuilder command = new StringBuilder();
command.append("remove.packages(\"");
command.append(packageInfo.getName());
command.append("\"");
if (!usingDefaultLibrary) {
command.append(", lib=\"");
command.append(packageInfo.getLibrary());
command.append("\"");
}
command.append(")");
String cmd = command.toString();
events_.fireEvent(new SendToConsoleEvent(cmd, true));
}
}, true);
}
});
}
use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.
the class ProfilerEditingTarget method onActivate.
public void onActivate() {
activeProfilerEditingTarger_ = this;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
commands_.gotoProfileSource().setEnabled(hasValidPath_);
}
});
final Operation activateOperation = new Operation() {
@Override
public void execute() {
if (!htmlPathInitialized_) {
htmlPathInitialized_ = true;
htmlPath_ = getContents().getHtmlPath();
htmlLocalPath_ = getContents().getHtmlLocalPath();
isUserSaved_ = getContents().isUserSaved();
if (htmlPath_ == null) {
presenter_.buildHtmlPath(new OperationWithInput<ProfileOperationResponse>() {
@Override
public void execute(ProfileOperationResponse response) {
htmlPath_ = response.getHtmlPath();
htmlLocalPath_ = response.getHtmlLocalPath();
persistDocumentProperty("htmlPath", htmlPath_);
persistDocumentProperty("htmlLocalPath", htmlLocalPath_);
view_.showProfilePage(htmlPath_);
pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
}
}, new Operation() {
@Override
public void execute() {
server_.clearProfile(getPath(), new ServerRequestCallback<JavaScriptObject>() {
@Override
public void onResponseReceived(JavaScriptObject response) {
commands_.closeSourceDoc().execute();
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
commands_.closeSourceDoc().execute();
}
});
}
}, getPath());
} else {
view_.showProfilePage(htmlPath_);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
}
});
}
}
}
};
if (getId() != null && !SourceWindowManager.isMainSourceWindow()) {
sourceServer_.getSourceDocument(getId(), new ServerRequestCallback<SourceDocument>() {
@Override
public void onResponseReceived(SourceDocument document) {
doc_ = document;
activateOperation.execute();
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
} else {
activateOperation.execute();
}
// This shouldn't happen though.
if (commandHandlerReg_ != null) {
Debug.log("Warning: onActivate called twice without intervening onDeactivate");
commandHandlerReg_.removeHandler();
commandHandlerReg_ = null;
}
commandHandlerReg_ = commandBinder.bind(commands_, this);
}
Aggregations