use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class DataEditingTarget method updateData.
public void updateData(final DataItem data) {
final Widget originalWidget = progressPanel_.getWidget();
clearDisplay();
final String oldCacheKey = getCacheKey();
HashMap<String, String> props = new HashMap<String, String>();
data.fillProperties(props);
server_.modifyDocumentProperties(doc_.getId(), props, new SimpleRequestCallback<Void>("Error") {
@Override
public void onResponseReceived(Void response) {
server_.removeCachedData(oldCacheKey, new ServerRequestCallback<Void>() {
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
data.fillProperties(doc_.getProperties());
reloadDisplay();
}
@Override
public void onError(ServerError error) {
super.onError(error);
progressPanel_.setWidget(originalWidget);
}
});
}
use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class ProfilerEditingTarget method onActivate.
public void onActivate() {
activeProfilerEditingTarger_ = this;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
commands_.gotoProfileSource().setEnabled(hasValidPath_);
}
});
final Operation activateOperation = new Operation() {
@Override
public void execute() {
if (!htmlPathInitialized_) {
htmlPathInitialized_ = true;
htmlPath_ = getContents().getHtmlPath();
htmlLocalPath_ = getContents().getHtmlLocalPath();
isUserSaved_ = getContents().isUserSaved();
if (htmlPath_ == null) {
presenter_.buildHtmlPath(new OperationWithInput<ProfileOperationResponse>() {
@Override
public void execute(ProfileOperationResponse response) {
htmlPath_ = response.getHtmlPath();
htmlLocalPath_ = response.getHtmlLocalPath();
persistDocumentProperty("htmlPath", htmlPath_);
persistDocumentProperty("htmlLocalPath", htmlLocalPath_);
view_.showProfilePage(htmlPath_);
pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
}
}, new Operation() {
@Override
public void execute() {
server_.clearProfile(getPath(), new ServerRequestCallback<JavaScriptObject>() {
@Override
public void onResponseReceived(JavaScriptObject response) {
commands_.closeSourceDoc().execute();
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
commands_.closeSourceDoc().execute();
}
});
}
}, getPath());
} else {
view_.showProfilePage(htmlPath_);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
}
});
}
}
}
};
if (getId() != null && !SourceWindowManager.isMainSourceWindow()) {
sourceServer_.getSourceDocument(getId(), new ServerRequestCallback<SourceDocument>() {
@Override
public void onResponseReceived(SourceDocument document) {
doc_ = document;
activateOperation.execute();
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
} else {
activateOperation.execute();
}
// This shouldn't happen though.
if (commandHandlerReg_ != null) {
Debug.log("Warning: onActivate called twice without intervening onDeactivate");
commandHandlerReg_.removeHandler();
commandHandlerReg_ = null;
}
commandHandlerReg_ = commandBinder.bind(commands_, this);
}
use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class Source method openNotebook.
private void openNotebook(final FileSystemItem rmdFile, final SourceDocumentResult doc, final ResultCallback<EditingTarget, ServerError> resultCallback) {
if (!StringUtil.isNullOrEmpty(doc.getDocPath())) {
// this happens if we created the R Markdown file, or if the R Markdown
// file on disk matched the one inside the notebook
openFileFromServer(rmdFile, FileTypeRegistry.RMARKDOWN, resultCallback);
} else if (!StringUtil.isNullOrEmpty(doc.getDocId())) {
// this happens when we have to open an untitled buffer for the the
// notebook (usually because the of a conflict between the Rmd on disk
// and the one in the .nb.html file)
server_.getSourceDocument(doc.getDocId(), new ServerRequestCallback<SourceDocument>() {
@Override
public void onResponseReceived(SourceDocument doc) {
// create the editor
EditingTarget target = addTab(doc, OPEN_INTERACTIVE);
// show a warning bar
if (target instanceof TextEditingTarget) {
((TextEditingTarget) target).showWarningMessage("This notebook has the same name as an R Markdown " + "file, but doesn't match it.");
}
resultCallback.onSuccess(target);
}
@Override
public void onError(ServerError error) {
globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. " + "If the error persists, try removing the " + "accompanying R Markdown file. \n\n" + error.getMessage());
resultCallback.onFailure(error);
}
});
}
}
use of org.rstudio.studio.client.server.ServerRequestCallback 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.ServerRequestCallback in project rstudio by rstudio.
the class ViewerPane method createMainToolbar.
@Override
protected Toolbar createMainToolbar() {
toolbar_ = new Toolbar();
// add html widget buttons
toolbar_.addLeftWidget(commands_.viewerBack().createToolbarButton());
toolbar_.addLeftWidget(commands_.viewerForward().createToolbarButton());
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerZoom().createToolbarButton());
// export commands
exportButtonSeparator_ = toolbar_.addLeftSeparator();
ToolbarPopupMenu exportMenu = new ToolbarPopupMenu();
exportMenu.addItem(commands_.viewerSaveAsImage().createMenuItem(false));
exportMenu.addItem(commands_.viewerCopyToClipboard().createMenuItem(false));
exportMenu.addSeparator();
exportMenu.addItem(commands_.viewerSaveAsWebPage().createMenuItem(false));
exportButton_ = new ToolbarButton("Export", new ImageResource2x(StandardIcons.INSTANCE.export_menu2x()), exportMenu);
toolbar_.addLeftWidget(exportButton_);
exportButton_.setVisible(false);
exportButtonSeparator_.setVisible(false);
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerClear().createToolbarButton());
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerClearAll().createToolbarButton());
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerPopout().createToolbarButton());
toolbar_.addLeftSeparator();
toolbar_.addLeftWidget(commands_.viewerStop().createToolbarButton());
// add publish button
publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_DOCUMENT, true, null);
toolbar_.addRightWidget(publishButton_);
toolbar_.addRightSeparator();
toolbar_.addRightWidget(commands_.viewerRefresh().createToolbarButton());
// create an HTML generator
publishButton_.setPublishHtmlSource(new PublishHtmlSource() {
@Override
public void generatePublishHtml(final CommandWithArg<String> onCompleted) {
server_.viewerCreateRPubsHtml(getTitle(), "", new ServerRequestCallback<String>() {
@Override
public void onResponseReceived(String htmlFile) {
onCompleted.execute(htmlFile);
}
@Override
public void onError(ServerError error) {
globalDisplay_.showErrorMessage("Could Not Publish", error.getMessage());
}
});
}
@Override
public String getTitle() {
String title = frame_.getTitle();
if (StringUtil.isNullOrEmpty(title))
title = "Viewer Content";
return title;
}
});
return toolbar_;
}
Aggregations