Search in sources :

Example 11 with Operation

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

the class ApplicationClientInit method execute.

public void execute(final ServerRequestCallback<SessionInfo> requestCallback, final boolean retryOnTransmissionError) {
    // reset internal state 
    timedOut_ = false;
    timeoutTimer_ = null;
    // send the request
    final ServerRequestCallback<SessionInfo> rpcRequestCallback = new ServerRequestCallback<SessionInfo>() {

        @Override
        public void onResponseReceived(SessionInfo sessionInfo) {
            if (!timedOut_) {
                cancelTimeoutTimer();
                requestCallback.onResponseReceived(sessionInfo);
            }
        }

        @Override
        public void onError(ServerError error) {
            if (!timedOut_) {
                cancelTimeoutTimer();
                if ((error.getCode() == ServerError.TRANSMISSION) && retryOnTransmissionError) {
                    // transmission error can occur due to a race 
                    // condition when switching projects or versions, for
                    // this case wait 1000ms then retry
                    new Timer() {

                        @Override
                        public void run() {
                            // retry (specify flag to ensure we only retry once)
                            execute(requestCallback, false);
                        }
                    }.schedule(1000);
                } else {
                    requestCallback.onError(error);
                }
            }
        }
    };
    server_.clientInit(rpcRequestCallback);
    // wait for 60 seconds then ask the user if they want to issue an 
    // interrupt to the server
    int timeoutMs = 60000;
    timeoutTimer_ = new Timer() {

        public void run() {
            // set timed out flag
            timedOut_ = true;
            // cancel our request
            rpcRequestCallback.cancel();
            // ask the user if they want to attempt to interrupt the server
            globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, // caption
            "Initializing RStudio", // message
            "The RStudio server is taking a long time to respond. It is " + "possible that your R session has become unresponsive. " + "Do you want to terminate the currently running R session?", // don't include cancel
            false, // Yes operation
            new Operation() {

                public void execute() {
                    // call interrupt then call this method back on success
                    server_.abort(null, new ServerRequestCallback<Void>() {

                        @Override
                        public void onResponseReceived(Void response) {
                            // reload the application
                            reloadWithDelay(1000);
                        }

                        @Override
                        public void onError(ServerError error) {
                            // if we get an error during interrupt then just
                            // forward the error on to the original handler
                            requestCallback.onError(error);
                        }
                    });
                }
            }, // No operation
            new Operation() {

                public void execute() {
                    // keep trying (reload to clear out any crufty app
                    // or networking state)
                    reloadWithDelay(1);
                }
            }, // Cancel operation (none)
            null, "Terminate R", "Keep Waiting", // default to No
            false);
        }
    };
    // activate the timer
    timeoutTimer_.schedule(timeoutMs);
}
Also used : Timer(com.google.gwt.user.client.Timer) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) Operation(org.rstudio.core.client.widget.Operation) Void(org.rstudio.studio.client.server.Void)

Example 12 with Operation

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

the class PDFViewer method onCompilePdfCompleted.

@Override
public void onCompilePdfCompleted(CompilePdfCompletedEvent event) {
    // only handle PDF compile events when we're the preferred viewer
    if (!prefs_.pdfPreview().getValue().equals(UIPrefs.PDF_PREVIEW_RSTUDIO))
        return;
    // only handle successful compiles
    final CompilePdfResult result = event.getResult();
    if (!result.getSucceeded())
        return;
    // when the PDF is finished rendering, optionally navigate to the desired
    // location, or set and restore the current location
    final PdfLocation pdfLocation = result.getPdfLocation();
    if (pdfLocation != null) {
        executeOnPdfLoad_ = new Operation() {

            @Override
            public void execute() {
                PdfJsWindow.navigateTo(pdfJsWindow_, pdfLocation);
            }
        };
    }
    lastSuccessfulPdfPath_ = result.getPdfPath();
    openPdfUrl(result.getViewPdfUrl(), result.isSynctexAvailable(), pdfLocation == null);
}
Also used : PdfLocation(org.rstudio.studio.client.common.synctex.model.PdfLocation) CompilePdfResult(org.rstudio.studio.client.common.compilepdf.model.CompilePdfResult) Operation(org.rstudio.core.client.widget.Operation)

Example 13 with Operation

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

the class RmdOutput method onRenderRmd.

@Override
public void onRenderRmd(final RenderRmdEvent event) {
    quitInitiatedAfterLastRender_ = false;
    final Operation renderOperation = new Operation() {

        @Override
        public void execute() {
            renderInProgress_ = true;
            server_.renderRmd(event.getSourceFile(), event.getSourceLine(), event.getFormat(), event.getEncoding(), event.getParamsFile(), event.asTempfile(), event.getType(), event.getExistingOutputFile(), event.getWorkingDir(), event.getViewerType(), new SimpleRequestCallback<Boolean>() {

                @Override
                public void onError(ServerError error) {
                    renderInProgress_ = false;
                }
            });
        }
    };
    // information back into the preview window.
    if (shinyDoc_ != null && event.getSourceFile().equals(shinyDoc_.getFile()) && !shinyDoc_.getFormat().getFormatName().endsWith(RmdOutputFormat.OUTPUT_PRESENTATION_SUFFIX) && (result_ == null || "shiny".equals(result_.getRuntime()))) {
        final RmdRenderResult result = RmdRenderResult.createFromShinyDoc(shinyDoc_);
        displayHTMLRenderResult(result);
    } else {
        performRenderOperation(renderOperation);
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) ProgressOperation(org.rstudio.core.client.widget.ProgressOperation) Operation(org.rstudio.core.client.widget.Operation) RmdRenderResult(org.rstudio.studio.client.rmarkdown.model.RmdRenderResult)

Example 14 with Operation

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

the class ProjectPreferencesPane method promptToRestart.

protected void promptToRestart() {
    globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Confirm Restart RStudio", "You need to restart RStudio in order for this change to take " + "effect. Do you want to do this now?", new Operation() {

        @Override
        public void execute() {
            forceClosed(new Command() {

                @Override
                public void execute() {
                    SwitchToProjectEvent event = new SwitchToProjectEvent(session_.getSessionInfo().getActiveProjectFile());
                    eventBus_.fireEvent(event);
                }
            });
        }
    }, true);
}
Also used : Command(com.google.gwt.user.client.Command) SwitchToProjectEvent(org.rstudio.studio.client.projects.events.SwitchToProjectEvent) Operation(org.rstudio.core.client.widget.Operation)

Example 15 with Operation

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

the class TextEditingTargetRMarkdownHelper method createDraftFromTemplate.

public void createDraftFromTemplate(final RmdChosenTemplate template) {
    final String target = template.getDirectory() + "/" + template.getFileName();
    final String targetFile = target + (template.createDir() ? "" : ".Rmd");
    fileServer_.stat(targetFile, new ServerRequestCallback<FileSystemItem>() {

        @Override
        public void onResponseReceived(final FileSystemItem fsi) {
            // the file doesn't exist--proceed
            if (!fsi.exists()) {
                createDraftFromTemplate(template, target);
                return;
            }
            // the file exists--offer to clean it up and continue.
            globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Overwrite " + (template.createDir() ? "Directory" : "File"), targetFile + " exists. Overwrite it?", false, new Operation() {

                @Override
                public void execute() {
                    cleanAndCreateTemplate(template, target, fsi);
                }
            }, null, null, "Overwrite", "Cancel", false);
        }

        @Override
        public void onError(ServerError error) {
            // presumably the file doesn't exist, which is what we want.
            createDraftFromTemplate(template, target);
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ServerError(org.rstudio.studio.client.server.ServerError) JsArrayString(com.google.gwt.core.client.JsArrayString) Operation(org.rstudio.core.client.widget.Operation)

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