Example usage for com.intellij.openapi.ui ComboBox setEditor

List of usage examples for com.intellij.openapi.ui ComboBox setEditor

Introduction

In this page you can find the example usage for com.intellij.openapi.ui ComboBox setEditor.

Prototype

@Override
    public final void setEditor(final ComboBoxEditor editor) 

Source Link

Usage

From source file:com.android.tools.idea.gradle.structure.editors.KeyValuePane.java

License:Apache License

private ComboBox createComboBox(boolean editable) {
    ComboBox comboBox = new ComboBox();
    comboBox.addItemListener(this);
    comboBox.setEditor(new FixedComboBoxEditor());
    comboBox.setEditable(true);/*from  w  ww . j a v a2 s  . c  o  m*/
    comboBox.setMinLength(60); // Default is only 20 chars
    JBTextField editorComponent = (JBTextField) comboBox.getEditor().getEditorComponent();
    editorComponent.setEditable(editable);
    editorComponent.getDocument().addDocumentListener(this);
    return comboBox;
}

From source file:com.android.tools.idea.structure.gradle.KeyValuePane.java

License:Apache License

private ComboBox getComboBox(boolean editable) {
    ComboBox comboBox = new ComboBox();
    comboBox.addItemListener(this);
    comboBox.setEditor(new ComboBoxEditor() {
        private final JBTextField myTextField = new JBTextField();

        @Override/* w  ww .j a v a2  s  . c om*/
        public Component getEditorComponent() {
            return myTextField;
        }

        @Override
        public void setItem(Object o) {
            myTextField.setText(o != null ? o.toString() : "");
        }

        @Override
        public Object getItem() {
            return myTextField.getText();
        }

        @Override
        public void selectAll() {
            myTextField.selectAll();
        }

        @Override
        public void addActionListener(ActionListener actionListener) {
        }

        @Override
        public void removeActionListener(ActionListener actionListener) {
        }
    });
    comboBox.setEditable(true);
    JBTextField editorComponent = (JBTextField) comboBox.getEditor().getEditorComponent();
    editorComponent.setEditable(editable);
    editorComponent.getDocument().addDocumentListener(this);
    return comboBox;
}

From source file:com.intellij.compiler.impl.javaCompiler.TargetOptionsComponent.java

License:Apache License

private static ComboBox createTargetOptionsCombo() {
    final ComboBox combo = new ComboBox(new TargetLevelComboboxModel());
    //combo.setRenderer(new DefaultListCellRenderer() {
    //  @Override
    //  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    //    try {/*from  w  ww . j a v  a 2  s.com*/
    //      return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    //    }
    //    finally {
    //      //if ("".equals(value)) {
    //      //  setText(COMPILER_DEFAULT);
    //      //}
    //    }
    //  }
    //});
    combo.setEditable(true);
    combo.setEditor(new BasicComboBoxEditor() {
        @Override
        protected JTextField createEditorComponent() {
            return new HintTextField(COMPILER_DEFAULT, 10);
        }
    });
    return combo;
}

From source file:com.intellij.execution.ui.JrePathEditor.java

License:Apache License

/**
 * This constructor can be used in UI forms. <strong>Don't forget to call {@link #setDefaultJreSelector(DefaultJreSelector)}!</strong>
 *///from  w  ww  .j  a v  a2s .c  o  m
public JrePathEditor() {
    myLabel = new JBLabel(ExecutionBundle.message("run.configuration.jre.label"));

    myComboBoxModel = new SortedComboBoxModel<JreComboBoxItem>((o1, o2) -> {
        int result = Comparing.compare(o1.getOrder(), o2.getOrder());
        if (result != 0) {
            return result;
        }
        return o1.getPresentableText().compareToIgnoreCase(o2.getPresentableText());
    });
    myDefaultJreItem = new DefaultJreItem();
    myComboBoxModel.add(myDefaultJreItem);
    final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks();
    for (Sdk sdk : allJDKs) {
        myComboBoxModel.add(new SdkAsJreItem(sdk));
    }

    final Set<String> jrePaths = new HashSet<String>();
    for (JreProvider provider : JreProvider.EP_NAME.getExtensions()) {
        String path = provider.getJrePath();
        if (!StringUtil.isEmpty(path)) {
            jrePaths.add(path);
            myComboBoxModel.add(new CustomJreItem(path));
        }
    }

    for (Sdk jdk : allJDKs) {
        String homePath = jdk.getHomePath();

        if (!SystemInfo.isMac) {
            final File jre = new File(jdk.getHomePath(), "jre");
            if (jre.isDirectory()) {
                homePath = jre.getPath();
            }
        }
        if (jrePaths.add(homePath)) {
            myComboBoxModel.add(new CustomJreItem(homePath));
        }
    }
    ComboBox comboBox = new ComboBox(myComboBoxModel, 100);
    comboBox.setEditable(true);
    comboBox.setRenderer(new ColoredListCellRendererWrapper<JreComboBoxItem>() {
        @Override
        protected void doCustomize(JList list, JreComboBoxItem value, int index, boolean selected,
                boolean hasFocus) {
            if (value != null) {
                value.render(this, selected);
            }
        }
    });
    myComboboxEditor = new JreComboboxEditor(myComboBoxModel);
    myComboboxEditor.getEditorComponent().setTextToTriggerEmptyTextStatus(DEFAULT_JRE_TEXT);
    comboBox.setEditor(myComboboxEditor);
    myPathField = new ComboboxWithBrowseButton(comboBox);
    myPathField.addBrowseFolderListener(ExecutionBundle.message("run.configuration.select.alternate.jre.label"),
            ExecutionBundle.message("run.configuration.select.jre.dir.label"), null,
            BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR, JreComboboxEditor.TEXT_COMPONENT_ACCESSOR);

    setLayout(new MigLayout("ins 0, gap 10, fill, flowx"));
    add(myLabel, "shrinkx");
    add(myPathField, "growx, pushx");

    InsertPathAction.addTo(myComboboxEditor.getEditorComponent());

    setAnchor(myLabel);

    updateUI();
}

From source file:com.intellij.find.impl.FindDialog.java

License:Apache License

private void revealWhitespaces(@NotNull ComboBox comboBox) {
    ComboBoxEditor comboBoxEditor = new RevealingSpaceComboboxEditor(myProject, comboBox);
    comboBox.setEditor(comboBoxEditor);
    comboBox.setRenderer(new EditorComboBoxRenderer(comboBoxEditor));
}

From source file:com.intellij.refactoring.ui.NameSuggestionsField.java

License:Apache License

private void setupComboBox(final ComboBox combobox, FileType fileType) {
    final EditorComboBoxEditor comboEditor = new StringComboboxEditor(myProject, fileType, combobox) {
        @Override//w  w  w.ja  va  2s . c o  m
        public void setItem(Object anObject) {
            myNonHumanChange = true;
            super.setItem(anObject);
        }
    };

    combobox.setEditor(comboEditor);
    combobox.setRenderer(new EditorComboBoxRenderer(comboEditor));

    combobox.setEditable(true);
    combobox.setMaximumRowCount(8);

    comboEditor.selectAll();
}