Search in sources :

Example 16 with CollectionComboBoxModel

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

the class PyActiveSdkConfigurable method updateSdkList.

private void updateSdkList(boolean preserveSelection) {
    final List<Sdk> sdkList = myInterpreterList.getAllPythonSdks(myProject);
    Sdk selection = preserveSelection ? (Sdk) mySdkCombo.getSelectedItem() : null;
    if (!sdkList.contains(selection)) {
        selection = null;
    }
    VirtualEnvProjectFilter.removeNotMatching(myProject, sdkList);
    // if the selection is a non-matching virtualenv, show it anyway
    if (selection != null && !sdkList.contains(selection)) {
        sdkList.add(0, selection);
    }
    List<Object> items = new ArrayList<>();
    items.add(null);
    boolean remoteSeparator = true;
    boolean separator = true;
    boolean detectedSeparator = true;
    for (Sdk sdk : sdkList) {
        if (!PythonSdkType.isVirtualEnv(sdk) && !PythonSdkType.isRemote(sdk) && !(sdk instanceof PyDetectedSdk) && separator) {
            items.add(PySdkListCellRenderer.SEPARATOR);
            separator = false;
        }
        if (PythonSdkType.isRemote(sdk) && remoteSeparator) {
            items.add(PySdkListCellRenderer.SEPARATOR);
            remoteSeparator = false;
        }
        if (sdk instanceof PyDetectedSdk && detectedSeparator) {
            items.add(PySdkListCellRenderer.SEPARATOR);
            detectedSeparator = false;
        }
        items.add(sdk);
    }
    items.add(PySdkListCellRenderer.SEPARATOR);
    items.add(SHOW_ALL);
    mySdkCombo.setRenderer(new PySdkListCellRenderer(false));
    //noinspection unchecked
    mySdkCombo.setModel(new CollectionComboBoxModel(items, selection));
}
Also used : ArrayList(java.util.ArrayList) CollectionComboBoxModel(com.intellij.ui.CollectionComboBoxModel) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

CollectionComboBoxModel (com.intellij.ui.CollectionComboBoxModel)16 ArrayList (java.util.ArrayList)4 Sdk (com.intellij.openapi.projectRoots.Sdk)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 NotNull (org.jetbrains.annotations.NotNull)2 InvalidationListener (com.android.tools.idea.ui.properties.InvalidationListener)1 ObservableValue (com.android.tools.idea.ui.properties.ObservableValue)1 CommonProgramParametersPanel (com.intellij.execution.ui.CommonProgramParametersPanel)1 Artifact (com.intellij.facet.frameworks.beans.Artifact)1 Disposable (com.intellij.openapi.Disposable)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 ModalityState (com.intellij.openapi.application.ModalityState)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 MultiLineLabelUI (com.intellij.openapi.ui.MultiLineLabelUI)1 CheckinHandler (com.intellij.openapi.vcs.checkin.CheckinHandler)1 RefreshableOnComponent (com.intellij.openapi.vcs.ui.RefreshableOnComponent)1