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