Search in sources :

Example 1 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class ConnectionsPresenter method disconnectConnection.

private void disconnectConnection(boolean prompt) {
    if (exploredConnection_ == null)
        return;
    // define connect operation
    final Operation connectOperation = new Operation() {

        @Override
        public void execute() {
            server_.getDisconnectCode(exploredConnection_.getId(), new SimpleRequestCallback<String>() {

                @Override
                public void onResponseReceived(String disconnectCode) {
                    eventBus_.fireEvent(new SendToConsoleEvent(disconnectCode, true));
                }
            });
        }
    };
    if (prompt) {
        StringBuilder builder = new StringBuilder();
        builder.append("Are you sure you want to disconnect from Spark?");
        globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Disconnect", builder.toString(), connectOperation, true);
    } else {
        connectOperation.execute();
    }
}
Also used : SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) Operation(org.rstudio.core.client.widget.Operation)

Example 2 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class RnwWeaveSelectWidget method verifyAvailable.

protected void verifyAvailable(final RnwWeave weave) {
    // first check if it was already available at startup
    TexCapabilities texCap = session_.getSessionInfo().getTexCapabilities();
    if (texCap.isRnwWeaveAvailable(weave))
        return;
    server_.getTexCapabilities(new ServerRequestCallback<TexCapabilities>() {

        @Override
        public void onResponseReceived(TexCapabilities capabilities) {
            if (!capabilities.isRnwWeaveAvailable(weave)) {
                globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Confirm Change", "The " + weave.getPackageName() + " package is required " + "for " + weave.getName() + " weaving, " + "however it is not currently installed. You should " + "ensure that " + weave.getPackageName() + " is installed " + "prior to compiling a PDF." + "\n\nAre you sure you want to change this option?", false, new Operation() {

                    @Override
                    public void execute() {
                    }
                }, new Operation() {

                    @Override
                    public void execute() {
                        setValue(rnwWeaveRegistry_.getTypes().get(0).getName());
                    }
                }, false);
            }
        }

        @Override
        public void onError(ServerError error) {
            Debug.logError(error);
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) TexCapabilities(org.rstudio.studio.client.workbench.model.TexCapabilities) Operation(org.rstudio.core.client.widget.Operation)

Example 3 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class RPubsUploadDialog method createMainWidget.

@Override
protected Widget createMainWidget() {
    Styles styles = RESOURCES.styles();
    SimplePanel mainPanel = new SimplePanel();
    mainPanel.addStyleName(styles.mainWidget());
    VerticalPanel verticalPanel = new VerticalPanel();
    HorizontalPanel headerPanel = new HorizontalPanel();
    headerPanel.addStyleName(styles.headerPanel());
    headerPanel.add(new Image(new ImageResource2x(RESOURCES.publishLarge2x())));
    Label headerLabel = new Label("Publish to RPubs");
    headerLabel.addStyleName(styles.headerLabel());
    headerPanel.add(headerLabel);
    headerPanel.setCellVerticalAlignment(headerLabel, HasVerticalAlignment.ALIGN_MIDDLE);
    verticalPanel.add(headerPanel);
    String msg;
    if (!isPublished_ && uploadId_.isEmpty()) {
        msg = "RPubs is a free service from RStudio for sharing " + "documents on the web. Click Publish to get " + "started.";
    } else {
        msg = "This document has already been published on RPubs. You can " + "choose to either update the existing RPubs document, or " + "create a new one.";
    }
    Label descLabel = new Label(msg);
    descLabel.addStyleName(styles.descLabel());
    verticalPanel.add(descLabel);
    // if we have a generator then show title and comment UI
    if (htmlGenerator_ != null) {
        Label titleLabel = new Label("Title (optional):");
        titleLabel.addStyleName(styles.fieldLabel());
        verticalPanel.add(titleLabel);
        titleTextBox_ = new TextBox();
        titleTextBox_.addStyleName(styles.titleTextBox());
        titleTextBox_.getElement().setAttribute("spellcheck", "false");
        verticalPanel.add(titleTextBox_);
        Label commentLabel = new Label("Comment (optional):");
        commentLabel.addStyleName(styles.fieldLabel());
        verticalPanel.add(commentLabel);
        commentTextArea_ = new FixedTextArea(6);
        commentTextArea_.addStyleName(styles.commentTextArea());
        verticalPanel.add(commentTextArea_);
        // not using either for now
        titleLabel.setVisible(false);
        titleTextBox_.setVisible(false);
        commentLabel.setVisible(false);
        commentTextArea_.setVisible(false);
        previewButton_ = new ThemedButton("Preview");
        previewButton_.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                htmlGenerator_.generateStaticHtml(titleTextBox_.getText().trim(), commentTextArea_.getText().trim(), new CommandWithArg<String>() {

                    @Override
                    public void execute(String rpubsFile) {
                        globalDisplay_.showHtmlFile(rpubsFile);
                    }
                });
            }
        });
        addLeftButton(previewButton_);
    }
    HTML warningLabel = new HTML("<strong>IMPORTANT: All documents published to RPubs are " + "publicly visible.</strong> You should " + "only publish documents that you wish to share publicly.");
    warningLabel.addStyleName(styles.warningLabel());
    verticalPanel.add(warningLabel);
    ThemedButton cancelButton = createCancelButton(new Operation() {

        @Override
        public void execute() {
            // if an upload is in progress then terminate it
            if (uploader_.isUploadInProgress()) {
                uploader_.terminateUpload();
            }
        }
    });
    continueButton_ = new ThemedButton("Publish", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            performUpload(false);
        }
    });
    updateButton_ = new ThemedButton("Update Existing", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            performUpload(true);
        }
    });
    createButton_ = new ThemedButton("Create New", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            performUpload(false);
        }
    });
    if (!isPublished_ && uploadId_.isEmpty()) {
        addOkButton(continueButton_);
        addCancelButton(cancelButton);
    } else {
        addOkButton(updateButton_);
        addButton(createButton_);
        addCancelButton(cancelButton);
    }
    mainPanel.setWidget(verticalPanel);
    return mainPanel;
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Label(com.google.gwt.user.client.ui.Label) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) HTML(com.google.gwt.user.client.ui.HTML) TextBox(com.google.gwt.user.client.ui.TextBox) CommandWithArg(org.rstudio.core.client.CommandWithArg) Operation(org.rstudio.core.client.widget.Operation) Image(com.google.gwt.user.client.ui.Image) ProgressImage(org.rstudio.core.client.widget.ProgressImage) ThemedButton(org.rstudio.core.client.widget.ThemedButton) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) FixedTextArea(org.rstudio.core.client.widget.FixedTextArea) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x)

Example 4 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class RStudioAPI method showDialog.

private void showDialog(String caption, String message, final String url) {
    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.addStyleName(RES.styles().textInfoWidget());
    SafeHtml safeMsg = DialogHtmlSanitizer.sanitizeHtml(message);
    HTML msg = new HTML(safeMsg.asString());
    msg.setWidth("100%");
    verticalPanel.add(msg);
    if (!StringUtil.isNullOrEmpty(url)) {
        HyperlinkLabel link = new HyperlinkLabel(url, new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                RStudioGinjector.INSTANCE.getGlobalDisplay().openWindow(url);
            }
        });
        link.addStyleName(RES.styles().installLink());
        verticalPanel.add(link);
    }
    MessageDialog dlg = new MessageDialog(MessageDialog.INFO, caption, verticalPanel);
    dlg.addButton("OK", new Operation() {

        @Override
        public void execute() {
            server_.showDialogCompleted(null, false, new SimpleRequestCallback<Void>());
        }
    }, true, false);
    dlg.showModal();
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) HTML(com.google.gwt.user.client.ui.HTML) MessageDialog(org.rstudio.core.client.widget.MessageDialog) Operation(org.rstudio.core.client.widget.Operation) HyperlinkLabel(org.rstudio.core.client.widget.HyperlinkLabel) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Example 5 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class DesktopApplicationHeader method respondToUpdateCheck.

private void respondToUpdateCheck(final UpdateCheckResult result, boolean manual) {
    boolean ignoredUpdate = false;
    if (result.getUpdateVersion().length() > 0) {
        JsArrayString ignoredUpdates = ignoredUpdates_.getIgnoredUpdates();
        for (int i = 0; i < ignoredUpdates.length(); i++) {
            if (ignoredUpdates.get(i).equals(result.getUpdateVersion())) {
                ignoredUpdate = true;
            }
        }
    }
    if (result.getUpdateVersion().length() > 0 && !ignoredUpdate) {
        ArrayList<String> buttonLabels = new ArrayList<String>();
        ArrayList<Operation> buttonOperations = new ArrayList<Operation>();
        buttonLabels.add("Quit and Download...");
        buttonOperations.add(new Operation() {

            @Override
            public void execute() {
                appQuit_.prepareForQuit("Update RStudio", new QuitContext() {

                    @Override
                    public void onReadyToQuit(boolean saveChanges) {
                        Desktop.getFrame().browseUrl(result.getUpdateUrl());
                        appQuit_.performQuit(saveChanges);
                    }
                });
            }
        });
        buttonLabels.add("Remind Later");
        buttonOperations.add(new Operation() {

            @Override
            public void execute() {
            // Don't do anything here; the prompt will re-appear the next
            // time we do an update check
            }
        });
        // Only provide the option to ignore the update if it's not urgent.
        if (result.getUpdateUrgency() == 0) {
            buttonLabels.add("Ignore Update");
            buttonOperations.add(new Operation() {

                @Override
                public void execute() {
                    ignoredUpdates_.addIgnoredUpdate(result.getUpdateVersion());
                    ignoredUpdatesDirty_ = true;
                }
            });
        }
        globalDisplay_.showGenericDialog(GlobalDisplay.MSG_QUESTION, "Update Available", result.getUpdateMessage(), buttonLabels, buttonOperations, 0);
    } else if (manual) {
        globalDisplay_.showMessage(GlobalDisplay.MSG_INFO, "No Update Available", "You're using the newest version of RStudio.");
    }
}
Also used : QuitContext(org.rstudio.studio.client.application.ApplicationQuit.QuitContext) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) Operation(org.rstudio.core.client.widget.Operation)

Aggregations

Operation (org.rstudio.core.client.widget.Operation)47 ServerError (org.rstudio.studio.client.server.ServerError)8 Command (com.google.gwt.user.client.Command)7 ArrayList (java.util.ArrayList)6 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)5 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)5 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)4 SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ProgressOperation (org.rstudio.core.client.widget.ProgressOperation)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 Timer (com.google.gwt.user.client.Timer)2 HTML (com.google.gwt.user.client.ui.HTML)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 WindowEx (org.rstudio.core.client.dom.WindowEx)2 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2