mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
AbstractCollectionComboBoxModel — specify list type
This commit is contained in:
@@ -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<T> 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<T> getItems();
|
||||
}
|
||||
|
||||
@@ -23,16 +23,16 @@ import java.util.List;
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class MutableCollectionComboBoxModel<T> extends AbstractCollectionComboBoxModel {
|
||||
public class MutableCollectionComboBoxModel<T> extends AbstractCollectionComboBoxModel<T> {
|
||||
private List<T> myItems;
|
||||
|
||||
public MutableCollectionComboBoxModel(@NotNull List<T> items, @Nullable Object selection) {
|
||||
public MutableCollectionComboBoxModel(@NotNull List<T> items, @Nullable T selection) {
|
||||
super(selection);
|
||||
|
||||
myItems = items;
|
||||
}
|
||||
|
||||
public MutableCollectionComboBoxModel(List<T> items) {
|
||||
public MutableCollectionComboBoxModel(@NotNull List<T> items) {
|
||||
super(items.isEmpty() ? null : items.get(0));
|
||||
myItems = items;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class MutableCollectionComboBoxModel<T> extends AbstractCollectionComboBo
|
||||
return myItems;
|
||||
}
|
||||
|
||||
public void update(List<T> items) {
|
||||
public void update(@NotNull List<T> items) {
|
||||
myItems = items;
|
||||
super.update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user