use of org.rstudio.studio.client.server.Void in project rstudio by rstudio.
the class DataImport method previewDataImport.
private void previewDataImport() {
Operation previewDataImportOperation = new Operation() {
@Override
public void execute() {
DataImportOptions previewImportOptions = getOptions();
if (dataImportFileChooser_.getText() == "") {
gridViewer_.setData(null);
return;
}
previewImportOptions.setMaxRows(maxRows_);
progressIndicator_.onProgress("Retrieving preview data...", new Operation() {
@Override
public void execute() {
progressIndicator_.clearProgress();
cleanPreviewResources();
server_.previewDataImportAsyncAbort(new ServerRequestCallback<Void>() {
@Override
public void onResponseReceived(Void empty) {
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
progressIndicator_.onError(error.getMessage());
}
});
}
});
server_.previewDataImportAsync(previewImportOptions, maxCols_, maxFactors_, new ServerRequestCallback<DataImportPreviewResponse>() {
@Override
public void onResponseReceived(DataImportPreviewResponse response) {
if (response == null || response.getErrorMessage() != null) {
if (response != null) {
setGridViewerData(response);
response.setColumnDefinitions(lastSuccessfulResponse_);
progressIndicator_.onError(enhancePreviewErrorMessage(response.getErrorMessage()));
}
return;
}
// Set the column definitions to allow subsequent calls to assemble
// generate preview code based on data.
importOptions_.setBaseColumnDefinitions(response);
lastSuccessfulResponse_ = response;
dataImportOptionsUi_.setPreviewResponse(response);
if (response.getLocalFiles() != null) {
localFiles_ = response.getLocalFiles();
}
gridViewer_.setOption("status", "Previewing first " + toLocaleString(maxRows_) + " entries. " + (response.getParsingErrors() > 0 ? Integer.toString(response.getParsingErrors()) + " parsing errors." : ""));
assignColumnDefinitions(response, importOptions_.getColumnDefinitions());
setGridViewerData(response);
progressIndicator_.onCompleted();
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
cleanPreviewResources();
gridViewer_.setData(null);
progressIndicator_.onError(error.getMessage());
}
});
}
};
assembleDataImport(previewDataImportOperation);
}
use of org.rstudio.studio.client.server.Void 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.Void in project rstudio by rstudio.
the class SourceWindowManager method assignSourceDocWindowId.
private void assignSourceDocWindowId(String docId, String windowId, final Command onComplete) {
// assign locally
JsArray<SourceDocument> docs = getSourceDocs();
for (int i = 0; i < docs.length(); i++) {
SourceDocument doc = docs.get(i);
if (doc.getId() == docId) {
// it
if (doc.getSourceWindowId() == windowId)
return;
doc.assignSourceWindowId(windowId);
break;
}
}
// create the new property map
HashMap<String, String> props = new HashMap<String, String>();
props.put(SOURCE_WINDOW_ID, windowId);
// update the doc window ID on the server
server_.modifyDocumentProperties(docId, props, new ServerRequestCallback<Void>() {
@Override
public void onResponseReceived(Void v) {
if (onComplete != null)
onComplete.execute();
}
@Override
public void onError(ServerError error) {
display_.showErrorMessage("Can't Move Doc", "The document could not be " + "moved to a different window: \n" + error.getMessage());
}
});
}
use of org.rstudio.studio.client.server.Void 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.Void in project rstudio by rstudio.
the class TextEditingTarget method sourceActiveDocument.
private void sourceActiveDocument(final boolean echo) {
docDisplay_.focus();
// If the document being sourced is a Shiny file, run the app instead.
if (fileType_.isR() && extendedType_.startsWith(SourceDocument.XT_SHINY_PREFIX)) {
runShinyApp();
return;
}
// if the document is an R Markdown notebook, run all its chunks instead
if (fileType_.isRmd() && isRmdNotebook()) {
onExecuteAllCode();
return;
}
// If the document being sourced is a script then use that codepath
if (fileType_.isScript()) {
runScript();
return;
}
// If the document is previewable
if (fileType_.canPreviewFromR()) {
previewFromR();
return;
}
String code = docDisplay_.getCode();
if (code != null && code.trim().length() > 0) {
// R 2.14 prints a warning when sourcing a file with no trailing \n
if (!code.endsWith("\n"))
code = code + "\n";
boolean sweave = fileType_.canCompilePDF() || fileType_.canKnitToHTML() || fileType_.isRpres();
RnwWeave rnwWeave = compilePdfHelper_.getActiveRnwWeave();
final boolean forceEcho = sweave && (rnwWeave != null) ? rnwWeave.forceEchoOnExec() : false;
// NOTE: we always set echo to true for knitr because knitr doesn't
// require print statements so if you don't echo to the console
// then you don't see any of the output
boolean saveWhenSourcing = fileType_.isCpp() || docDisplay_.hasBreakpoints() || (prefs_.saveBeforeSourcing().getValue() && (getPath() != null) && !sweave);
if ((dirtyState_.getValue() || sweave) && !saveWhenSourcing) {
server_.saveActiveDocument(code, sweave, compilePdfHelper_.getActiveRnwWeaveName(), new SimpleRequestCallback<Void>() {
@Override
public void onResponseReceived(Void response) {
consoleDispatcher_.executeSourceCommand("~/.active-rstudio-document", fileType_, "UTF-8", activeCodeIsAscii(), forceEcho ? true : echo, prefs_.focusConsoleAfterExec().getValue(), docDisplay_.hasBreakpoints());
}
});
} else {
Command sourceCommand = new Command() {
@Override
public void execute() {
if (docDisplay_.hasBreakpoints()) {
hideBreakpointWarningBar();
}
consoleDispatcher_.executeSourceCommand(getPath(), fileType_, docUpdateSentinel_.getEncoding(), activeCodeIsAscii(), forceEcho ? true : echo, prefs_.focusConsoleAfterExec().getValue(), docDisplay_.hasBreakpoints());
}
};
if (saveWhenSourcing && (dirtyState_.getValue() || (getPath() == null)))
saveThenExecute(null, sourceCommand);
else
sourceCommand.execute();
}
}
// update pref if necessary
if (prefs_.sourceWithEcho().getValue() != echo) {
prefs_.sourceWithEcho().setGlobalValue(echo, true);
prefs_.writeUIPrefs();
}
}
Aggregations