From 9f28f9d29fa4e4e6c5119139ddc33b43c72f16bb Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Jan 2014 17:57:37 +0100 Subject: [PATCH] =?UTF-8?q?AbstractCollectionComboBoxModel=20=E2=80=94=20s?= =?UTF-8?q?pecify=20list=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/AbstractCollectionComboBoxModel.java | 21 ++++++++++++------- .../ui/MutableCollectionComboBoxModel.java | 8 +++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/AbstractCollectionComboBoxModel.java b/platform/platform-api/src/com/intellij/ui/AbstractCollectionComboBoxModel.java index 8352f43b991f..21b24e8ac19b 100644 --- a/platform/platform-api/src/com/intellij/ui/AbstractCollectionComboBoxModel.java +++ b/platform/platform-api/src/com/intellij/ui/AbstractCollectionComboBoxModel.java @@ -24,25 +24,30 @@ import java.util.List; /** * @author traff */ -public abstract class AbstractCollectionComboBoxModel extends AbstractListModel implements ComboBoxModel { - private Object mySelection; +public abstract class AbstractCollectionComboBoxModel extends AbstractListModel implements ComboBoxModel { + private T mySelection; - public AbstractCollectionComboBoxModel(Object selection) { + public AbstractCollectionComboBoxModel(@Nullable T selection) { mySelection = selection; } + @Override public int getSize() { return getItems().size(); } - public Object getElementAt(final int index) { + @Override + public T getElementAt(final int index) { return getItems().get(index); } - public void setSelectedItem(@Nullable final Object anItem) { - mySelection = anItem; + @Override + public void setSelectedItem(@Nullable Object anItem) { + //noinspection unchecked + mySelection = (T)anItem; } + @Override @Nullable public Object getSelectedItem() { return mySelection; @@ -52,10 +57,10 @@ public abstract class AbstractCollectionComboBoxModel extends AbstractListModel super.fireContentsChanged(this, -1, -1); } - public boolean contains(Object item) { + public boolean contains(T item) { return getItems().contains(item); } @NotNull - abstract protected List getItems(); + abstract protected List getItems(); } diff --git a/platform/platform-api/src/com/intellij/ui/MutableCollectionComboBoxModel.java b/platform/platform-api/src/com/intellij/ui/MutableCollectionComboBoxModel.java index 52053fa8b760..241fd1ea91bc 100644 --- a/platform/platform-api/src/com/intellij/ui/MutableCollectionComboBoxModel.java +++ b/platform/platform-api/src/com/intellij/ui/MutableCollectionComboBoxModel.java @@ -23,16 +23,16 @@ import java.util.List; /** * @author traff */ -public class MutableCollectionComboBoxModel extends AbstractCollectionComboBoxModel { +public class MutableCollectionComboBoxModel extends AbstractCollectionComboBoxModel { private List myItems; - public MutableCollectionComboBoxModel(@NotNull List items, @Nullable Object selection) { + public MutableCollectionComboBoxModel(@NotNull List items, @Nullable T selection) { super(selection); myItems = items; } - public MutableCollectionComboBoxModel(List items) { + public MutableCollectionComboBoxModel(@NotNull List items) { super(items.isEmpty() ? null : items.get(0)); myItems = items; } @@ -43,7 +43,7 @@ public class MutableCollectionComboBoxModel extends AbstractCollectionComboBo return myItems; } - public void update(List items) { + public void update(@NotNull List items) { myItems = items; super.update(); }