use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class DependencyManager method processDependencyRequest.
private void processDependencyRequest(final DependencyRequest req) {
// convert dependencies to JsArray, excluding satisfied dependencies
final JsArray<Dependency> deps = JsArray.createArray().cast();
for (int i = 0; i < req.dependencies.length; i++) {
boolean satisfied = false;
for (Dependency d : satisfied_) {
if (req.dependencies[i].isEqualTo(d)) {
satisfied = true;
break;
}
}
if (!satisfied)
deps.push(req.dependencies[i]);
}
// if no unsatisfied dependencies were found, we're done already
if (deps.length() == 0) {
req.onComplete.execute(true);
return;
}
// create progress indicator
final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 250, req.progressCaption + "...").getIndicator();
// query for unsatisfied dependencies
server_.unsatisfiedDependencies(deps, req.silentEmbeddedUpdate, new ServerRequestCallback<JsArray<Dependency>>() {
@Override
public void onResponseReceived(final JsArray<Dependency> unsatisfiedDeps) {
progress.onCompleted();
updateSatisfied(deps, unsatisfiedDeps);
// if we've satisfied all dependencies then execute the command
if (unsatisfiedDeps.length() == 0) {
req.onComplete.execute(true);
return;
}
// check to see if we can satisfy the version requirement for all
// dependencies
String unsatisfiedVersions = "";
for (int i = 0; i < unsatisfiedDeps.length(); i++) {
if (!unsatisfiedDeps.get(i).getVersionSatisfied()) {
unsatisfiedVersions += unsatisfiedDeps.get(i).getName() + " " + unsatisfiedDeps.get(i).getVersion();
String version = unsatisfiedDeps.get(i).getAvailableVersion();
if (version.isEmpty())
unsatisfiedVersions += " is not available\n";
else
unsatisfiedVersions += " is required but " + version + " is available\n";
}
}
if (!unsatisfiedVersions.isEmpty()) {
// error if we can't satisfy requirements
globalDisplay_.showErrorMessage(StringUtil.isNullOrEmpty(req.userAction) ? "Packages Not Found" : req.userAction, "Required package versions could not be found:\n\n" + unsatisfiedVersions + "\n" + "Check that getOption(\"repos\") refers to a CRAN " + "repository that contains the needed package versions.");
req.onComplete.execute(false);
} else {
// otherwise ask the user if they want to install the
// unsatisifed dependencies
final CommandWithArg<Boolean> installCommand = new CommandWithArg<Boolean>() {
@Override
public void execute(Boolean confirmed) {
// bail if user didn't confirm
if (!confirmed) {
req.onComplete.execute(false);
return;
}
// the incoming JsArray from the server may not serialize
// as expected when this code is executed from a satellite
// (see RemoteServer.sendRequestViaMainWorkbench), so we
// clone it before passing to the dependency installer
JsArray<Dependency> newArray = JsArray.createArray().cast();
newArray.setLength(unsatisfiedDeps.length());
for (int i = 0; i < unsatisfiedDeps.length(); i++) {
newArray.set(i, unsatisfiedDeps.get(i));
}
installDependencies(newArray, req.silentEmbeddedUpdate, req.onComplete);
}
};
if (req.userPrompt != null) {
req.userPrompt.execute(describeDepPkgs(unsatisfiedDeps), new Command() {
@Override
public void execute() {
installCommand.execute(true);
}
});
} else {
confirmPackageInstallation(req.userAction, unsatisfiedDeps, installCommand);
}
}
}
@Override
public void onError(ServerError error) {
progress.onError(error.getUserMessage());
req.onComplete.execute(false);
}
});
}
use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class Ignore method showDialog.
public void showDialog(final IgnoreList ignoreList, final Strategy strategy) {
// show progress
final ProgressIndicator globalIndicator = new GlobalProgressDelayer(globalDisplay_, 500, "Getting ignored files for path...").getIndicator();
// get existing ignores
final String fullPath = projPathToFullPath(ignoreList.getPath());
strategy.getIgnores(fullPath, new ServerRequestCallback<ProcessResult>() {
@Override
public void onResponseReceived(final ProcessResult result) {
globalIndicator.onCompleted();
if (checkForProcessError(strategy.getDialogCaption(), result))
return;
// show the ignore dialog
String ignored = getIgnored(ignoreList, result.getOutput());
showDialog(fullPath, ignored, strategy);
}
@Override
public void onError(ServerError error) {
globalIndicator.onError(error.getUserMessage());
}
});
}
use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class ConnectionsPresenter method onViewConnectionDataset.
@Override
public void onViewConnectionDataset(ViewConnectionDatasetEvent event) {
if (exploredConnection_ == null)
return;
GlobalProgressDelayer progress = new GlobalProgressDelayer(globalDisplay_, 100, "Previewing table...");
server_.connectionPreviewTable(exploredConnection_.getId(), event.getDataset(), new VoidServerRequestCallback(progress.getIndicator()));
}
use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class Source method onNewSweaveDoc.
@Handler
public void onNewSweaveDoc() {
// set concordance value if we need to
String concordance = new String();
if (uiPrefs_.alwaysEnableRnwConcordance().getValue()) {
RnwWeave activeWeave = rnwWeaveRegistry_.findTypeIgnoreCase(uiPrefs_.defaultSweaveEngine().getValue());
if (activeWeave.getInjectConcordance())
concordance = "\\SweaveOpts{concordance=TRUE}\n";
}
final String concordanceValue = concordance;
// show progress
final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Creating new document...").getIndicator();
// get the template
server_.getSourceTemplate("", "sweave.Rnw", new ServerRequestCallback<String>() {
@Override
public void onResponseReceived(String templateContents) {
indicator.onCompleted();
// add in concordance if necessary
final boolean hasConcordance = concordanceValue.length() > 0;
if (hasConcordance) {
String beginDoc = "\\begin{document}\n";
templateContents = templateContents.replace(beginDoc, beginDoc + concordanceValue);
}
newDoc(FileTypeRegistry.SWEAVE, templateContents, new ResultCallback<EditingTarget, ServerError>() {
@Override
public void onSuccess(EditingTarget target) {
int startRow = 4 + (hasConcordance ? 1 : 0);
target.setCursorPosition(Position.create(startRow, 0));
}
});
}
@Override
public void onError(ServerError error) {
indicator.onError(error.getUserMessage());
}
});
}
use of org.rstudio.studio.client.common.GlobalProgressDelayer in project rstudio by rstudio.
the class Source method newSourceDocWithTemplate.
private void newSourceDocWithTemplate(final TextFileType fileType, String name, String template, final Position cursorPosition, final CommandWithArg<EditingTarget> onSuccess, final TransformerCommand<String> contentTransformer) {
final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Creating new document...").getIndicator();
server_.getSourceTemplate(name, template, new ServerRequestCallback<String>() {
@Override
public void onResponseReceived(String templateContents) {
indicator.onCompleted();
if (contentTransformer != null)
templateContents = contentTransformer.transform(templateContents);
newDoc(fileType, templateContents, new ResultCallback<EditingTarget, ServerError>() {
@Override
public void onSuccess(EditingTarget target) {
if (cursorPosition != null)
target.setCursorPosition(cursorPosition);
if (onSuccess != null)
onSuccess.execute(target);
}
});
}
@Override
public void onError(ServerError error) {
indicator.onError(error.getUserMessage());
}
});
}
Aggregations