use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class ProjectPopupMenu method getDynamicPopupMenu.
@Override
public void getDynamicPopupMenu(final DynamicPopupMenuCallback callback) {
ProjectMRUList.setOpenInNewWindow(false);
if (allowSharedProjects_) {
final GlobalProgressDelayer progress = new GlobalProgressDelayer(RStudioGinjector.INSTANCE.getGlobalDisplay(), 250, "Looking for projects...");
// if shared projects are on, check for them every time the user drops
// the menu; we request one more than the maximum we can display so
// we can let the user know whether there are more projects than those
// that can be displayed in the menu
server_.getSharedProjects(MAX_SHARED_PROJECTS + 1, new ServerRequestCallback<JsArray<SharedProjectDetails>>() {
@Override
public void onResponseReceived(JsArray<SharedProjectDetails> result) {
rebuildMenu(result, callback);
progress.dismiss();
}
@Override
public void onError(ServerError error) {
// if we can't get the shared projects, we can at least show
// the menu without them
rebuildMenu(null, callback);
progress.dismiss();
}
});
} else {
rebuildMenu(null, callback);
}
}
use of org.rstudio.studio.client.server.ServerError 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.server.ServerError in project rstudio by rstudio.
the class SpellChecker method checkSpelling.
public void checkSpelling(List<String> words, final ServerRequestCallback<SpellCheckerResult> callback) {
// allocate results
final SpellCheckerResult spellCheckerResult = new SpellCheckerResult();
if (words.isEmpty()) {
callback.onResponseReceived(spellCheckerResult);
return;
}
// only send words to the server that aren't ignored
final ArrayList<String> wordsToCheck = new ArrayList<String>();
for (int i = 0; i < words.size(); i++) {
String word = words.get(i);
if (isWordIgnored(word))
spellCheckerResult.getCorrect().add(word);
else
wordsToCheck.add(word);
}
// call the service to check the non-ignored words
spellingService_.checkSpelling(wordsToCheck, new ServerRequestCallback<SpellCheckerResult>() {
@Override
public void onResponseReceived(SpellCheckerResult result) {
spellCheckerResult.getCorrect().addAll(result.getCorrect());
spellCheckerResult.getIncorrect().addAll(result.getIncorrect());
callback.onResponseReceived(spellCheckerResult);
}
@Override
public void onError(ServerError error) {
callback.onError(error);
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class SpellingService method checkSpelling.
public void checkSpelling(List<String> words, final ServerRequestCallback<SpellCheckerResult> callback) {
// results to return
final SpellCheckerResult spellCheckerResult = new SpellCheckerResult();
// only send words to the server that aren't in the cache
final ArrayList<String> wordsToCheck = new ArrayList<String>();
for (int i = 0; i < words.size(); i++) {
String word = words.get(i);
Boolean isCorrect = previousResults_.get(word);
if (isCorrect != null) {
if (isCorrect)
spellCheckerResult.getCorrect().add(word);
else
spellCheckerResult.getIncorrect().add(word);
} else {
wordsToCheck.add(word);
}
}
// if there are no words to check then return
if (wordsToCheck.size() == 0) {
callback.onResponseReceived(spellCheckerResult);
return;
}
// hit the server
server_.checkSpelling(JsUtil.toJsArrayString(wordsToCheck), new ServerRequestCallback<JsArrayInteger>() {
@Override
public void onResponseReceived(JsArrayInteger result) {
// get misspelled indexes
ArrayList<Integer> misspelledIndexes = new ArrayList<Integer>();
for (int i = 0; i < result.length(); i++) misspelledIndexes.add(result.get(i));
// determine correct/incorrect status and populate result & cache
for (int i = 0; i < wordsToCheck.size(); i++) {
String word = wordsToCheck.get(i);
if (misspelledIndexes.contains(i)) {
spellCheckerResult.getIncorrect().add(word);
previousResults_.put(word, false);
} else {
spellCheckerResult.getCorrect().add(word);
previousResults_.put(word, true);
}
}
// return result
callback.onResponseReceived(spellCheckerResult);
}
@Override
public void onError(ServerError error) {
callback.onError(error);
}
});
}
use of org.rstudio.studio.client.server.ServerError in project rstudio by rstudio.
the class Synctex method doInverseSearch.
private void doInverseSearch(JavaScriptObject pdfLocationObject) {
PdfLocation pdfLocation = pdfLocationObject.cast();
final ProgressIndicator indicator = getSyncProgress();
server_.synctexInverseSearch(pdfLocation, new ServerRequestCallback<SourceLocation>() {
@Override
public void onResponseReceived(SourceLocation location) {
indicator.onCompleted();
if (location != null)
goToSourceLocation(location);
}
@Override
public void onError(ServerError error) {
indicator.onError(error.getUserMessage());
}
});
}
Aggregations