Search in sources :

Example 51 with ServerError

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);
    }
}
Also used : JsArray(com.google.gwt.core.client.JsArray) SharedProjectDetails(org.rstudio.studio.client.projects.model.SharedProjectDetails) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer)

Example 52 with ServerError

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);
        }
    });
}
Also used : JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) Dependency(org.rstudio.studio.client.common.dependencies.model.Dependency) CommandWithArg(org.rstudio.core.client.CommandWithArg) Command(com.google.gwt.user.client.Command) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator)

Example 53 with ServerError

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);
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) SpellCheckerResult(org.rstudio.studio.client.common.spelling.model.SpellCheckerResult) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 54 with ServerError

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);
        }
    });
}
Also used : JsArrayInteger(com.google.gwt.core.client.JsArrayInteger) ServerError(org.rstudio.studio.client.server.ServerError) SpellCheckerResult(org.rstudio.studio.client.common.spelling.model.SpellCheckerResult) JsArrayInteger(com.google.gwt.core.client.JsArrayInteger) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 55 with ServerError

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());
        }
    });
}
Also used : SourceLocation(org.rstudio.studio.client.common.synctex.model.SourceLocation) PdfLocation(org.rstudio.studio.client.common.synctex.model.PdfLocation) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError)

Aggregations

ServerError (org.rstudio.studio.client.server.ServerError)109 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)26 JsArrayString (com.google.gwt.core.client.JsArrayString)22 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)20 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)18 Void (org.rstudio.studio.client.server.Void)16 ArrayList (java.util.ArrayList)13 JsArray (com.google.gwt.core.client.JsArray)12 Command (com.google.gwt.user.client.Command)11 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)10 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)9 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)9 Operation (org.rstudio.core.client.widget.Operation)8 Handler (org.rstudio.core.client.command.Handler)7 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)7 JSONString (com.google.gwt.json.client.JSONString)6 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)6 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)6 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)6 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)6