Class ObservableList<E>
- java.lang.Object
-
- org.eclipse.core.databinding.observable.AbstractObservable
-
- org.eclipse.core.databinding.observable.list.ObservableList<E>
-
- Type Parameters:
E- the type of the elements in this list
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>,IObservable,IObservableCollection<E>,IObservableList<E>
- Direct Known Subclasses:
WritableList
public abstract class ObservableList<E> extends AbstractObservable implements IObservableList<E>
Abstract implementation ofIObservableList, based on an underlying regular list.This class is thread safe. All state accessing methods must be invoked from the
current realm. Methods for adding and removing listeners may be invoked from any thread.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description protected List<E>wrappedList
-
Constructor Summary
Constructors Modifier Constructor Description protectedObservableList(List<E> wrappedList, Object elementType)protectedObservableList(Realm realm, List<E> wrappedList, Object elementType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)booleanadd(E o)booleanaddAll(int index, Collection<? extends E> c)booleanaddAll(Collection<? extends E> c)voidaddListChangeListener(IListChangeListener<? super E> listener)Adds the given list change listener to the list of list change listeners.protected voidaddListener(Object listenerType, IObservablesListener listener)voidclear()protected Objectclone()booleancontains(Object o)booleancontainsAll(Collection<?> c)booleanequals(Object o)protected voidfireChange()protected voidfireEvent(ObservableEvent event)protected voidfireListChange(ListDiff<E> diff)protected voidfirstListenerAdded()Eget(int index)ObjectgetElementType()Returns the element type of this observable collection, ornullif this observable collection is untyped.RealmgetRealm()protected voidgetterCalled()inthashCode()protected booleanhasListeners()intindexOf(Object o)booleanisEmpty()booleanisStale()Returns the stale state.Iterator<E>iterator()intlastIndexOf(Object o)protected voidlastListenerRemoved()ListIterator<E>listIterator()ListIterator<E>listIterator(int index)Emove(int oldIndex, int newIndex)Moves the element located atoldIndextonewIndex.Eremove(int index)booleanremove(Object o)booleanremoveAll(Collection<?> c)voidremoveListChangeListener(IListChangeListener<? super E> listener)Removes the given list change listener from the list of list change listeners.protected voidremoveListener(Object listenerType, IObservablesListener listener)booleanretainAll(Collection<?> c)Eset(int index, E element)voidsetStale(boolean stale)Sets the stale state.intsize()List<E>subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] a)StringtoString()protected voidupdateWrappedList(List<E> newList)-
Methods inherited from class org.eclipse.core.databinding.observable.AbstractObservable
addChangeListener, addDisposeListener, addStaleListener, checkRealm, dispose, fireStale, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface org.eclipse.core.databinding.observable.IObservable
addChangeListener, addDisposeListener, addStaleListener, dispose, getRealm, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener
-
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
-
-
-
Method Detail
-
addListChangeListener
public void addListChangeListener(IListChangeListener<? super E> listener)
Description copied from interface:IObservableListAdds the given list change listener to the list of list change listeners.- Specified by:
addListChangeListenerin interfaceIObservableList<E>- Parameters:
listener- the change listener to add; notnull
-
removeListChangeListener
public void removeListChangeListener(IListChangeListener<? super E> listener)
Description copied from interface:IObservableListRemoves the given list change listener from the list of list change listeners. Has no effect if the given listener is not registered as a list change listener.- Specified by:
removeListChangeListenerin interfaceIObservableList<E>- Parameters:
listener- the change listener to remove; notnull
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceIObservableList<E>- Specified by:
containsin interfaceList<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceIObservableList<E>- Specified by:
containsAllin interfaceList<E>
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceIObservableList<E>- Specified by:
isEmptyin interfaceList<E>
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceIObservableList<E>- Specified by:
sizein interfaceList<E>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceIObservableList<E>- Specified by:
toArrayin interfaceList<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceIObservableList<E>- Specified by:
toArrayin interfaceList<E>
-
get
public E get(int index)
-
indexOf
public int indexOf(Object o)
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOfin interfaceIObservableList<E>- Specified by:
lastIndexOfin interfaceList<E>- "TrackedGetter"
-
listIterator
public ListIterator<E> listIterator()
- Specified by:
listIteratorin interfaceIObservableList<E>- Specified by:
listIteratorin interfaceList<E>- "TrackedGetter"
-
listIterator
public ListIterator<E> listIterator(int index)
- Specified by:
listIteratorin interfaceIObservableList<E>- Specified by:
listIteratorin interfaceList<E>- "TrackedGetter"
-
getterCalled
protected void getterCalled()
-
move
public E move(int oldIndex, int newIndex)
Moves the element located atoldIndextonewIndex. This method is equivalent to callingadd(newIndex, remove(oldIndex)).Subclasses should override this method to deliver list change notification for the remove and add operations in the same ListChangeEvent, as this allows
ListDiff.accept(ListDiffVisitor)to recognize the operation as a move.- Specified by:
movein interfaceIObservableList<E>- Parameters:
oldIndex- the element's position before the move. Must be within the range0 <= oldIndex < size().newIndex- the element's position after the move. Must be within the range0 <= newIndex < size().- Returns:
- the element that was moved.
- Throws:
IndexOutOfBoundsException- if either argument is out of range (0 <= index < size()).- Since:
- 1.1
- See Also:
ListDiffVisitor.handleMove(int, int, Object),ListDiff.accept(ListDiffVisitor)
-
remove
public E remove(int index)
-
add
public boolean add(E o)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceIObservableList<E>- Specified by:
addin interfaceList<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceIObservableList<E>- Specified by:
addAllin interfaceList<E>
-
addAll
public boolean addAll(int index, Collection<? extends E> c)
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceIObservableList<E>- Specified by:
removein interfaceList<E>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceIObservableList<E>- Specified by:
removeAllin interfaceList<E>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceIObservableList<E>- Specified by:
retainAllin interfaceList<E>
-
clear
public void clear()
-
isStale
public boolean isStale()
Returns the stale state. Must be invoked from the current realm.- Specified by:
isStalein interfaceIObservable- Returns:
- stale state
-
setStale
public void setStale(boolean stale)
Sets the stale state. Must be invoked from the current realm.- Parameters:
stale- The stale state to list. This will fire a stale event if the given boolean is true and this observable list was not already stale.
-
fireChange
protected void fireChange()
- Overrides:
fireChangein classAbstractObservable
-
getElementType
public Object getElementType()
Description copied from interface:IObservableCollectionReturns the element type of this observable collection, ornullif this observable collection is untyped.- Specified by:
getElementTypein interfaceIObservableCollection<E>- Specified by:
getElementTypein interfaceIObservableList<E>- Returns:
- the type of the elements or
nullif untyped
-
addListener
protected void addListener(Object listenerType, IObservablesListener listener)
- Parameters:
listenerType- arbitrary object to identify a type of the listenerlistener- the listener to add; notnull
-
removeListener
protected void removeListener(Object listenerType, IObservablesListener listener)
- Parameters:
listenerType- arbitrary object to identify a type of the listenerlistener- the listener to remove; notnull
-
hasListeners
protected boolean hasListeners()
-
fireEvent
protected void fireEvent(ObservableEvent event)
-
firstListenerAdded
protected void firstListenerAdded()
-
lastListenerRemoved
protected void lastListenerRemoved()
-
getRealm
public Realm getRealm()
- Returns:
- Returns the realm.
-
clone
protected Object clone() throws CloneNotSupportedException
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
-