Search in sources :

Example 1 with ListComboBoxModel

use of org.jdesktop.swingx.combobox.ListComboBoxModel in project intellij-community by JetBrains.

the class ParameterNameHintsConfigurable method initLanguageCombo.

private void initLanguageCombo(Language selected, List<Language> languages) {
    ListComboBoxModel<Language> model = new ListComboBoxModel<>(languages);
    myCurrentLanguageCombo = new ComboBox<>(model);
    myCurrentLanguageCombo.setSelectedItem(selected);
    myCurrentLanguageCombo.setRenderer(new ListCellRendererWrapper<Language>() {

        @Override
        public void customize(JList list, Language value, int index, boolean selected, boolean hasFocus) {
            setText(value.getDisplayName());
        }
    });
    myCurrentLanguageCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            Language language = (Language) e.getItem();
            if (e.getStateChange() == ItemEvent.SELECTED) {
                showLanguagePanel(language);
            }
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) Language(com.intellij.lang.Language) ListComboBoxModel(org.jdesktop.swingx.combobox.ListComboBoxModel) ItemListener(java.awt.event.ItemListener)

Example 2 with ListComboBoxModel

use of org.jdesktop.swingx.combobox.ListComboBoxModel in project intellij-community by JetBrains.

the class ComboBoxTableCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    if (value instanceof ListWithSelection) {
        ListWithSelection options = (ListWithSelection) value;
        //noinspection unchecked
        comboBox.setModel(new ListComboBoxModel(options));
        if (options.getSelection() == null) {
            options.selectFirst();
        }
        comboBox.setSelectedItem(options.getSelection());
    } else {
        Enum enumValue = (Enum) value;
        Class enumClass = enumValue.getDeclaringClass();
        //noinspection unchecked
        ComboBoxModel model = comboBox.getModel();
        if (!(model instanceof EnumComboBoxModel && model.getSize() > 0 && ((Enum) model.getElementAt(0)).getDeclaringClass() == enumClass)) {
            //noinspection unchecked
            comboBox.setModel(new EnumComboBoxModel(enumClass));
        }
        comboBox.setSelectedItem(value);
    }
    return comboBox;
}
Also used : EnumComboBoxModel(com.intellij.ui.EnumComboBoxModel) ListComboBoxModel(org.jdesktop.swingx.combobox.ListComboBoxModel) EnumComboBoxModel(com.intellij.ui.EnumComboBoxModel) ListComboBoxModel(org.jdesktop.swingx.combobox.ListComboBoxModel) ListWithSelection(com.intellij.util.ListWithSelection)

Aggregations

ListComboBoxModel (org.jdesktop.swingx.combobox.ListComboBoxModel)2 Language (com.intellij.lang.Language)1 EnumComboBoxModel (com.intellij.ui.EnumComboBoxModel)1 ListWithSelection (com.intellij.util.ListWithSelection)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1