use of org.rstudio.studio.client.workbench.views.packages.model.PackageInstallContext in project rstudio by rstudio.
the class Packages method withPackageInstallContext.
private void withPackageInstallContext(final OperationWithInput<PackageInstallContext> operation) {
final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error");
indicator.onProgress("Retrieving package installation context...");
server_.getPackageInstallContext(new SimpleRequestCallback<PackageInstallContext>() {
@Override
public void onResponseReceived(PackageInstallContext context) {
indicator.onCompleted();
operation.execute(context);
}
@Override
public void onError(ServerError error) {
indicator.onError(error.getUserMessage());
}
});
}
use of org.rstudio.studio.client.workbench.views.packages.model.PackageInstallContext 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.studio.client.workbench.views.packages.model.PackageInstallContext 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);
}
});
}
Aggregations