Search in sources :

Example 16 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class InstallPackageDialog method createMainWidget.

@Override
protected Widget createMainWidget() {
    // vertical panel
    VerticalPanel mainPanel = new VerticalPanel();
    mainPanel.setSpacing(2);
    mainPanel.setStylePrimaryName(RESOURCES.styles().mainWidget());
    // source type
    reposCaption_ = new CaptionWithHelp("Install from:", "Configuring Repositories", "configuring_repositories");
    reposCaption_.setIncludeVersionInfo(false);
    reposCaption_.setWidth("100%");
    mainPanel.add(reposCaption_);
    packageSourceListBox_ = new ListBox();
    packageSourceListBox_.setStylePrimaryName(RESOURCES.styles().packageSourceListBox());
    packageSourceListBox_.addStyleName(RESOURCES.styles().extraBottomPad());
    JsArrayString repos = installContext_.selectedRepositoryNames();
    if (repos.length() == 1) {
        packageSourceListBox_.addItem("Repository (" + repos.get(0) + ")");
    } else {
        StringBuilder reposItem = new StringBuilder();
        reposItem.append("Repository (");
        for (int i = 0; i < repos.length(); i++) {
            if (i != 0)
                reposItem.append(", ");
            reposItem.append(repos.get(i));
        }
        reposItem.append(")");
        packageSourceListBox_.addItem(reposItem.toString());
    }
    packageSourceListBox_.addItem("Package Archive File (" + installContext_.packageArchiveExtension() + ")");
    mainPanel.add(packageSourceListBox_);
    // source panel container
    sourcePanel_ = new SimplePanel();
    sourcePanel_.setStylePrimaryName(RESOURCES.styles().packageSourcePanel());
    // repos source panel
    reposSourcePanel_ = new FlowPanel();
    Label packagesLabel = new Label("Packages (separate multiple with space or comma):");
    packagesLabel.setStylePrimaryName(RESOURCES.styles().packagesLabel());
    reposSourcePanel_.add(packagesLabel);
    packagesTextBox_ = new MultipleItemSuggestTextBox();
    packagesSuggestBox_ = new SuggestBox(new PackageOracle(), packagesTextBox_);
    packagesSuggestBox_.setWidth("100%");
    packagesSuggestBox_.setLimit(20);
    packagesSuggestBox_.addStyleName(RESOURCES.styles().extraBottomPad());
    reposSourcePanel_.add(packagesSuggestBox_);
    sourcePanel_.setWidget(reposSourcePanel_);
    mainPanel.add(sourcePanel_);
    // archive source panel
    packageArchiveFile_ = new TextBoxWithButton("Package archive:", "Browse...", browseForArchiveClickHandler_);
    // create check box here because manageUIState accesses it
    installDependenciesCheckBox_ = new CheckBox();
    if (defaultInstallOptions_.getInstallFromRepository())
        packageSourceListBox_.setSelectedIndex(0);
    else
        packageSourceListBox_.setSelectedIndex(1);
    manageUIState();
    packageSourceListBox_.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            manageUIState();
            if (!installFromRepository())
                packageArchiveFile_.click();
        }
    });
    mainPanel.add(new Label("Install to Library:"));
    // library list box
    libraryListBox_ = new ListBox();
    libraryListBox_.setWidth("100%");
    libraryListBox_.addStyleName(RESOURCES.styles().extraBottomPad());
    JsArrayString libPaths = installContext_.getWriteableLibraryPaths();
    int selectedIndex = 0;
    for (int i = 0; i < libPaths.length(); i++) {
        String libPath = libPaths.get(i);
        if (!installContext_.isDevModeOn()) {
            if (defaultInstallOptions_.getLibraryPath().equals(libPath))
                selectedIndex = i;
        }
        if (libPath.equals(installContext_.getDefaultLibraryPath()))
            libPath = libPath + " [Default]";
        libraryListBox_.addItem(libPath);
    }
    libraryListBox_.setSelectedIndex(selectedIndex);
    mainPanel.add(libraryListBox_);
    // install dependencies check box
    installDependenciesCheckBox_.addStyleName(RESOURCES.styles().installDependenciesCheckBox());
    installDependenciesCheckBox_.setText("Install dependencies");
    installDependenciesCheckBox_.setValue(defaultInstallOptions_.getInstallDependencies());
    mainPanel.add(installDependenciesCheckBox_);
    mainPanel.add(new HTML("<br/>"));
    return mainPanel;
}
Also used : MultipleItemSuggestTextBox(org.rstudio.core.client.widget.MultipleItemSuggestTextBox) Label(com.google.gwt.user.client.ui.Label) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) HTML(com.google.gwt.user.client.ui.HTML) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) SuggestBox(com.google.gwt.user.client.ui.SuggestBox) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) TextBoxWithButton(org.rstudio.core.client.widget.TextBoxWithButton) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CheckBox(com.google.gwt.user.client.ui.CheckBox) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) CaptionWithHelp(org.rstudio.core.client.widget.CaptionWithHelp) ListBox(com.google.gwt.user.client.ui.ListBox)

Example 17 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class ImportFileSettingsDialog method populateOutput.

private void populateOutput(DataPreviewResult result) {
    JsArray<JsObject> output = result.getOutput();
    JsArrayString names = result.getOutputNames();
    int rows = output.length();
    int cols = names.length();
    Grid grid = new Grid(rows + 1, cols);
    grid.setCellPadding(0);
    grid.setCellSpacing(0);
    grid.getRowFormatter().addStyleName(0, styles_.header());
    for (int col = 0; col < cols; col++) grid.setText(0, col, names.get(col));
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            String val = output.get(row).getString(names.get(col), true);
            if (val == null)
                val = "NA";
            grid.setText(row + 1, col, val);
        }
    }
    outputPanel_.setWidget(grid);
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 18 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class IgnoredUpdates method addIgnoredUpdate.

public final void addIgnoredUpdate(String update) {
    JsArrayString newUpdateList = create().getIgnoredUpdates();
    JsArrayString existingUpdateList = getIgnoredUpdates();
    for (int i = 0; i < existingUpdateList.length(); i++) {
        // we're about to add.
        if (ApplicationUtils.compareVersions(update, existingUpdateList.get(i)) < 0) {
            newUpdateList.push(existingUpdateList.get(i));
        }
    }
    newUpdateList.push(update);
    setIgnoredUpdates(newUpdateList);
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 19 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class TextEditingTarget method onExtractLocalVariable.

@Handler
void onExtractLocalVariable() {
    if (!isCursorInRMode()) {
        showRModeWarning("Extract Variable");
        return;
    }
    docDisplay_.focus();
    String initialSelection = docDisplay_.getSelectionValue();
    final String refactoringName = "Extract local variable";
    final String pleaseSelectCodeMessage = "Please select the code to " + "extract into a variable.";
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, initialSelection))
        return;
    docDisplay_.fitSelectionToLines(false);
    final String code = docDisplay_.getSelectionValue();
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, code))
        return;
    // get the first line of the selection and calculate it's indentation
    String firstLine = docDisplay_.getLine(docDisplay_.getSelectionStart().getRow());
    final String indentation = extractIndentation(firstLine);
    // used to parse the code
    server_.detectFreeVars(code, new RefactorServerRequestCallback(refactoringName) {

        @Override
        void doExtract(JsArrayString response) {
            globalDisplay_.promptForText(refactoringName, "Variable Name", "", new OperationWithInput<String>() {

                public void execute(String input) {
                    final String extractedCode = indentation + input.trim() + " <- " + code + "\n";
                    InputEditorPosition insertPosition = docDisplay_.getSelection().extendToLineStart().getStart();
                    docDisplay_.replaceSelection(input.trim());
                    docDisplay_.insertCode(insertPosition, extractedCode);
                }
            });
        }
    });
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) InputEditorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition) Handler(org.rstudio.core.client.command.Handler) ChangeFontSizeHandler(org.rstudio.studio.client.application.events.ChangeFontSizeHandler) RecordNavigationPositionHandler(org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) FileChangeHandler(org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)

Example 20 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project rstudio by rstudio.

the class TextEditingTarget method onExtractFunction.

@Handler
void onExtractFunction() {
    if (!isCursorInRMode()) {
        showRModeWarning("Extract Function");
        return;
    }
    docDisplay_.focus();
    String initialSelection = docDisplay_.getSelectionValue();
    final String refactoringName = "Extract Function";
    final String pleaseSelectCodeMessage = "Please select the code to " + "extract into a function.";
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, initialSelection))
        return;
    docDisplay_.fitSelectionToLines(false);
    final String code = docDisplay_.getSelectionValue();
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, code))
        return;
    final String indentation = extractIndentation(code);
    server_.detectFreeVars(code, new RefactorServerRequestCallback(refactoringName) {

        @Override
        void doExtract(final JsArrayString response) {
            globalDisplay_.promptForText(refactoringName, "Function Name", "", new OperationWithInput<String>() {

                public void execute(String input) {
                    String prefix;
                    if (docDisplay_.getSelectionOffset(true) == 0)
                        prefix = "";
                    else
                        prefix = "\n";
                    String args = response != null ? response.join(", ") : "";
                    docDisplay_.replaceSelection(prefix + indentation + input.trim() + " <- " + "function(" + args + ") {\n" + StringUtil.indent(code, "  ") + "\n" + indentation + "}");
                }
            });
        }
    });
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) Handler(org.rstudio.core.client.command.Handler) ChangeFontSizeHandler(org.rstudio.studio.client.application.events.ChangeFontSizeHandler) RecordNavigationPositionHandler(org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) FileChangeHandler(org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)86 ArrayList (java.util.ArrayList)15 JSONString (com.google.gwt.json.client.JSONString)5 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)5 ServerError (org.rstudio.studio.client.server.ServerError)4 JsArrayInteger (com.google.gwt.core.client.JsArrayInteger)3 Command (com.google.gwt.user.client.Command)3 List (java.util.List)3 KeySequence (org.rstudio.core.client.command.KeyboardShortcut.KeySequence)3 JsObject (org.rstudio.core.client.js.JsObject)3 RmdTemplateFormatOption (org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption)3 JsArrayBoolean (com.google.gwt.core.client.JsArrayBoolean)2 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)2 Label (com.google.gwt.user.client.ui.Label)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 Handler (org.rstudio.core.client.command.Handler)2 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)2 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)2 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)2 RmdFrontMatterOutputOptions (org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)2