Search in sources :

Example 96 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class Plots method onSavePlotAsPdf.

void onSavePlotAsPdf() {
    view_.bringToFront();
    final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error");
    indicator.onProgress("Preparing to export plot...");
    // get the default directory
    final FileSystemItem defaultDir = ExportPlotUtils.getDefaultSaveDirectory(workbenchContext_.getCurrentWorkingDir());
    // get context
    server_.getUniqueSavePlotStem(defaultDir.getPath(), new SimpleRequestCallback<String>() {

        @Override
        public void onResponseReceived(String stem) {
            indicator.onCompleted();
            Size size = getPlotSize();
            final SavePlotAsPdfOptions currentOptions = uiPrefs_.get().savePlotAsPdfOptions().getValue();
            exportPlot_.savePlotAsPdf(globalDisplay_, server_, session_.getSessionInfo(), defaultDir, stem, currentOptions, pixelsToInches(size.width), pixelsToInches(size.height), new OperationWithInput<SavePlotAsPdfOptions>() {

                @Override
                public void execute(SavePlotAsPdfOptions options) {
                    if (!SavePlotAsPdfOptions.areEqual(options, currentOptions)) {
                        UIPrefs prefs = uiPrefs_.get();
                        prefs.savePlotAsPdfOptions().setGlobalValue(options);
                        prefs.writeUIPrefs();
                    }
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) Size(org.rstudio.core.client.Size) ServerError(org.rstudio.studio.client.server.ServerError) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) SavePlotAsPdfOptions(org.rstudio.studio.client.workbench.views.plots.model.SavePlotAsPdfOptions) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs)

Example 97 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class SavePlotAsHandler method webSavePlotAs.

private void webSavePlotAs(final FileSystemItem targetPath, final boolean overwrite, final boolean viewAfterSave, final Operation onCompleted) {
    globalDisplay_.openProgressWindow("_blank", "Converting Plot...", new OperationWithInput<WindowEx>() {

        public void execute(final WindowEx window) {
            savePlotAs(targetPath, overwrite, viewAfterSave, onCompleted, new PlotSaveAsUIHandler() {

                @Override
                public void onSuccess() {
                    // redirect window to view file
                    final String url = server_.getFileUrl(targetPath);
                    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                        @Override
                        public void execute() {
                            window.replaceLocationHref(url);
                        }
                    });
                }

                @Override
                public void onError(ServerError error) {
                    window.close();
                    globalDisplay_.showErrorMessage("Error Saving Plot", error.getUserMessage());
                }

                @Override
                public void onOverwritePrompt() {
                    window.close();
                }
            });
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ServerError(org.rstudio.studio.client.server.ServerError) WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 98 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class Presentation method onClearPresentationCache.

@Handler
void onClearPresentationCache() {
    globalDisplay_.showYesNoMessage(MessageDialog.INFO, "Clear Knitr Cache", "Clearing the Knitr cache will discard previously cached " + "output and re-run all of the R code chunks within the " + "presentation.\n\n" + "Are you sure you want to clear the cache now?", false, new ProgressOperation() {

        @Override
        public void execute(final ProgressIndicator indicator) {
            indicator.onProgress("Clearing Knitr Cache...");
            server_.clearPresentationCache(new ServerRequestCallback<Void>() {

                @Override
                public void onResponseReceived(Void response) {
                    indicator.onCompleted();
                    refreshPresentation();
                }

                @Override
                public void onError(ServerError error) {
                    indicator.onCompleted();
                    globalDisplay_.showErrorMessage("Error Clearing Cache", getErrorMessage(error));
                }
            });
        }
    }, new ProgressOperation() {

        @Override
        public void execute(ProgressIndicator indicator) {
            indicator.onCompleted();
        }
    }, true);
}
Also used : ProgressOperation(org.rstudio.core.client.widget.ProgressOperation) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) Void(org.rstudio.studio.client.server.Void) Handler(org.rstudio.core.client.command.Handler)

Example 99 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class Source method pasteFileContentsAtCursor.

private void pasteFileContentsAtCursor(final String path, final String encoding) {
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget) {
        final TextEditingTarget target = (TextEditingTarget) activeEditor_;
        server_.getFileContents(path, encoding, new ServerRequestCallback<String>() {

            @Override
            public void onResponseReceived(String content) {
                target.insertCode(content, false);
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 100 with ServerError

use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.

the class Source method openNotebook.

private void openNotebook(final FileSystemItem rnbFile, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    // construct path to .Rmd
    final String rnbPath = rnbFile.getPath();
    final String rmdPath = FilePathUtils.filePathSansExtension(rnbPath) + ".Rmd";
    final FileSystemItem rmdFile = FileSystemItem.createFile(rmdPath);
    // TODO: should we perform conflict resolution here as well?
    if (openFileAlreadyOpen(rmdFile, resultCallback))
        return;
    // ask the server to extract the .Rmd, then open that
    Command extractRmdCommand = new Command() {

        @Override
        public void execute() {
            server_.extractRmdFromNotebook(rnbPath, new ServerRequestCallback<SourceDocumentResult>() {

                @Override
                public void onResponseReceived(SourceDocumentResult doc) {
                    openNotebook(rmdFile, doc, resultCallback);
                }

                @Override
                public void onError(ServerError error) {
                    globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. \n\n" + error.getMessage());
                    resultCallback.onFailure(error);
                }
            });
        }
    };
    dependencyManager_.withRMarkdown("R Notebook", "Using R Notebooks", extractRmdCommand);
}
Also used : SourceDocumentResult(org.rstudio.studio.client.workbench.views.source.model.SourceDocumentResult) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ServerError(org.rstudio.studio.client.server.ServerError) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

ServerError (org.rstudio.studio.client.server.ServerError)109 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)26 JsArrayString (com.google.gwt.core.client.JsArrayString)22 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)20 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)18 Void (org.rstudio.studio.client.server.Void)16 ArrayList (java.util.ArrayList)13 JsArray (com.google.gwt.core.client.JsArray)12 Command (com.google.gwt.user.client.Command)11 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)10 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)9 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)9 Operation (org.rstudio.core.client.widget.Operation)8 Handler (org.rstudio.core.client.command.Handler)7 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)7 JSONString (com.google.gwt.json.client.JSONString)6 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)6 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)6 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)6 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)6