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

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

Introduction

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

Prototype

public ComboBox(E @NotNull [] items) 

Source Link

Usage

From source file:org.mustbe.consulo.csharp.ide.newProjectOrModule.CSharpSdkPanel.java

License:Apache License

public CSharpSdkPanel() {
    super(new VerticalFlowLayout());

    myTargetComboBox = new ComboBox(DotNetTarget.values());
    myTargetComboBox.setRenderer(new ColoredListCellRendererWrapper<DotNetTarget>() {
        @Override/*from   ww  w  . ja  v  a 2s.com*/
        protected void doCustomize(JList list, DotNetTarget value, int index, boolean selected,
                boolean hasFocus) {
            append(value.getDescription());
        }
    });
    add(myTargetComponent = LabeledComponent.left(myTargetComboBox, "Target"));

    SdkTable sdkTable = SdkTable.getInstance();
    myComboBox = new ComboBox();
    myComboBox.setRenderer(new SdkListCellRenderer("<none>"));

    List<String> validSdkTypes = new SmartList<String>();
    for (Map.Entry<String, String[]> entry : CSharpNewModuleBuilder.ourExtensionMapping.entrySet()) {
        // need check C# extension
        ModuleExtensionProviderEP providerEP = ModuleExtensionProviderEP.findProviderEP(entry.getValue()[1]);
        if (providerEP == null) {
            continue;
        }
        validSdkTypes.add(entry.getKey());
    }

    for (Sdk o : sdkTable.getAllSdks()) {
        SdkTypeId sdkType = o.getSdkType();
        if (validSdkTypes.contains(sdkType.getName())) {
            myComboBox.addItem(o);
        }
    }

    add(LabeledComponent.left(myComboBox, ".NET SDK"));
}

From source file:org.mustbe.consulo.dotnet.module.extension.DotNetConfigurationPanel.java

License:Apache License

public DotNetConfigurationPanel(final DotNetMutableModuleExtension<?> extension, final List<String> variables,
        final Runnable updater) {
    super(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));
    add(DotNetModuleExtensionWithSdkPanel.create(extension, EmptyRunnable.INSTANCE));

    val fileNameField = new JBTextField(extension.getFileName());
    fileNameField.getEmptyText().setText(DotNetModuleExtension.DEFAULT_FILE_NAME);
    fileNameField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override/*from w  w  w .  j  a  va 2s.  c o  m*/
        protected void textChanged(DocumentEvent documentEvent) {
            extension.setFileName(fileNameField.getText());
        }
    });

    add(LabeledComponent.left(fileNameField, DotNetBundle.message("file.label")));

    val outputDirectoryField = new JBTextField(extension.getOutputDir());
    outputDirectoryField.getEmptyText().setText(DotNetModuleExtension.DEFAULT_OUTPUT_DIR);
    outputDirectoryField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent documentEvent) {
            extension.setOutputDir(outputDirectoryField.getText());
        }
    });

    add(LabeledComponent.left(outputDirectoryField, DotNetBundle.message("output.dir.label")));

    val comp = new ComboBox(DotNetTarget.values());
    comp.setRenderer(new ListCellRendererWrapper<DotNetTarget>() {
        @Override
        public void customize(JList jList, DotNetTarget dotNetTarget, int i, boolean b, boolean b2) {
            setText(dotNetTarget.getDescription());
        }
    });
    comp.setSelectedItem(extension.getTarget());
    comp.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            extension.setTarget((DotNetTarget) comp.getSelectedItem());
        }
    });

    add(LabeledComponent.left(comp, DotNetBundle.message("target.label")));

    final List<Object> items = new ArrayList<Object>();
    final CollectionComboBoxModel model = new CollectionComboBoxModel(items);
    val mainClassList = new ComboBox(model);
    mainClassList.setEnabled(false);
    mainClassList.setRenderer(new ColoredListCellRenderer() {
        @Override
        protected void customizeCellRenderer(JList list, Object value, int index, boolean selected,
                boolean hasFocus) {
            if (!mainClassList.isEnabled()) {
                return;
            }

            if (value instanceof DotNetQualifiedElement) {
                setIcon(IconDescriptorUpdaters.getIcon((PsiElement) value, 0));
                append(((DotNetQualifiedElement) value).getPresentableQName());
            } else if (value instanceof String) {
                setIcon(AllIcons.Toolbar.Unknown);
                append((String) value, SimpleTextAttributes.ERROR_ATTRIBUTES);
            } else {
                append("<none>");
            }
        }
    });
    mainClassList.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (!mainClassList.isEnabled()) {
                return;
            }

            Object selectedItem = mainClassList.getSelectedItem();
            if (selectedItem instanceof DotNetQualifiedElement) {
                extension.setMainType(((DotNetQualifiedElement) selectedItem).getPresentableQName());
            } else if (selectedItem instanceof String) {
                extension.setMainType((String) selectedItem);
            } else {
                extension.setMainType(null);
            }
        }
    });

    model.update();

    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        @Override
        public void run() {
            final Ref<DotNetQualifiedElement> selected = Ref.create();
            final List<Object> newItems = new ArrayList<Object>();
            newItems.add(null);

            ApplicationManager.getApplication().runReadAction(new Runnable() {
                @Override
                public void run() {
                    for (PsiElement psiElement : extension.getEntryPointElements()) {
                        if (psiElement instanceof DotNetQualifiedElement) {
                            newItems.add(psiElement);
                            String mainType = extension.getMainType();
                            DotNetQualifiedElement qualifiedElement = (DotNetQualifiedElement) psiElement;
                            if (mainType != null
                                    && Comparing.equal(mainType, qualifiedElement.getPresentableQName())) {
                                selected.set(qualifiedElement);
                            }
                        }
                    }
                }
            });

            UIUtil.invokeLaterIfNeeded(new Runnable() {
                @Override
                public void run() {
                    DotNetQualifiedElement selectedType = selected.get();
                    String mainType = extension.getMainType();
                    if (mainType != null && selectedType == null) {
                        newItems.add(mainType);
                    }

                    items.clear();
                    items.addAll(newItems);

                    if (mainType != null) {
                        if (selectedType != null) {
                            model.setSelectedItem(selectedType);
                        } else {
                            model.setSelectedItem(mainType);
                        }
                    } else {
                        model.setSelectedItem(null);
                    }

                    mainClassList.setEnabled(true);
                    model.update();
                }
            });
        }
    });

    add(LabeledComponent.left(mainClassList, DotNetBundle.message("main.type.label")));

    val debugCombobox = new JBCheckBox(DotNetBundle.message("generate.debug.info.label"),
            extension.isAllowDebugInfo());
    debugCombobox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            extension.setAllowDebugInfo(debugCombobox.isSelected());
        }
    });
    add(debugCombobox);

    val namespacePrefixField = new JBTextField(extension.getNamespacePrefix());
    namespacePrefixField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent documentEvent) {
            extension.setNamespacePrefix(namespacePrefixField.getText());
        }
    });

    final LabeledComponent<JBTextField> namespaceComponent = LabeledComponent.left(namespacePrefixField,
            "Namespace:");

    val allowSourceRootsBox = new JBCheckBox(DotNetBundle.message("allow.source.roots.label"),
            extension.isAllowSourceRoots());
    allowSourceRootsBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            extension.setAllowSourceRoots(allowSourceRootsBox.isSelected());
            namespaceComponent.setVisible(!allowSourceRootsBox.isSelected());

            updater.run();
        }
    });
    add(allowSourceRootsBox);
    add(namespaceComponent);

    val dataModel = new CollectionListModel<String>(variables) {
        @Override
        public int getSize() {
            return variables.size();
        }

        @Override
        public String getElementAt(int index) {
            return variables.get(index);
        }

        @Override
        public void add(final String element) {
            int i = variables.size();
            variables.add(element);
            fireIntervalAdded(this, i, i);
        }

        @Override
        public void remove(@NotNull final String element) {
            int i = variables.indexOf(element);
            variables.remove(element);
            fireIntervalRemoved(this, i, i);
        }

        @Override
        public void remove(int index) {
            variables.remove(index);
            fireIntervalRemoved(this, index, index);
        }
    };

    val variableList = new JBList(dataModel);
    ToolbarDecorator variableDecorator = ToolbarDecorator.createDecorator(variableList);
    variableDecorator.setAddAction(new AnActionButtonRunnable() {
        @Override
        public void run(AnActionButton anActionButton) {
            String name = Messages.showInputDialog(DotNetConfigurationPanel.this,
                    DotNetBundle.message("new.variable.message"), DotNetBundle.message("new.variable.title"),
                    null, null, new InputValidator() {
                        @Override
                        public boolean checkInput(String s) {
                            return !variables.contains(s);
                        }

                        @Override
                        public boolean canClose(String s) {
                            return true;
                        }
                    });

            if (StringUtil.isEmpty(name)) {
                return;
            }

            dataModel.add(name);
        }
    });
    add(variableDecorator.createPanel());
}

From source file:org.mustbe.consulo.nodejs.run.NodeJSConfigurationEditor.java

License:Apache License

private void createUIComponents() {
    myModuleBox = new ComboBox(myNodeJSConfiguration.getValidModules().toArray());
    myModuleBox.setRenderer(new ModuleListCellRenderer());
}

From source file:org.mustbe.consulo.unity3d.module.ui.UnityConfigurationPanel.java

License:Apache License

@RequiredDispatchThread
public UnityConfigurationPanel(final Unity3dRootMutableModuleExtension extension, final List<String> variables,
        final Runnable updater) {
    super(new VerticalFlowLayout(true, true));
    ModuleExtensionSdkBoxBuilder<Unity3dRootMutableModuleExtension> sdkBoxBuilder = ModuleExtensionSdkBoxBuilder
            .create(extension, updater);
    sdkBoxBuilder.sdkTypeClass(extension.getSdkTypeClass());
    sdkBoxBuilder.sdkPointerFunc(/*from   w  w  w  .j a va 2s .com*/
            new NullableFunction<Unity3dRootMutableModuleExtension, MutableModuleInheritableNamedPointer<Sdk>>() {
                @Nullable
                @Override
                public MutableModuleInheritableNamedPointer<Sdk> fun(
                        Unity3dRootMutableModuleExtension mutableModuleExtension) {
                    return mutableModuleExtension.getInheritableSdk();
                }
            });
    add(sdkBoxBuilder.build());

    final ComboBox target = new ComboBox(Unity3dTarget.values());
    target.setRenderer(new ColoredListCellRendererWrapper<Unity3dTarget>() {
        @Override
        protected void doCustomize(JList list, Unity3dTarget value, int index, boolean selected,
                boolean hasFocus) {
            String presentation = value.getPresentation();
            int i = presentation.indexOf('(');
            if (i != -1) {
                append(presentation.substring(0, i));
                append(presentation.substring(i, presentation.length()), SimpleTextAttributes.GRAY_ATTRIBUTES);
            } else {
                append(presentation);
            }
        }
    });
    target.setSelectedItem(extension.getBuildTarget());
    target.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                extension.setBuildTarget((Unity3dTarget) target.getSelectedItem());
            }
        }
    });

    val fileNameField = new JBTextField(extension.getFileName());
    fileNameField.getEmptyText().setText(Unity3dRootModuleExtension.FILE_NAME);
    fileNameField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent documentEvent) {
            extension.setFileName(fileNameField.getText());
        }
    });

    add(LabeledComponent.left(fileNameField, DotNetBundle.message("file.label")));

    val outputDirectoryField = new JBTextField(extension.getOutputDir());
    outputDirectoryField.getEmptyText().setText(DotNetModuleExtension.DEFAULT_OUTPUT_DIR);
    outputDirectoryField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent documentEvent) {
            extension.setOutputDir(outputDirectoryField.getText());
        }
    });

    add(LabeledComponent.left(outputDirectoryField, DotNetBundle.message("output.dir.label")));
    add(LabeledComponent.left(target, "Target:"));

    val dataModel = new CollectionListModel<String>(variables) {
        @Override
        public int getSize() {
            return variables.size();
        }

        @Override
        public String getElementAt(int index) {
            return variables.get(index);
        }

        @Override
        public void add(final String element) {
            int i = variables.size();
            variables.add(element);
            fireIntervalAdded(this, i, i);
        }

        @Override
        public void remove(@NotNull final String element) {
            int i = variables.indexOf(element);
            variables.remove(element);
            fireIntervalRemoved(this, i, i);
        }

        @Override
        public void remove(int index) {
            variables.remove(index);
            fireIntervalRemoved(this, index, index);
        }
    };

    val variableList = new JBList(dataModel);
    ToolbarDecorator variableDecorator = ToolbarDecorator.createDecorator(variableList);
    variableDecorator.setAddAction(new AnActionButtonRunnable() {
        @Override
        public void run(AnActionButton anActionButton) {
            String name = Messages.showInputDialog(UnityConfigurationPanel.this,
                    DotNetBundle.message("new.variable.message"), DotNetBundle.message("new.variable.title"),
                    null, null, new InputValidator() {
                        @Override
                        public boolean checkInput(String s) {
                            return !variables.contains(s);
                        }

                        @Override
                        public boolean canClose(String s) {
                            return true;
                        }
                    });

            if (StringUtil.isEmpty(name)) {
                return;
            }

            dataModel.add(name);
        }
    });
    add(new JBLabel("Preprocessor variables:"));
    add(variableDecorator.createPanel());
}

From source file:org.objectweb.asm.idea.config.ASMPluginConfiguration.java

License:Apache License

private void createUIComponents() {
    ComboBoxModel model = new EnumComboBoxModel<GroovyCodeStyle>(GroovyCodeStyle.class);
    groovyCodeStyleComboBox = new ComboBox(model);
    groovyCodeStyleComboBox.setRenderer(new GroovyCodeStyleCellRenderer());
}

From source file:org.perfcake.ide.intellij.dialogs.ScenarioForm.java

License:Apache License

protected void createUiComponents() {
    setLayout(new GridBagLayout());

    nameLabel = new JLabel("Scenario name:");
    nameTextField = new JTextField(20);
    typeComboBox = new ComboBox(new String[] { "xml", "dsl" });
    typeLabel = new JLabel("Type:");

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;//from  w w w  . j a  va2s  .c o m
    c.gridy = 0;
    c.insets = new Insets(2, 10, 2, 10);
    c.fill = GridBagConstraints.NONE;

    add(nameLabel, c);
    c.gridy++;
    add(typeLabel, c);

    c.gridy = 0;
    c.gridx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    add(nameTextField, c);
    c.gridy++;
    add(typeComboBox, c);
}

From source file:org.sonarlint.intellij.ui.SonarLintAnalysisResultsPanel.java

License:Open Source License

private JComponent createScopePanel() {
    DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
    changedFilesScope = new ChangedFilesScope(project);
    comboModel.addElement(changedFilesScope);
    comboModel.addElement(new AllFilesScope(project));

    // set selected element that was last saved, if any
    String savedSelectedScope = PropertiesComponent.getInstance(project).getValue(SELECTED_SCOPE_KEY);
    if (savedSelectedScope != null) {
        for (int i = 0; i < comboModel.getSize(); i++) {
            Object el = comboModel.getElementAt(i);
            if (el.toString().equals(savedSelectedScope)) {
                comboModel.setSelectedItem(el);
                break;
            }//from  w ww. j av  a 2s.  c o  m
        }
    }

    scopeComboBox = new ComboBox(comboModel);
    scopeComboBox.addActionListener(evt -> switchScope((AbstractScope) scopeComboBox.getSelectedItem()));
    switchScope((AbstractScope) scopeComboBox.getSelectedItem());
    JPanel scopePanel = new JPanel(new GridBagLayout());
    final JLabel scopesLabel = new JLabel("Scope:");
    scopesLabel.setDisplayedMnemonic('S');
    scopesLabel.setLabelFor(scopeComboBox);
    final GridBagConstraints gc = new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0);
    scopePanel.add(scopesLabel, gc);
    scopePanel.add(scopeComboBox, gc);

    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.weightx = 1;
    scopePanel.add(Box.createHorizontalBox(), gc);

    return scopePanel;
}

From source file:org.sonarlint.intellij.ui.SonarLintIssuesPanel.java

License:Open Source License

private JComponent createScopePanel() {
    DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
    comboModel.addElement(new CurrentFileScope(project));
    comboModel.addElement(new ProjectScope());

    // set selected element that was last saved, if any
    String savedSelectedScope = PropertiesComponent.getInstance(project).getValue(SELECTED_SCOPE_KEY);
    if (savedSelectedScope != null) {
        for (int i = 0; i < comboModel.getSize(); i++) {
            Object el = comboModel.getElementAt(i);
            if (el.toString().equals(savedSelectedScope)) {
                comboModel.setSelectedItem(el);
                break;
            }/*from w w w.j a v  a 2 s. c o m*/
        }
    }

    final ComboBox scopeComboBox = new ComboBox(comboModel);
    scopeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            switchScope((IssueTreeScope) scopeComboBox.getSelectedItem());
            updateTree();
            PropertiesComponent.getInstance(project).setValue(SELECTED_SCOPE_KEY,
                    scopeComboBox.getSelectedItem().toString());
        }
    });
    switchScope((IssueTreeScope) scopeComboBox.getSelectedItem());
    JPanel scopePanel = new JPanel(new GridBagLayout());
    final JLabel scopesLabel = new JLabel("Scope:");
    scopesLabel.setDisplayedMnemonic('S');
    scopesLabel.setLabelFor(scopeComboBox);
    final GridBagConstraints gc = new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0);
    scopePanel.add(scopesLabel, gc);
    scopePanel.add(scopeComboBox, gc);

    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.weightx = 1;
    scopePanel.add(Box.createHorizontalBox(), gc);

    return scopePanel;
}

From source file:org.twodividedbyzero.idea.findbugs.gui.settings.AnalysisEffortPane.java

License:Open Source License

AnalysisEffortPane(final int indent) {
    super(new FlowLayout(FlowLayout.LEFT, 0, 0));
    label = new JLabel(ResourcesLoader.getString("effort.text"));
    label.setToolTipText(ResourcesLoader.getString("effort.description"));
    label.setPreferredSize(new JBDimension(indent, label.getPreferredSize().height));
    comboBox = new ComboBox(AnalysisEffort.values());
    add(label);//w w w  .j  av  a 2 s .  com
    add(comboBox);
}

From source file:org.twodividedbyzero.idea.findbugs.gui.settings.MinPriorityPane.java

License:Open Source License

MinPriorityPane(final int indent) {
    super(new FlowLayout(FlowLayout.LEFT, 0, 0));
    label = new JLabel(ResourcesLoader.getString("minPriority.text"));
    label.setToolTipText(ResourcesLoader.getString("minPriority.description"));
    label.setPreferredSize(new JBDimension(indent, label.getPreferredSize().height));
    comboBox = new ComboBox(new Object[] { ProjectFilterSettings.HIGH_PRIORITY,
            ProjectFilterSettings.MEDIUM_PRIORITY, ProjectFilterSettings.LOW_PRIORITY });
    add(label);//from   w w  w .  j  ava  2 s .com
    add(comboBox);
}