Search in sources :

Example 1 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.

the class LintManager method performCppLintServerRequest.

private void performCppLintServerRequest(final LintContext context) {
    cppCompletionContext_.cppCompletionOperation(new CppCompletionOperation() {

        @Override
        public void execute(String docPath, int line, int column) {
            server_.getCppDiagnostics(target_.getPath(), new ServerRequestCallback<JsArray<CppDiagnostic>>() {

                @Override
                public void onResponseReceived(JsArray<CppDiagnostic> diag) {
                    if (context.token.isInvalid())
                        return;
                    final JsArray<LintItem> cppLint = CppCompletionRequest.asLintArray(diag);
                    server_.lintRSourceDocument(target_.getId(), target_.getPath(), context.showMarkers, context.explicit, new ServerRequestCallback<JsArray<LintItem>>() {

                        @Override
                        public void onResponseReceived(JsArray<LintItem> rLint) {
                            if (context.token.isInvalid())
                                return;
                            JsArray<LintItem> allLint = JsArray.createArray().cast();
                            for (int i = 0; i < cppLint.length(); i++) allLint.push(cppLint.get(i));
                            for (int i = 0; i < rLint.length(); i++) allLint.push(rLint.get(i));
                            showLint(context, allLint);
                        }

                        @Override
                        public void onError(ServerError error) {
                            Debug.logError(error);
                        }
                    });
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                }
            });
        }
    });
}
Also used : CppCompletionOperation(org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionOperation) JsArray(com.google.gwt.core.client.JsArray) LintItem(org.rstudio.studio.client.workbench.views.output.lint.model.LintItem) CppDiagnostic(org.rstudio.studio.client.workbench.views.source.model.CppDiagnostic) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 2 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.

the class Packages method doUpdatePackages.

private void doUpdatePackages(final PackageInstallContext installContext) {
    new CheckForUpdatesDialog(globalDisplay_, new ServerDataSource<JsArray<PackageUpdate>>() {

        public void requestData(ServerRequestCallback<JsArray<PackageUpdate>> requestCallback) {
            server_.checkForPackageUpdates(requestCallback);
        }
    }, new OperationWithInput<ArrayList<PackageUpdate>>() {

        @Override
        public void execute(ArrayList<PackageUpdate> updates) {
            InstallCommand cmd = buildUpdatePackagesCommand(updates, installContext);
            executeWithLoadedPackageCheck(cmd);
        }
    }, new Operation() {

        @Override
        public void execute() {
            // cancel emits an empty console input line to clear
            // the busy indicator
            events_.fireEvent(new SendToConsoleEvent("", true));
        }
    }).showModal();
}
Also used : ServerDataSource(org.rstudio.studio.client.server.ServerDataSource) ProgressOperationWithInput(org.rstudio.core.client.widget.ProgressOperationWithInput) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) ArrayList(java.util.ArrayList) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) PackageUpdate(org.rstudio.studio.client.workbench.views.packages.model.PackageUpdate) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) CheckForUpdatesDialog(org.rstudio.studio.client.workbench.views.packages.ui.CheckForUpdatesDialog) Operation(org.rstudio.core.client.widget.Operation)

Example 3 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback 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);
}
Also used : Timer(com.google.gwt.user.client.Timer) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) Operation(org.rstudio.core.client.widget.Operation) Void(org.rstudio.studio.client.server.Void)

Example 4 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.

the class ChunkSatelliteWindow method onInitialize.

@Override
protected void onInitialize(LayoutPanel mainPanel, JavaScriptObject params) {
    chunkWindowParams_ = params.cast();
    String title = "RStudio: Notebook Output";
    Window.setTitle(title);
    ChunkOutputHost chunkOutputHost = new ChunkOutputHost() {

        @Override
        public void onOutputRemoved(final ChunkOutputWidget widget) {
        }

        @Override
        public void onOutputHeightChanged(ChunkOutputWidget widget, int height, boolean ensureVisible) {
        }
    };
    chunkOutputWidget_ = new ChunkOutputWidget(chunkWindowParams_.getDocId(), chunkWindowParams_.getChunkId(), RmdChunkOptions.create(), ChunkOutputWidget.EXPANDED, // can close
    false, chunkOutputHost, ChunkOutputSize.Full);
    Element ele = chunkOutputWidget_.getElement();
    ele.addClassName(ThemeStyles.INSTANCE.selectableText());
    // Append the chunkOutputWidget as an HTML element, not as a widget.
    // Why? Chunks are widgets that are attached to the ACE editor as HTML
    // elements, not as widgets. The reason being that GWT does not support
    // triggering events for widgets that are not attached to their hierarchy.
    // Therefore, if we attach this element as a widget, GWT will remove 
    // events in some cases which will cause functionality to be lost.
    mainPanel.getElement().appendChild(chunkOutputWidget_.getElement());
    chunkOutputWidget_.getElement().getStyle().setHeight(100, Unit.PCT);
    mainPanel.addStyleName("ace_editor");
    pEventBus_.get().addHandler(ChunkSatelliteCodeExecutingEvent.TYPE, this);
    pEventBus_.get().addHandler(ChunkSatelliteCacheEditorStyleEvent.TYPE, this);
    pEventBus_.get().addHandler(ChunkPlotRefreshedEvent.TYPE, this);
    pEventBus_.get().addHandler(ChunkPlotRefreshFinishedEvent.TYPE, this);
    pEventBus_.get().addHandler(ChunkChangeEvent.TYPE, this);
    pEventBus_.get().addHandler(RmdChunkOutputFinishedEvent.TYPE, this);
    pEventBus_.get().addHandler(RmdChunkOutputEvent.TYPE, this);
    Window.addWindowClosingHandler(new ClosingHandler() {

        @Override
        public void onWindowClosing(ClosingEvent arg0) {
            server_.cleanReplayNotebookChunkPlots(chunkWindowParams_.getDocId(), chunkWindowParams_.getChunkId(), new ServerRequestCallback<Void>() {

                @Override
                public void onError(ServerError error) {
                }
            });
        }
    });
    pEventBus_.get().fireEventToMainWindow(new ChunkSatelliteWindowOpenedEvent(chunkWindowParams_.getDocId(), chunkWindowParams_.getChunkId()));
}
Also used : ChunkSatelliteWindowOpenedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.ChunkSatelliteWindowOpenedEvent) ChunkOutputHost(org.rstudio.studio.client.workbench.views.source.editors.text.rmd.ChunkOutputHost) ServerError(org.rstudio.studio.client.server.ServerError) Element(com.google.gwt.dom.client.Element) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) ClosingEvent(com.google.gwt.user.client.Window.ClosingEvent) ClosingHandler(com.google.gwt.user.client.Window.ClosingHandler)

Example 5 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.

the class Projects method createNewProject.

private void createNewProject(final NewProjectResult newProject, final boolean saveChanges) {
    // This gets a little crazy. We have several pieces of asynchronous logic
    // that each may or may not need to be executed, depending on the type
    // of project being created and on whether the previous pieces of logic
    // succeed. Plus we have this ProgressIndicator that needs to be fed
    // properly.
    final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error Creating Project");
    // Here's the command queue that will hold the various operations.
    final SerializedCommandQueue createProjectCmds = new SerializedCommandQueue();
    // WARNING: When calling addCommand, BE SURE TO PASS FALSE as the second
    // argument, to delay running of the commands until they are all
    // scheduled.
    // First, attempt to update the default project location pref
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            UIPrefs uiPrefs = pUIPrefs_.get();
            // update default project location pref if necessary
            if ((newProject.getNewDefaultProjectLocation() != null) || (newProject.getCreateGitRepo() != uiPrefs.newProjGitInit().getValue())) {
                indicator.onProgress("Saving defaults...");
                if (newProject.getNewDefaultProjectLocation() != null) {
                    uiPrefs.defaultProjectLocation().setGlobalValue(newProject.getNewDefaultProjectLocation());
                }
                if (newProject.getCreateGitRepo() != uiPrefs.newProjGitInit().getValue()) {
                    uiPrefs.newProjGitInit().setGlobalValue(newProject.getCreateGitRepo());
                }
                if (newProject.getUsePackrat() != uiPrefs.newProjUsePackrat().getValue()) {
                    uiPrefs.newProjUsePackrat().setGlobalValue(newProject.getUsePackrat());
                }
                // call the server -- in all cases continue on with
                // creating the project (swallow errors updating the pref)
                projServer_.setUiPrefs(session_.getSessionInfo().getUiPrefs(), new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onResponseReceived(Void response) {
                        continuation.execute();
                    }

                    @Override
                    public void onError(ServerError error) {
                        super.onError(error);
                        continuation.execute();
                    }
                });
            } else {
                continuation.execute();
            }
        }
    }, false);
    // Next, if necessary, clone a repo
    if (newProject.getVcsCloneOptions() != null) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                VcsCloneOptions cloneOptions = newProject.getVcsCloneOptions();
                if (cloneOptions.getVcsName().equals((VCSConstants.GIT_ID)))
                    indicator.onProgress("Cloning Git repository...");
                else
                    indicator.onProgress("Checking out SVN repository...");
                gitServer_.vcsClone(cloneOptions, new ServerRequestCallback<ConsoleProcess>() {

                    @Override
                    public void onResponseReceived(ConsoleProcess proc) {
                        final ConsoleProgressDialog consoleProgressDialog = new ConsoleProgressDialog(proc, gitServer_);
                        consoleProgressDialog.showModal();
                        proc.addProcessExitHandler(new ProcessExitEvent.Handler() {

                            @Override
                            public void onProcessExit(ProcessExitEvent event) {
                                if (event.getExitCode() == 0) {
                                    consoleProgressDialog.hide();
                                    continuation.execute();
                                } else {
                                    indicator.onCompleted();
                                }
                            }
                        });
                    }

                    @Override
                    public void onError(ServerError error) {
                        Debug.logError(error);
                        indicator.onError(error.getUserMessage());
                    }
                });
            }
        }, false);
    }
    // Next, create the project itself -- depending on the type, this
    // could involve creating an R package, or Shiny application, and so on.
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // Validate the package name if we're creating a package
            if (newProject.getNewPackageOptions() != null) {
                final String packageName = newProject.getNewPackageOptions().getPackageName();
                if (!PACKAGE_NAME_PATTERN.test(packageName)) {
                    indicator.onError("Invalid package name '" + packageName + "': " + "package names must start with a letter, and contain " + "only letters and numbers.");
                    return;
                }
            }
            indicator.onProgress("Creating project...");
            if (newProject.getNewPackageOptions() == null) {
                projServer_.createProject(newProject.getProjectFile(), newProject.getNewPackageOptions(), newProject.getNewShinyAppOptions(), newProject.getProjectTemplateOptions(), new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }
                });
            } else {
                String projectFile = newProject.getProjectFile();
                String packageDirectory = projectFile.substring(0, projectFile.lastIndexOf('/'));
                projServer_.packageSkeleton(newProject.getNewPackageOptions().getPackageName(), packageDirectory, newProject.getNewPackageOptions().getCodeFiles(), newProject.getNewPackageOptions().getUsingRcpp(), new ServerRequestCallback<RResult<Void>>() {

                    @Override
                    public void onResponseReceived(RResult<Void> response) {
                        if (response.failed())
                            indicator.onError(response.errorMessage());
                        else
                            continuation.execute();
                    }

                    @Override
                    public void onError(ServerError error) {
                        Debug.logError(error);
                        indicator.onError(error.getUserMessage());
                    }
                });
            }
        }
    }, false);
    // Next, initialize a git repo if requested
    if (newProject.getCreateGitRepo()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                indicator.onProgress("Initializing git repository...");
                String projDir = FileSystemItem.createFile(newProject.getProjectFile()).getParentPathString();
                gitServer_.gitInitRepo(projDir, new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }

                    @Override
                    public void onFailure() {
                        continuation.execute();
                    }
                });
            }
        }, false);
    }
    // Generate a new packrat project
    if (newProject.getUsePackrat()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                indicator.onProgress("Initializing packrat project...");
                String projDir = FileSystemItem.createFile(newProject.getProjectFile()).getParentPathString();
                packratServer_.packratBootstrap(projDir, false, new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }
                });
            }
        }, false);
    }
    if (newProject.getOpenInNewWindow()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                FileSystemItem project = FileSystemItem.createFile(newProject.getProjectFile());
                if (Desktop.isDesktop()) {
                    Desktop.getFrame().openProjectInNewWindow(project.getPath());
                    continuation.execute();
                } else {
                    indicator.onProgress("Preparing to open project...");
                    serverOpenProjectInNewWindow(project, newProject.getRVersion(), continuation);
                }
            }
        }, false);
    }
    // If we get here, dismiss the progress indicator
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(Command continuation) {
            indicator.onCompleted();
            if (!newProject.getOpenInNewWindow()) {
                applicationQuit_.performQuit(saveChanges, newProject.getProjectFile(), newProject.getRVersion());
            }
            continuation.execute();
        }
    }, false);
    // Now set it all in motion!
    createProjectCmds.run();
}
Also used : ConsoleProgressDialog(org.rstudio.studio.client.workbench.views.vcs.common.ConsoleProgressDialog) VcsCloneOptions(org.rstudio.studio.client.common.vcs.VcsCloneOptions) SerializedCommand(org.rstudio.core.client.SerializedCommand) SerializedCommandQueue(org.rstudio.core.client.SerializedCommandQueue) ServerError(org.rstudio.studio.client.server.ServerError) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) Command(com.google.gwt.user.client.Command) SerializedCommand(org.rstudio.core.client.SerializedCommand) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ConsoleProcess(org.rstudio.studio.client.common.console.ConsoleProcess) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs) Void(org.rstudio.studio.client.server.Void) ProcessExitEvent(org.rstudio.studio.client.common.console.ProcessExitEvent) RResult(org.rstudio.studio.client.server.remote.RResult)

Aggregations

ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)21 ServerError (org.rstudio.studio.client.server.ServerError)20 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)5 Void (org.rstudio.studio.client.server.Void)5 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 Operation (org.rstudio.core.client.widget.Operation)4 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)4 JsArray (com.google.gwt.core.client.JsArray)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 SourceDocument (org.rstudio.studio.client.workbench.views.source.model.SourceDocument)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)2 Command (com.google.gwt.user.client.Command)2 Timer (com.google.gwt.user.client.Timer)2 Handler (org.rstudio.core.client.command.Handler)2 ProfileOperationResponse (org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Element (com.google.gwt.dom.client.Element)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1