Search in sources :

Example 1 with CommandWithArg

use of org.rstudio.core.client.CommandWithArg in project rstudio by rstudio.

the class ProfilerEditingTarget method initialize.

public void initialize(SourceDocument document, FileSystemContext fileContext, FileType type, Provider<String> defaultNameProvider) {
    // initialize doc, view, and presenter
    doc_ = document;
    PublishHtmlSource publishHtmlSource = new PublishHtmlSource() {

        @Override
        public void generatePublishHtml(CommandWithArg<String> onComplete) {
            onComplete.execute(htmlLocalPath_);
        }

        @Override
        public String getTitle() {
            return "Profile";
        }
    };
    view_ = new ProfilerEditingTargetWidget(commands_, publishHtmlSource);
    defaultNameProvider_ = defaultNameProvider;
    getName().setValue(getAndSetInitialName());
    presenter_.attach(doc_, view_);
}
Also used : PublishHtmlSource(org.rstudio.studio.client.rsconnect.model.PublishHtmlSource) CommandWithArg(org.rstudio.core.client.CommandWithArg)

Example 2 with CommandWithArg

use of org.rstudio.core.client.CommandWithArg 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 3 with CommandWithArg

use of org.rstudio.core.client.CommandWithArg in project rstudio by rstudio.

the class ModifyKeyboardShortcutsWidget method collectShortcuts.

private void collectShortcuts() {
    final List<KeyboardShortcutEntry> bindings = new ArrayList<KeyboardShortcutEntry>();
    SerializedCommandQueue queue = new SerializedCommandQueue();
    // Load addins discovered as part of package exports. This registers
    // the addin, with the actual keybinding to be registered later,
    // if discovered.
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            RAddins rAddins = addins_.getRAddins();
            for (String key : JsUtil.asIterable(rAddins.keys())) {
                RAddin addin = rAddins.get(key);
                bindings.add(new KeyboardShortcutEntry(addin.getPackage() + "::" + addin.getBinding(), addin.getName(), new KeySequence(), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
            }
            continuation.execute();
        }
    });
    // Load saved addin bindings
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            addins_.loadBindings(new CommandWithArg<EditorKeyBindings>() {

                @Override
                public void execute(EditorKeyBindings addinBindings) {
                    for (String commandId : addinBindings.iterableKeys()) {
                        EditorKeyBinding addinBinding = addinBindings.get(commandId);
                        for (KeyboardShortcutEntry binding : bindings) {
                            if (binding.getId() == commandId) {
                                List<KeySequence> keys = addinBinding.getKeyBindings();
                                if (keys.size() >= 1)
                                    binding.setDefaultKeySequence(keys.get(0));
                                if (keys.size() >= 2) {
                                    for (int i = 1; i < keys.size(); i++) {
                                        bindings.add(new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys.get(i), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
                                    }
                                }
                            }
                        }
                    }
                    continuation.execute();
                }
            });
        }
    });
    // Ace loading command
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // Ace Commands
            JsArray<AceCommand> aceCommands = editorCommands_.getCommands();
            for (int i = 0; i < aceCommands.length(); i++) {
                AceCommand command = aceCommands.get(i);
                JsArrayString shortcuts = command.getBindingsForCurrentPlatform();
                if (shortcuts != null) {
                    String id = command.getInternalName();
                    String name = command.getDisplayName();
                    boolean custom = command.isCustomBinding();
                    for (int j = 0; j < shortcuts.length(); j++) {
                        String shortcut = shortcuts.get(j);
                        KeySequence keys = KeySequence.fromShortcutString(shortcut);
                        int type = KeyboardShortcutEntry.TYPE_EDITOR_COMMAND;
                        bindings.add(new KeyboardShortcutEntry(id, name, keys, type, custom, AppCommand.Context.Editor));
                    }
                }
            }
            continuation.execute();
        }
    });
    // RStudio commands
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // RStudio Commands
            appCommands_.loadBindings(new CommandWithArg<EditorKeyBindings>() {

                @Override
                public void execute(final EditorKeyBindings customBindings) {
                    Map<String, AppCommand> commands = commands_.getCommands();
                    for (Map.Entry<String, AppCommand> entry : commands.entrySet()) {
                        AppCommand command = entry.getValue();
                        if (isExcludedCommand(command))
                            continue;
                        String id = command.getId();
                        String name = getAppCommandName(command);
                        int type = KeyboardShortcutEntry.TYPE_RSTUDIO_COMMAND;
                        boolean isCustom = customBindings.hasKey(id);
                        List<KeySequence> keySequences = new ArrayList<KeySequence>();
                        if (isCustom)
                            keySequences = customBindings.get(id).getKeyBindings();
                        else
                            keySequences.add(command.getKeySequence());
                        for (KeySequence keys : keySequences) {
                            KeyboardShortcutEntry binding = new KeyboardShortcutEntry(id, name, keys, type, isCustom, command.getContext());
                            bindings.add(binding);
                        }
                    }
                    continuation.execute();
                }
            });
        }
    });
    // Sort and finish up
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            Collections.sort(bindings, new Comparator<KeyboardShortcutEntry>() {

                @Override
                public int compare(KeyboardShortcutEntry o1, KeyboardShortcutEntry o2) {
                    if (o1.getContext() != o2.getContext())
                        return o1.getContext().compareTo(o2.getContext());
                    return o1.getName().compareTo(o2.getName());
                }
            });
            originalBindings_ = bindings;
            updateData(bindings);
            continuation.execute();
        }
    });
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(Command continuation) {
            if (initialFilterText_ != null) {
                filterWidget_.setText(initialFilterText_);
                filter();
            }
            continuation.execute();
        }
    });
    // Exhaust the queue
    queue.run();
}
Also used : SerializedCommand(org.rstudio.core.client.SerializedCommand) RAddins(org.rstudio.studio.client.workbench.addins.Addins.RAddins) SerializedCommandQueue(org.rstudio.core.client.SerializedCommandQueue) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) CommandWithArg(org.rstudio.core.client.CommandWithArg) Comparator(java.util.Comparator) EditorKeyBinding(org.rstudio.core.client.command.EditorCommandManager.EditorKeyBinding) EditorKeyBindings(org.rstudio.core.client.command.EditorCommandManager.EditorKeyBindings) JsArray(com.google.gwt.core.client.JsArray) RAddin(org.rstudio.studio.client.workbench.addins.Addins.RAddin) JsArrayString(com.google.gwt.core.client.JsArrayString) Command(com.google.gwt.user.client.Command) SerializedCommand(org.rstudio.core.client.SerializedCommand) AceCommand(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceCommand) AceCommand(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceCommand) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with CommandWithArg

use of org.rstudio.core.client.CommandWithArg in project rstudio by rstudio.

the class DependencyManager method processDependencyRequest.

private void processDependencyRequest(final DependencyRequest req) {
    // convert dependencies to JsArray, excluding satisfied dependencies
    final JsArray<Dependency> deps = JsArray.createArray().cast();
    for (int i = 0; i < req.dependencies.length; i++) {
        boolean satisfied = false;
        for (Dependency d : satisfied_) {
            if (req.dependencies[i].isEqualTo(d)) {
                satisfied = true;
                break;
            }
        }
        if (!satisfied)
            deps.push(req.dependencies[i]);
    }
    // if no unsatisfied dependencies were found, we're done already
    if (deps.length() == 0) {
        req.onComplete.execute(true);
        return;
    }
    // create progress indicator
    final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 250, req.progressCaption + "...").getIndicator();
    // query for unsatisfied dependencies
    server_.unsatisfiedDependencies(deps, req.silentEmbeddedUpdate, new ServerRequestCallback<JsArray<Dependency>>() {

        @Override
        public void onResponseReceived(final JsArray<Dependency> unsatisfiedDeps) {
            progress.onCompleted();
            updateSatisfied(deps, unsatisfiedDeps);
            // if we've satisfied all dependencies then execute the command
            if (unsatisfiedDeps.length() == 0) {
                req.onComplete.execute(true);
                return;
            }
            // check to see if we can satisfy the version requirement for all
            // dependencies
            String unsatisfiedVersions = "";
            for (int i = 0; i < unsatisfiedDeps.length(); i++) {
                if (!unsatisfiedDeps.get(i).getVersionSatisfied()) {
                    unsatisfiedVersions += unsatisfiedDeps.get(i).getName() + " " + unsatisfiedDeps.get(i).getVersion();
                    String version = unsatisfiedDeps.get(i).getAvailableVersion();
                    if (version.isEmpty())
                        unsatisfiedVersions += " is not available\n";
                    else
                        unsatisfiedVersions += " is required but " + version + " is available\n";
                }
            }
            if (!unsatisfiedVersions.isEmpty()) {
                // error if we can't satisfy requirements
                globalDisplay_.showErrorMessage(StringUtil.isNullOrEmpty(req.userAction) ? "Packages Not Found" : req.userAction, "Required package versions could not be found:\n\n" + unsatisfiedVersions + "\n" + "Check that getOption(\"repos\") refers to a CRAN " + "repository that contains the needed package versions.");
                req.onComplete.execute(false);
            } else {
                // otherwise ask the user if they want to install the 
                // unsatisifed dependencies
                final CommandWithArg<Boolean> installCommand = new CommandWithArg<Boolean>() {

                    @Override
                    public void execute(Boolean confirmed) {
                        // bail if user didn't confirm
                        if (!confirmed) {
                            req.onComplete.execute(false);
                            return;
                        }
                        // the incoming JsArray from the server may not serialize
                        // as expected when this code is executed from a satellite
                        // (see RemoteServer.sendRequestViaMainWorkbench), so we
                        // clone it before passing to the dependency installer
                        JsArray<Dependency> newArray = JsArray.createArray().cast();
                        newArray.setLength(unsatisfiedDeps.length());
                        for (int i = 0; i < unsatisfiedDeps.length(); i++) {
                            newArray.set(i, unsatisfiedDeps.get(i));
                        }
                        installDependencies(newArray, req.silentEmbeddedUpdate, req.onComplete);
                    }
                };
                if (req.userPrompt != null) {
                    req.userPrompt.execute(describeDepPkgs(unsatisfiedDeps), new Command() {

                        @Override
                        public void execute() {
                            installCommand.execute(true);
                        }
                    });
                } else {
                    confirmPackageInstallation(req.userAction, unsatisfiedDeps, installCommand);
                }
            }
        }

        @Override
        public void onError(ServerError error) {
            progress.onError(error.getUserMessage());
            req.onComplete.execute(false);
        }
    });
}
Also used : JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) Dependency(org.rstudio.studio.client.common.dependencies.model.Dependency) CommandWithArg(org.rstudio.core.client.CommandWithArg) Command(com.google.gwt.user.client.Command) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator)

Example 5 with CommandWithArg

use of org.rstudio.core.client.CommandWithArg in project rstudio by rstudio.

the class ProjectOpener method showOpenProjectDialog.

public void showOpenProjectDialog(FileSystemContext fsContext, ProjectsServerOperations server, String defaultLocation, int defaultType, boolean showNewSession, final ProgressOperationWithInput<OpenProjectParams> onCompleted) {
    initialize();
    // use the default dialog on desktop mode or single-session mode
    FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
    if (Desktop.isDesktop() || !RStudioGinjector.INSTANCE.getSession().getSessionInfo().getMultiSession()) {
        dialogs.openFile("Open Project", fsContext, FileSystemItem.createDir(defaultLocation), "R Projects (*.Rproj)", true, new ProgressOperationWithInput<FileSystemItem>() {

            @Override
            public void execute(FileSystemItem input, final ProgressIndicator indicator) {
                final CommandWithArg<FileSystemItem> onProjectFileReady = new CommandWithArg<FileSystemItem>() {

                    @Override
                    public void execute(FileSystemItem item) {
                        onCompleted.execute(new OpenProjectParams(item, null, false), indicator);
                    }
                };
                // null return values here imply a cancellation
                if (input == null)
                    return;
                if (input.isDirectory()) {
                    final String rprojPath = input.completePath(input.getName() + ".Rproj");
                    final FileSystemItem rprojFile = FileSystemItem.createFile(rprojPath);
                    server_.createProjectFile(rprojFile.getPath(), new ServerRequestCallback<Boolean>() {

                        @Override
                        public void onResponseReceived(Boolean success) {
                            onProjectFileReady.execute(rprojFile);
                        }

                        @Override
                        public void onError(ServerError error) {
                            Debug.logError(error);
                            onProjectFileReady.execute(rprojFile);
                        }
                    });
                } else {
                    onProjectFileReady.execute(input);
                }
            }
        });
    } else {
        // in multi-session mode, we have a special dialog for opening projects
        WebFileDialogs webDialogs = (WebFileDialogs) dialogs;
        webDialogs.openProject(fsContext, FileSystemItem.createDir(defaultLocation), defaultType, showNewSession, onCompleted);
    }
}
Also used : OpenProjectParams(org.rstudio.studio.client.projects.model.OpenProjectParams) ServerError(org.rstudio.studio.client.server.ServerError) CommandWithArg(org.rstudio.core.client.CommandWithArg) WebFileDialogs(org.rstudio.studio.client.common.impl.WebFileDialogs) FileDialogs(org.rstudio.studio.client.common.FileDialogs) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) WebFileDialogs(org.rstudio.studio.client.common.impl.WebFileDialogs) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Aggregations

CommandWithArg (org.rstudio.core.client.CommandWithArg)7 Command (com.google.gwt.user.client.Command)3 JsArray (com.google.gwt.core.client.JsArray)2 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)2 Image (com.google.gwt.user.client.ui.Image)2 Label (com.google.gwt.user.client.ui.Label)2 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)2 Map (java.util.Map)2 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)2 ServerError (org.rstudio.studio.client.server.ServerError)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Element (com.google.gwt.dom.client.Element)1 Style (com.google.gwt.dom.client.Style)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Event (com.google.gwt.user.client.Event)1 EventListener (com.google.gwt.user.client.EventListener)1 Timer (com.google.gwt.user.client.Timer)1