Search in sources :

Example 51 with Command

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

the class TextEditingTarget method doHtmlPreview.

private void doHtmlPreview(final Provider<HTMLPreviewParams> pParams) {
    // command to show the preview window
    final Command showPreviewWindowCommand = new Command() {

        @Override
        public void execute() {
            HTMLPreviewParams params = pParams.get();
            events_.fireEvent(new ShowHTMLPreviewEvent(params));
        }
    };
    // command to run the preview
    final Command runPreviewCommand = new Command() {

        @Override
        public void execute() {
            final HTMLPreviewParams params = pParams.get();
            server_.previewHTML(params, new SimpleRequestCallback<Boolean>());
        }
    };
    if (pParams.get().isNotebook()) {
        saveThenExecute(null, new Command() {

            @Override
            public void execute() {
                generateNotebook(new Command() {

                    @Override
                    public void execute() {
                        showPreviewWindowCommand.execute();
                        runPreviewCommand.execute();
                    }
                });
            }
        });
    } else // due to popup activation rules but at least it will show up
    if (isNewDoc()) {
        saveThenExecute(null, CommandUtil.join(showPreviewWindowCommand, runPreviewCommand));
    } else // beat the popup blockers) then save & run
    if (dirtyState().getValue()) {
        showPreviewWindowCommand.execute();
        saveThenExecute(null, runPreviewCommand);
    } else // otherwise show the preview window then run the preview
    {
        showPreviewWindowCommand.execute();
        runPreviewCommand.execute();
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ShowHTMLPreviewEvent(org.rstudio.studio.client.htmlpreview.events.ShowHTMLPreviewEvent) HTMLPreviewParams(org.rstudio.studio.client.htmlpreview.model.HTMLPreviewParams)

Example 52 with Command

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

the class ChunkOutputWidget method showChunkOutputUnit.

// Private methods ---------------------------------------------------------
private void showChunkOutputUnit(RmdChunkOutputUnit unit, int mode, boolean replay, boolean ensureVisible) {
    // nothing to show)
    if (unit.getType() == RmdChunkOutputUnit.TYPE_TEXT && unit.getArray().length() < 1)
        return;
    // are not visible)
    if (unit.getType() != RmdChunkOutputUnit.TYPE_ORDINAL)
        initializeOutput(unit.getType());
    switch(unit.getType()) {
        case RmdChunkOutputUnit.TYPE_TEXT:
            presenter_.showConsoleOutput(unit.getArray());
            break;
        case RmdChunkOutputUnit.TYPE_HTML:
            final RenderTimer widgetTimer = new RenderTimer();
            presenter_.showHtmlOutput(unit.getString(), (NotebookHtmlMetadata) unit.getMetadata().cast(), unit.getOrdinal(), new Command() {

                @Override
                public void execute() {
                    widgetTimer.cancel();
                }
            });
            break;
        case RmdChunkOutputUnit.TYPE_PLOT:
            final RenderTimer plotTimer = new RenderTimer();
            presenter_.showPlotOutput(unit.getString(), (NotebookPlotMetadata) unit.getMetadata().cast(), unit.getOrdinal(), new Command() {

                @Override
                public void execute() {
                    plotTimer.cancel();
                }
            });
            break;
        case RmdChunkOutputUnit.TYPE_ERROR:
            // override visibility flag when there's an error in batch mode
            if (!replay && !options_.error() && mode == NotebookQueueUnit.EXEC_MODE_BATCH)
                ensureVisible = true;
            hasErrors_ = true;
            presenter_.showErrorOutput(unit.getUnhandledError());
            break;
        case RmdChunkOutputUnit.TYPE_ORDINAL:
            // used to reserve a plot placeholder 
            presenter_.showOrdinalOutput(unit.getOrdinal());
            break;
        case RmdChunkOutputUnit.TYPE_DATA:
            presenter_.showDataOutput(unit.getOuputObject(), (NotebookFrameMetadata) unit.getMetadata().cast(), unit.getOrdinal());
            break;
    }
}
Also used : Command(com.google.gwt.user.client.Command)

Example 53 with Command

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

the class WebTextInput method promptForTextWithOption.

@Override
public void promptForTextWithOption(String title, String label, String initialValue, final boolean usePasswordMask, String extraOptionPrompt, boolean extraOptionDefault, int selectionStart, int selectionLength, String okButtonCaption, final ProgressOperationWithInput<PromptWithOptionResult> okOperation, Operation cancelOperation) {
    // This variable introduces a level of pointer indirection that lets us
    // get around passing TextEntryModalDialog a reference to itself in its
    // own constructor.
    final Value<TextEntryModalDialog> pDialog = new Value<TextEntryModalDialog>(null);
    final TextEntryModalDialog dialog = new TextEntryModalDialog(title, label, initialValue, usePasswordMask, extraOptionPrompt, extraOptionDefault, false, selectionStart, selectionLength, okButtonCaption, 300, new ProgressOperationWithInput<String>() {

        @Override
        public void execute(String input, ProgressIndicator indicator) {
            PromptWithOptionResult result = new PromptWithOptionResult();
            result.input = input;
            result.extraOption = pDialog.getValue().getExtraOption();
            okOperation.execute(result, indicator);
        }
    }, cancelOperation) {

        @Override
        protected void positionAndShowDialog(final Command onCompleted) {
            setPopupPositionAndShow(new PositionCallback() {

                @Override
                public void setPosition(int offsetWidth, int offsetHeight) {
                    int left = (Window.getClientWidth() / 2) - (offsetWidth / 2);
                    int top = (Window.getClientHeight() / 2) - (offsetHeight / 2);
                    if (usePasswordMask)
                        top = 50;
                    setPopupPosition(left, top);
                    onCompleted.execute();
                }
            });
        }
    };
    pDialog.setValue(dialog, false);
    dialog.showModal();
}
Also used : TextEntryModalDialog(org.rstudio.core.client.widget.TextEntryModalDialog) Command(com.google.gwt.user.client.Command) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) Value(org.rstudio.studio.client.common.Value) PromptWithOptionResult(org.rstudio.core.client.MessageDisplay.PromptWithOptionResult)

Example 54 with Command

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

the class MathJax method removeChunkOutputWidget.

private void removeChunkOutputWidget(final ChunkOutputWidget widget) {
    final PinnedLineWidget plw = cowToPlwMap_.get(widget);
    if (plw == null)
        return;
    FadeOutAnimation anim = new FadeOutAnimation(widget, new Command() {

        @Override
        public void execute() {
            cowToPlwMap_.remove(widget);
            lwToPlwMap_.remove(plw.getLineWidget());
            plw.detach();
        }
    });
    anim.run(400);
}
Also used : FadeOutAnimation(org.rstudio.core.client.layout.FadeOutAnimation) Command(com.google.gwt.user.client.Command) ForEachCommand(org.rstudio.core.client.MapUtil.ForEachCommand) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget)

Example 55 with Command

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

the class SlideNavigationPresenter method onSlideNavigationChanged.

@Override
public void onSlideNavigationChanged(SlideNavigationChangedEvent event) {
    slideNavigation_ = event.getNavigation();
    SlideNavigationMenu navigationMenu = view_.getNavigationMenu();
    navigationMenu.clear();
    if (slideNavigation_ != null) {
        JsArray<SlideNavigationItem> items = slideNavigation_.getItems();
        for (int i = 0; i < items.length(); i++) {
            // get slide
            final SlideNavigationItem item = items.get(i);
            // build html
            SafeHtmlBuilder menuHtml = new SafeHtmlBuilder();
            for (int j = 0; j < item.getIndent(); j++) menuHtml.appendHtmlConstant("&nbsp;&nbsp;&nbsp;");
            menuHtml.appendEscaped(item.getTitle());
            navigationMenu.addItem(new MenuItem(menuHtml.toSafeHtml(), new Command() {

                @Override
                public void execute() {
                    view_.navigate(item.getIndex());
                }
            }));
        }
        navigationMenu.setVisible(true);
        navigationMenu.setDropDownVisible(slideNavigation_.getItems().length() > 1);
    } else {
        navigationMenu.setVisible(false);
    }
}
Also used : Command(com.google.gwt.user.client.Command) MenuItem(com.google.gwt.user.client.ui.MenuItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) SlideNavigationItem(org.rstudio.studio.client.common.presentation.model.SlideNavigationItem)

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