Search in sources :

Example 6 with GlobalProgressDelayer

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);
        }
    });
}
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 7 with GlobalProgressDelayer

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());
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) ProcessResult(org.rstudio.studio.client.common.vcs.ProcessResult)

Example 8 with GlobalProgressDelayer

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()));
}
Also used : GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback)

Example 9 with GlobalProgressDelayer

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());
        }
    });
}
Also used : RnwWeave(org.rstudio.studio.client.common.rnw.RnwWeave) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString) NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) FileTypeChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.FileTypeChangedHandler) Handler(org.rstudio.core.client.command.Handler) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) SelectionHandler(com.google.gwt.event.logical.shared.SelectionHandler) CloseHandler(com.google.gwt.event.logical.shared.CloseHandler) ViewDataHandler(org.rstudio.studio.client.workbench.views.data.events.ViewDataHandler) SourceOnSaveChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.SourceOnSaveChangedHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) OpenSourceFileHandler(org.rstudio.studio.client.common.filetypes.events.OpenSourceFileHandler)

Example 10 with GlobalProgressDelayer

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());
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)11 ServerError (org.rstudio.studio.client.server.ServerError)10 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)8 JsArray (com.google.gwt.core.client.JsArray)2 JsArrayString (com.google.gwt.core.client.JsArrayString)2 JSONString (com.google.gwt.json.client.JSONString)2 Handler (org.rstudio.core.client.command.Handler)2 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)2 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)2 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)2 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 CloseHandler (com.google.gwt.event.logical.shared.CloseHandler)1 SelectionHandler (com.google.gwt.event.logical.shared.SelectionHandler)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 Command (com.google.gwt.user.client.Command)1 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)1 CommandWithArg (org.rstudio.core.client.CommandWithArg)1 Dependency (org.rstudio.studio.client.common.dependencies.model.Dependency)1