Search in sources :

Example 21 with VoidServerRequestCallback

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

the class TerminalSession method sendUserInput.

/**
    * Send user input to the server, breaking down into chunks. We do this
    * for when a large amount of text is pasted into the terminal; we don't
    * want to overwhelm the RPC.
    * @param userInput string to send
    */
private void sendUserInput() {
    final int MAXCHUNK = 128;
    String userInput;
    if (inputQueue_.length() == 0) {
        return;
    }
    if (inputQueue_.length() > MAXCHUNK) {
        userInput = inputQueue_.substring(0, MAXCHUNK);
        inputQueue_.delete(0, MAXCHUNK);
    } else {
        userInput = inputQueue_.toString();
        inputQueue_.setLength(0);
    }
    // message so server can put messages back in order
    if (BrowseCap.isWindowsDesktop()) {
        if (inputSequence_ == ShellInput.IGNORE_SEQUENCE) {
            // First message sent for this client-side terminal instance, start
            // by flushing the server-side queue to reset server's "last-sequence"
            // back to default.
            inputSequence_ = ShellInput.FLUSH_SEQUENCE;
        } else if (inputSequence_ == ShellInput.FLUSH_SEQUENCE) {
            // Last message has flushed server, start tracking sequences again.
            inputSequence_ = 0;
        } else if (inputSequence_ >= Integer.MAX_VALUE - 100) {
            // Very diligent typist!  Tell server to flush its input
            // queue, temporarily ignoring sequences.
            inputSequence_ = ShellInput.FLUSH_SEQUENCE;
        } else {
            inputSequence_++;
        }
    }
    socket_.dispatchInput(inputSequence_, userInput, new VoidServerRequestCallback() {

        @Override
        public void onResponseReceived(Void response) {
            sendUserInput();
        }

        @Override
        public void onError(ServerError error) {
            writeError(error.getUserMessage());
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) Void(org.rstudio.studio.client.server.Void)

Example 22 with VoidServerRequestCallback

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

the class EnvironmentPresenter method onClearWorkspace.

void onClearWorkspace() {
    view_.bringToFront();
    final List<String> objectNames = view_.getSelectedObjects();
    new ClearAllDialog(objectNames.size(), new ProgressOperationWithInput<Boolean>() {

        @Override
        public void execute(Boolean includeHidden, ProgressIndicator indicator) {
            indicator.onProgress("Removing objects...");
            if (objectNames.size() == 0) {
                server_.removeAllObjects(includeHidden, new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        view_.clearSelection();
                        view_.clearObjects();
                    }
                });
            } else {
                server_.removeObjects(objectNames, new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        view_.clearSelection();
                        for (String obj : objectNames) {
                            view_.removeObject(obj);
                        }
                    }
                });
            }
        }
    }).showModal();
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) JsArrayString(com.google.gwt.core.client.JsArrayString) ProgressOperationWithInput(org.rstudio.core.client.widget.ProgressOperationWithInput)

Example 23 with VoidServerRequestCallback

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

the class EditSnippetsDialog method attemptSaveAndClose.

private void attemptSaveAndClose() {
    // record pending edits
    recordEditorState();
    // check for edits we need to save
    JsArray<SnippetData> changedSnippets = JsArray.createArray().cast();
    for (int i = 0; i < snippetTypes_.getItemCount(); i++) {
        EditableSnippets snippets = snippetTypes_.getItemAtIdx(i);
        String edits = snippets.getPendingEdits();
        if (edits != null) {
            String mode = snippets.getEditorMode();
            JavaScriptException ex = SnippetHelper.loadSnippetsForMode(mode, edits);
            if (ex != null) {
                snippetTypes_.setSelectedIndex(i);
                globalDisplay_.showErrorMessage("Error Applying Snippets (" + snippets.getFileTypeLabel() + ")", ex.getDescription());
                // early return (don't close dialog)
                return;
            }
            changedSnippets.push(SnippetData.create(mode, edits));
        }
    }
    // perform the save then close the dialog
    if (changedSnippets.length() > 0) {
        server_.saveSnippets(changedSnippets, new VoidServerRequestCallback() {

            @Override
            protected void onSuccess() {
                closeDialog();
            }
        });
    } else {
        closeDialog();
    }
}
Also used : SnippetData(org.rstudio.studio.client.workbench.snippets.model.SnippetData) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) JavaScriptException(com.google.gwt.core.client.JavaScriptException)

Example 24 with VoidServerRequestCallback

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

the class ApplicationInterrupt method interruptR.

public void interruptR(final InterruptHandler handler) {
    if (interruptRequestCounter_ == 0) {
        interruptRequestCounter_ = 1;
        interruptUnresponsiveTimer_ = new Timer() {

            @Override
            public void run() {
                showInterruptUnresponsiveDialog();
            }
        };
        interruptUnresponsiveTimer_.schedule(10000);
        eventBus_.fireEvent(new InterruptStatusEvent(InterruptStatusEvent.INTERRUPT_INITIATED));
        server_.interrupt(new VoidServerRequestCallback() {

            @Override
            public void onSuccess() {
                eventBus_.fireEvent(new InterruptStatusEvent(InterruptStatusEvent.INTERRUPT_COMPLETED));
                finishInterrupt(handler);
            }

            @Override
            public void onFailure() {
                finishInterrupt(handler);
            }
        });
    } else {
        interruptRequestCounter_++;
        if (interruptRequestCounter_ >= 3) {
            interruptUnresponsiveTimer_.cancel();
            showInterruptUnresponsiveDialog();
        }
    }
}
Also used : Timer(com.google.gwt.user.client.Timer) InterruptStatusEvent(org.rstudio.studio.client.application.events.InterruptStatusEvent) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback)

Example 25 with VoidServerRequestCallback

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

the class ApplicationQuit method onSuspendAndRestart.

@Override
public void onSuspendAndRestart(final SuspendAndRestartEvent event) {
    // Ignore nested restarts once restart starts
    if (suspendingAndRestarting_)
        return;
    // set restart pending for desktop
    setPendinqQuit(DesktopFrame.PENDING_QUIT_AND_RESTART);
    final TimedProgressIndicator progress = new TimedProgressIndicator(globalDisplay_.getProgressIndicator("Error"));
    progress.onTimedProgress("Restarting R", 1000);
    final Operation onRestartComplete = new Operation() {

        @Override
        public void execute() {
            suspendingAndRestarting_ = false;
            progress.onCompleted();
        }
    };
    // perform the suspend and restart
    suspendingAndRestarting_ = true;
    eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_INITIATED));
    server_.suspendForRestart(event.getSuspendOptions(), new VoidServerRequestCallback() {

        @Override
        protected void onSuccess() {
            // send pings until the server restarts
            sendPing(event.getAfterRestartCommand(), 200, 25, new Command() {

                @Override
                public void execute() {
                    onRestartComplete.execute();
                    eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_COMPLETED));
                }
            });
        }

        @Override
        protected void onFailure() {
            onRestartComplete.execute();
            eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_COMPLETED));
            setPendinqQuit(DesktopFrame.PENDING_QUIT_NONE);
        }
    });
}
Also used : TimedProgressIndicator(org.rstudio.studio.client.common.TimedProgressIndicator) Command(com.google.gwt.user.client.Command) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) RestartStatusEvent(org.rstudio.studio.client.application.events.RestartStatusEvent) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) Operation(org.rstudio.core.client.widget.Operation)

Aggregations

VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)44 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)14 Handler (org.rstudio.core.client.command.Handler)8 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)7 ServerError (org.rstudio.studio.client.server.ServerError)7 Command (com.google.gwt.user.client.Command)6 Operation (org.rstudio.core.client.widget.Operation)4 ProgressOperation (org.rstudio.core.client.widget.ProgressOperation)4 Void (org.rstudio.studio.client.server.Void)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)3 ArrayList (java.util.ArrayList)3 AppCommand (org.rstudio.core.client.command.AppCommand)3 ProgressOperationWithInput (org.rstudio.core.client.widget.ProgressOperationWithInput)3 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)3 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)3 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)3 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)3 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)2