Search in sources :

Example 91 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class UserCommandManager method onRegisterUserCommand.

private void onRegisterUserCommand(RegisterUserCommandEvent event) {
    final String name = event.getData().getName();
    JsArrayString shortcutStrings = event.getData().getShortcuts();
    for (int i = 0; i < shortcutStrings.length(); i++) {
        String shortcutString = shortcutStrings.get(i);
        KeySequence sequence = KeySequence.fromShortcutString(shortcutString);
        assert sequence != null : "Failed to parse string '" + shortcutString + "'";
        KeyboardShortcut shortcut = new KeyboardShortcut(sequence);
        UserCommand command = new UserCommand(name, new Command() {

            @Override
            public void execute() {
                events_.fireEvent(new ExecuteUserCommandEvent(name));
            }
        });
        commandMap_.put(shortcut, command);
    }
}
Also used : Command(com.google.gwt.user.client.Command) ExecuteUserCommandEvent(org.rstudio.studio.client.server.remote.ExecuteUserCommandEvent) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence)

Example 92 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class RStudio method delayLoadApplication.

private void delayLoadApplication(final Command dismissProgressAnimation) {
    final RunAsyncCallback runCallback = new RunAsyncCallback() {

        public void onFailure(Throwable reason) {
            dismissProgressAnimation.execute();
            Window.alert("Error: " + reason.getMessage());
        }

        public void onSuccess() {
            // TODO (gary) This early loading of XTermWidget dependencies needs to be
            // removed once I figure out why XTermWidget.load in 
            // TerminalPane:createMainWidget) isn't sufficient. Suspect due to xterm.js
            // loading its add-ons (fit.js) but need to investigate. 
            XTermWidget.load(new Command() {

                public void execute() {
                    AceEditor.load(new Command() {

                        public void execute() {
                            ensureStylesInjected();
                            String view = Window.Location.getParameter("view");
                            if (VCSApplication.NAME.equals(view)) {
                                RStudioGinjector.INSTANCE.getVCSApplication().go(RootLayoutPanel.get(), dismissProgressAnimation);
                            } else if (HTMLPreviewApplication.NAME.equals(view)) {
                                RStudioGinjector.INSTANCE.getHTMLPreviewApplication().go(RootLayoutPanel.get(), dismissProgressAnimation);
                            } else if (ShinyApplicationSatellite.NAME.equals(view)) {
                                RStudioGinjector.INSTANCE.getShinyApplicationSatellite().go(RootLayoutPanel.get(), dismissProgressAnimation);
                            } else if (RmdOutputSatellite.NAME.equals(view)) {
                                RStudioGinjector.INSTANCE.getRmdOutputSatellite().go(RootLayoutPanel.get(), dismissProgressAnimation);
                            } else if (view != null && view.startsWith(SourceSatellite.NAME_PREFIX)) {
                                SourceSatellite satellite = new SourceSatellite(view);
                                satellite.go(RootLayoutPanel.get(), dismissProgressAnimation);
                            } else if (view != null && view.startsWith(ChunkSatellite.NAME_PREFIX)) {
                                ChunkSatellite satellite = new ChunkSatellite(view);
                                satellite.go(RootLayoutPanel.get(), dismissProgressAnimation);
                            } else {
                                RStudioGinjector.INSTANCE.getApplication().go(RootLayoutPanel.get(), dismissProgressAnimation);
                            }
                        }
                    });
                }
            });
        }
    };
    GWT.runAsync(runCallback);
}
Also used : RunAsyncCallback(com.google.gwt.core.client.RunAsyncCallback) Command(com.google.gwt.user.client.Command) SourceSatellite(org.rstudio.studio.client.workbench.views.source.SourceSatellite) ChunkSatellite(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkSatellite)

Example 93 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class RStudio method showProgress.

private Command showProgress() {
    final Label background = new Label();
    background.getElement().getStyle().setZIndex(1000);
    background.getElement().getStyle().setBackgroundColor("#e1e2e5");
    final RootLayoutPanel rootPanel = RootLayoutPanel.get();
    rootPanel.add(background);
    rootPanel.setWidgetTopBottom(background, 0, Style.Unit.PX, 0, Style.Unit.PX);
    rootPanel.setWidgetLeftRight(background, 0, Style.Unit.PX, 0, Style.Unit.PX);
    String progressUrl = ProgressImages.createLargeGray().getUrl();
    StringBuilder str = new StringBuilder();
    str.append("<img src=\"");
    str.append(progressUrl);
    str.append("\"");
    if (BrowseCap.devicePixelRatio() > 1.0)
        str.append("width=24 height=24");
    str.append("/>");
    final SimplePanel progressPanel = new SimplePanel();
    final Element div = progressPanel.getElement();
    div.setInnerHTML(str.toString());
    div.getStyle().setWidth(100, Style.Unit.PCT);
    div.getStyle().setMarginTop(200, Style.Unit.PX);
    div.getStyle().setProperty("textAlign", "center");
    div.getStyle().setZIndex(1000);
    ElementIds.assignElementId(div, ElementIds.LOADING_SPINNER);
    rootPanel.add(progressPanel);
    return new Command() {

        public void execute() {
            try {
                rootPanel.remove(progressPanel);
                rootPanel.remove(background);
            } catch (Exception e) {
                Debug.log(e.toString());
            }
        }
    };
}
Also used : Command(com.google.gwt.user.client.Command) Element(com.google.gwt.dom.client.Element) Label(com.google.gwt.user.client.ui.Label) SlideLabel(org.rstudio.core.client.widget.SlideLabel) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) RootLayoutPanel(com.google.gwt.user.client.ui.RootLayoutPanel)

Example 94 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class ModalDialogBase method showModal.

public void showModal() {
    if (mainWidget_ == null) {
        mainWidget_ = createMainWidget();
        // get the main widget to line up with the right edge of the buttons.
        mainWidget_.getElement().getStyle().setMarginRight(2, Unit.PX);
        mainPanel_.insert(mainWidget_, 0);
    }
    originallyActiveElement_ = DomUtils.getActiveElement();
    if (originallyActiveElement_ != null)
        originallyActiveElement_.blur();
    // position the dialog
    positionAndShowDialog(new Command() {

        @Override
        public void execute() {
            // defer shown notification to allow all elements to render
            // before attempting to interact w/ them programatically (e.g. setFocus)
            Timer timer = new Timer() {

                public void run() {
                    onDialogShown();
                }
            };
            timer.schedule(100);
        }
    });
}
Also used : Timer(com.google.gwt.user.client.Timer) Command(com.google.gwt.user.client.Command)

Example 95 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class ApplicationQuit method prepareForQuit.

public void prepareForQuit(final String caption, final boolean forceSaveAll, final QuitContext quitContext) {
    boolean busy = workbenchContext_.isServerBusy() || workbenchContext_.isTerminalBusy();
    String msg = null;
    if (busy) {
        if (workbenchContext_.isServerBusy() && !workbenchContext_.isTerminalBusy())
            msg = "The R session is currently busy.";
        else if (workbenchContext_.isServerBusy() && workbenchContext_.isTerminalBusy())
            msg = "The R session and the terminal are currently busy.";
        else
            msg = "The terminal is currently busy.";
    }
    eventBus_.fireEvent(new QuitInitiatedEvent());
    if (busy && !forceSaveAll) {
        globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, caption, msg + " Are you sure you want to quit?", new Operation() {

            @Override
            public void execute() {
                handleUnsavedChanges(caption, forceSaveAll, quitContext);
            }
        }, true);
    } else {
        // if we aren't restoring source documents then close them all now
        if (!pUiPrefs_.get().restoreSourceDocuments().getValue()) {
            sourceShim_.closeAllSourceDocs(caption, new Command() {

                @Override
                public void execute() {
                    handleUnsavedChanges(caption, forceSaveAll, quitContext);
                }
            });
        } else {
            handleUnsavedChanges(caption, forceSaveAll, quitContext);
        }
    }
}
Also used : Command(com.google.gwt.user.client.Command) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) QuitInitiatedEvent(org.rstudio.studio.client.application.events.QuitInitiatedEvent) Operation(org.rstudio.core.client.widget.Operation)

Aggregations

Command (com.google.gwt.user.client.Command)189 AppCommand (org.rstudio.core.client.command.AppCommand)39 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)38 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)21 JsArrayString (com.google.gwt.core.client.JsArrayString)16 Test (org.junit.Test)16 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)15 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)15 ArrayList (java.util.ArrayList)11 ServerError (org.rstudio.studio.client.server.ServerError)11 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)10 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)10 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)9 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)8 MenuItem (com.google.gwt.user.client.ui.MenuItem)8 Handler (org.rstudio.core.client.command.Handler)8 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)8 Widget (com.google.gwt.user.client.ui.Widget)7 Operation (org.rstudio.core.client.widget.Operation)7 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)7