Search in sources :

Example 21 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class ApplicationQuit method handleUnsavedChanges.

public static void handleUnsavedChanges(final int saveAction, String caption, boolean forceSaveAll, final SourceShim sourceShim, final WorkbenchContext workbenchContext, final UnsavedChangesTarget globalEnvTarget, final QuitContext quitContext) {
    // see what the unsaved changes situation is and prompt accordingly
    ArrayList<UnsavedChangesTarget> unsavedSourceDocs = sourceShim.getUnsavedChanges(Source.TYPE_FILE_BACKED);
    // force save all
    if (forceSaveAll) {
        // save all unsaved documents and then quit
        sourceShim.handleUnsavedChangesBeforeExit(unsavedSourceDocs, new Command() {

            @Override
            public void execute() {
                boolean saveChanges = saveAction != SaveAction.NOSAVE;
                quitContext.onReadyToQuit(saveChanges);
            }
        });
        return;
    } else // no unsaved changes at all
    if (saveAction != SaveAction.SAVEASK && unsavedSourceDocs.size() == 0) {
        // define quit operation
        final Operation quitOperation = new Operation() {

            public void execute() {
                quitContext.onReadyToQuit(saveAction == SaveAction.SAVE);
            }
        };
        // if this is a quit session then we always prompt
        if (ApplicationAction.isQuit()) {
            RStudioGinjector.INSTANCE.getGlobalDisplay().showYesNoMessage(MessageDialog.QUESTION, caption, "Are you sure you want to quit the R session?", quitOperation, true);
        } else {
            quitOperation.execute();
        }
        return;
    }
    // just an unsaved environment
    if (unsavedSourceDocs.size() == 0 && workbenchContext != null) {
        // confirm quit and do it
        String prompt = "Save workspace image to " + workbenchContext.getREnvironmentPath() + "?";
        RStudioGinjector.INSTANCE.getGlobalDisplay().showYesNoMessage(GlobalDisplay.MSG_QUESTION, caption, prompt, true, new Operation() {

            public void execute() {
                quitContext.onReadyToQuit(true);
            }
        }, new Operation() {

            public void execute() {
                quitContext.onReadyToQuit(false);
            }
        }, new Operation() {

            public void execute() {
            }
        }, "Save", "Don't Save", true);
    } else // must be from the main window in web mode)
    if (saveAction != SaveAction.SAVEASK && unsavedSourceDocs.size() == 1 && (Desktop.isDesktop() || !(unsavedSourceDocs.get(0) instanceof UnsavedChangesItem))) {
        sourceShim.saveWithPrompt(unsavedSourceDocs.get(0), sourceShim.revertUnsavedChangesBeforeExitCommand(new Command() {

            @Override
            public void execute() {
                quitContext.onReadyToQuit(saveAction == SaveAction.SAVE);
            }
        }), null);
    } else // multiple save targets
    {
        ArrayList<UnsavedChangesTarget> unsaved = new ArrayList<UnsavedChangesTarget>();
        if (saveAction == SaveAction.SAVEASK && globalEnvTarget != null)
            unsaved.add(globalEnvTarget);
        unsaved.addAll(unsavedSourceDocs);
        new UnsavedChangesDialog(caption, unsaved, new OperationWithInput<UnsavedChangesDialog.Result>() {

            @Override
            public void execute(Result result) {
                ArrayList<UnsavedChangesTarget> saveTargets = result.getSaveTargets();
                // remote global env target from list (if specified) and 
                // compute the saveChanges value
                boolean saveGlobalEnv = saveAction == SaveAction.SAVE;
                if (saveAction == SaveAction.SAVEASK && globalEnvTarget != null)
                    saveGlobalEnv = saveTargets.remove(globalEnvTarget);
                final boolean saveChanges = saveGlobalEnv;
                // save specified documents and then quit
                sourceShim.handleUnsavedChangesBeforeExit(saveTargets, new Command() {

                    @Override
                    public void execute() {
                        quitContext.onReadyToQuit(saveChanges);
                    }
                });
            }
        }, // no cancel operation
        null).showModal();
    }
}
Also used : UnsavedChangesItem(org.rstudio.studio.client.workbench.model.UnsavedChangesItem) UnsavedChangesDialog(org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) Command(com.google.gwt.user.client.Command) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) ArrayList(java.util.ArrayList) Operation(org.rstudio.core.client.widget.Operation) Result(org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result)

Example 22 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class ApplicationQuit method onSuspendAndRestart.

@Override
public void onSuspendAndRestart(final SuspendAndRestartEvent event) {
    // Ignore nested restarts once restart starts
    if (suspendingAndRestarting_)
        return;
    // set restart pending for desktop
    setPendinqQuit(DesktopFrame.PENDING_QUIT_AND_RESTART);
    final TimedProgressIndicator progress = new TimedProgressIndicator(globalDisplay_.getProgressIndicator("Error"));
    progress.onTimedProgress("Restarting R", 1000);
    final Operation onRestartComplete = new Operation() {

        @Override
        public void execute() {
            suspendingAndRestarting_ = false;
            progress.onCompleted();
        }
    };
    // perform the suspend and restart
    suspendingAndRestarting_ = true;
    eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_INITIATED));
    server_.suspendForRestart(event.getSuspendOptions(), new VoidServerRequestCallback() {

        @Override
        protected void onSuccess() {
            // send pings until the server restarts
            sendPing(event.getAfterRestartCommand(), 200, 25, new Command() {

                @Override
                public void execute() {
                    onRestartComplete.execute();
                    eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_COMPLETED));
                }
            });
        }

        @Override
        protected void onFailure() {
            onRestartComplete.execute();
            eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_COMPLETED));
            setPendinqQuit(DesktopFrame.PENDING_QUIT_NONE);
        }
    });
}
Also used : TimedProgressIndicator(org.rstudio.studio.client.common.TimedProgressIndicator) Command(com.google.gwt.user.client.Command) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) RestartStatusEvent(org.rstudio.studio.client.application.events.RestartStatusEvent) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) Operation(org.rstudio.core.client.widget.Operation)

Example 23 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class DependencyManager method withShiny.

public void withShiny(final String userAction, final Command command) {
    // create user prompt command
    CommandWith2Args<String, Command> userPrompt = new CommandWith2Args<String, Command>() {

        @Override
        public void execute(final String unmetDeps, final Command yesCommand) {
            globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Install Shiny Package", userAction + " requires installation of an updated version " + "of the shiny package.\n\nDo you want to install shiny now?", new Operation() {

                @Override
                public void execute() {
                    yesCommand.execute();
                }
            }, true);
        }
    };
    // perform dependency resolution 
    withDependencies("Checking installed packages", userPrompt, shinyDependenciesArray(), true, new CommandWithArg<Boolean>() {

        @Override
        public void execute(Boolean succeeded) {
            if (succeeded)
                command.execute();
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) CommandWith2Args(org.rstudio.core.client.CommandWith2Args) Operation(org.rstudio.core.client.widget.Operation)

Example 24 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class Projects method onOpenProjectFile.

@Override
public void onOpenProjectFile(final OpenProjectFileEvent event) {
    // project options for current project
    FileSystemItem projFile = event.getFile();
    if (projFile.getPath().equals(session_.getSessionInfo().getActiveProjectFile())) {
        onProjectOptions();
        return;
    }
    // prompt to confirm
    String projectPath = projFile.getParentPathString();
    globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Confirm Open Project", "Do you want to open the project " + projectPath + "?", new Operation() {

        public void execute() {
            switchToProject(event.getFile().getPath());
        }
    }, true);
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) Operation(org.rstudio.core.client.widget.Operation)

Example 25 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class RmdOutput method onRenderRmdSource.

@Override
public void onRenderRmdSource(final RenderRmdSourceEvent event) {
    quitInitiatedAfterLastRender_ = false;
    performRenderOperation(new Operation() {

        @Override
        public void execute() {
            server_.renderRmdSource(event.getSource(), new SimpleRequestCallback<Boolean>());
        }
    });
}
Also used : ProgressOperation(org.rstudio.core.client.widget.ProgressOperation) Operation(org.rstudio.core.client.widget.Operation) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Aggregations

Operation (org.rstudio.core.client.widget.Operation)47 ServerError (org.rstudio.studio.client.server.ServerError)8 Command (com.google.gwt.user.client.Command)7 ArrayList (java.util.ArrayList)6 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)5 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)5 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)4 SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ProgressOperation (org.rstudio.core.client.widget.ProgressOperation)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 Timer (com.google.gwt.user.client.Timer)2 HTML (com.google.gwt.user.client.ui.HTML)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 WindowEx (org.rstudio.core.client.dom.WindowEx)2 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2