// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class MutableCollectionComboBoxModel<T> extends CollectionComboBoxModel<T> {
  public MutableCollectionComboBoxModel(@NotNull List<T> items) {
    super(items);
  }

  public MutableCollectionComboBoxModel() {
    super();
  }

  public MutableCollectionComboBoxModel(@NotNull List<T> items, @Nullable T selection) {
    super(items, selection);
  }

  public void update(@NotNull List<? extends T> items) {
    replaceAll(items);
  }

  public void addItem(T item) {
    add(item);
  }

  @Override
  protected final void fireIntervalAdded(Object source, int index0, int index1) {
    super.fireIntervalAdded(source, index0, index1);

    if (getSize() == 1 && getSelectedItem() == null) {
      setSelectedItem(getElementAt(0));
    }
  }

  @Override
  protected final void fireIntervalRemoved(Object source, int index0, int index1) {
    super.fireIntervalRemoved(source, index0, index1);

    if (getSelected() != null && !contains(getSelected())) {
      setSelectedItem(isEmpty() ? null : getElementAt(index0 == 0 ? 0 : index0 - 1));
    }
  }
}

@@ -246,16 +246,38 @@
 lable;%0A%0A
+import javax.swing.*;%0A
 import j
@@ -374,17 +374,53 @@
 odel%3CT%3E 
-%7B
+implements MutableComboBoxModel%3CT%3E %7B%0A
 %0A  publi
@@ -1385,11 +1385,381 @@
    %7D%0A  %7D
+%0A%0A  @Override%0A  public void addElement(T item) %7B%0A    add(item);%0A  %7D%0A%0A  @SuppressWarnings(%22unchecked%22)%0A  @Override%0A  public void removeElement(Object obj) %7B%0A    T item = ((T) obj);%0A    remove(item);%0A  %7D%0A%0A  @Override%0A  public void insertElementAt(T item, int index) %7B%0A    add(index, item);%0A  %7D%0A%0A  @Override%0A  public void removeElementAt(int index) %7B%0A    remove(index);%0A  %7D
 %0A%7D%0A

Make MutableCollectionComboBoxModel implement MutableComboBoxModel