Search in sources :

Example 1 with ListWithSelection

use of com.intellij.util.ListWithSelection 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)

Example 2 with ListWithSelection

use of com.intellij.util.ListWithSelection in project intellij-community by JetBrains.

the class ComboBoxTableCellRenderer method getTableCellRendererComponent.

@Override
public JComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (value instanceof ListWithSelection) {
        final ListWithSelection tags = (ListWithSelection) value;
        if (tags.getSelection() == null) {
            tags.selectFirst();
        }
        myCombo.removeAllItems();
        for (Object tag : tags) {
            myCombo.addItem(tag);
        }
        myCombo.setSelectedItem(tags.getSelection());
    } else {
        if (value != null) {
            LOG.error("value " + LogUtil.objectAndClass(value) + ", at " + row + ":" + column + ", in " + table.getModel());
        }
        myCombo.removeAllItems();
        myCombo.setSelectedIndex(-1);
    }
    return this;
}
Also used : ListWithSelection(com.intellij.util.ListWithSelection)

Example 3 with ListWithSelection

use of com.intellij.util.ListWithSelection 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) {
    final ListWithSelection options = (ListWithSelection) value;
    if (options.getSelection() == null) {
        options.selectFirst();
    }
    myComboBox.removeAllItems();
    for (Object option : options) {
        //noinspection unchecked
        myComboBox.addItem(option);
    }
    myComboBox.setSelectedItem(options.getSelection());
    return myPanel;
}
Also used : ListWithSelection(com.intellij.util.ListWithSelection)

Aggregations

ListWithSelection (com.intellij.util.ListWithSelection)3 EnumComboBoxModel (com.intellij.ui.EnumComboBoxModel)1 ListComboBoxModel (org.jdesktop.swingx.combobox.ListComboBoxModel)1