Search in sources :

Example 1 with EnumComboBoxModel

use of com.intellij.ui.EnumComboBoxModel 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 EnumComboBoxModel

use of com.intellij.ui.EnumComboBoxModel in project intellij-community by JetBrains.

the class GitVcsPanel method createUIComponents.

private void createUIComponents() {
    myProtectedBranchesButton = new TextFieldWithBrowseButton.NoPathCompletion(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Messages.showTextAreaDialog(myProtectedBranchesButton.getTextField(), "Protected Branches", "Git.Force.Push.Protected.Branches", ParametersListUtil.COLON_LINE_PARSER, ParametersListUtil.COLON_LINE_JOINER);
        }
    });
    myProtectedBranchesButton.setButtonIcon(AllIcons.Actions.ShowViewer);
    myUpdateMethodComboBox = new ComboBox(new EnumComboBoxModel<>(UpdateMethod.class));
    myUpdateMethodComboBox.setRenderer(new ListCellRendererWrapper<UpdateMethod>() {

        @Override
        public void customize(JList list, UpdateMethod value, int index, boolean selected, boolean hasFocus) {
            setText(StringUtil.capitalize(StringUtil.toLowerCase(value.name().replace('_', ' '))));
        }
    });
}
Also used : TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ActionListener(java.awt.event.ActionListener) EnumComboBoxModel(com.intellij.ui.EnumComboBoxModel) ActionEvent(java.awt.event.ActionEvent) ComboBox(com.intellij.openapi.ui.ComboBox)

Aggregations

EnumComboBoxModel (com.intellij.ui.EnumComboBoxModel)2 ComboBox (com.intellij.openapi.ui.ComboBox)1 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)1 ListWithSelection (com.intellij.util.ListWithSelection)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ListComboBoxModel (org.jdesktop.swingx.combobox.ListComboBoxModel)1