Search in sources :

Example 1 with PackageInstallContext

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());
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) PackageInstallContext(org.rstudio.studio.client.workbench.views.packages.model.PackageInstallContext)

Example 2 with PackageInstallContext

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);
            }
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) Operation(org.rstudio.core.client.widget.Operation) PackageInstallContext(org.rstudio.studio.client.workbench.views.packages.model.PackageInstallContext)

Example 3 with PackageInstallContext

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);
        }
    });
}
Also used : SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) Operation(org.rstudio.core.client.widget.Operation) PackageInstallContext(org.rstudio.studio.client.workbench.views.packages.model.PackageInstallContext)

Aggregations

PackageInstallContext (org.rstudio.studio.client.workbench.views.packages.model.PackageInstallContext)3 Operation (org.rstudio.core.client.widget.Operation)2 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)2 ServerError (org.rstudio.studio.client.server.ServerError)1 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)1 SendToConsoleEvent (org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)1