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());
}
});
}
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();
}
});
}
});
}
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);
}
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);
}
});
}
}
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);
}
Aggregations