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:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.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 java.util.List<E>wrappedList
-
Constructor Summary
Constructors Modifier Constructor Description protectedObservableList(java.util.List<E> wrappedList, java.lang.Object elementType)protectedObservableList(Realm realm, java.util.List<E> wrappedList, java.lang.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, java.util.Collection<? extends E> c)booleanaddAll(java.util.Collection<? extends E> c)voidaddListChangeListener(IListChangeListener<? super E> listener)Adds the given list change listener to the list of list change listeners.protected voidaddListener(java.lang.Object listenerType, IObservablesListener listener)voidclear()protected java.lang.Objectclone()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)booleanequals(java.lang.Object o)protected voidfireChange()protected voidfireEvent(ObservableEvent event)protected voidfireListChange(ListDiff<E> diff)protected voidfirstListenerAdded()Eget(int index)java.lang.ObjectgetElementType()Returns the element type of this observable collection, ornullif this observable collection is untyped.RealmgetRealm()protected voidgetterCalled()inthashCode()protected booleanhasListeners()intindexOf(java.lang.Object o)booleanisEmpty()booleanisStale()Returns the stale state.java.util.Iterator<E>iterator()intlastIndexOf(java.lang.Object o)protected voidlastListenerRemoved()java.util.ListIterator<E>listIterator()java.util.ListIterator<E>listIterator(int index)Emove(int oldIndex, int newIndex)Moves the element located atoldIndextonewIndex.Eremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)voidremoveListChangeListener(IListChangeListener<? super E> listener)Removes the given list change listener from the list of list change listeners.protected voidremoveListener(java.lang.Object listenerType, IObservablesListener listener)booleanretainAll(java.util.Collection<?> c)Eset(int index, E element)voidsetStale(boolean stale)Sets the stale state.intsize()java.util.List<E>subList(int fromIndex, int toIndex)java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()protected voidupdateWrappedList(java.util.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 org.eclipse.core.databinding.observable.IObservable
addChangeListener, addDisposeListener, addStaleListener, dispose, getRealm, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener
-
-
-
-
Field Detail
-
wrappedList
protected java.util.List<E> wrappedList
-
-
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(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<E>- Specified by:
containsin interfaceIObservableList<E>- Specified by:
containsin interfacejava.util.List<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<E>- Specified by:
containsAllin interfaceIObservableList<E>- Specified by:
containsAllin interfacejava.util.List<E>
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equalsin interfacejava.util.Collection<E>- Specified by:
equalsin interfaceIObservableList<E>- Specified by:
equalsin interfacejava.util.List<E>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<E>- Specified by:
hashCodein interfaceIObservableList<E>- Specified by:
hashCodein interfacejava.util.List<E>- Overrides:
hashCodein classjava.lang.Object
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<E>- Specified by:
isEmptyin interfaceIObservableList<E>- Specified by:
isEmptyin interfacejava.util.List<E>
-
iterator
public java.util.Iterator<E> iterator()
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<E>- Specified by:
sizein interfaceIObservableList<E>- Specified by:
sizein interfacejava.util.List<E>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<E>- Specified by:
toArrayin interfaceIObservableList<E>- Specified by:
toArrayin interfacejava.util.List<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<E>- Specified by:
toArrayin interfaceIObservableList<E>- Specified by:
toArrayin interfacejava.util.List<E>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
get
public E get(int index)
- Specified by:
getin interfaceIObservableList<E>- Specified by:
getin interfacejava.util.List<E>- "TrackedGetter"
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfaceIObservableList<E>- Specified by:
indexOfin interfacejava.util.List<E>- "TrackedGetter"
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfaceIObservableList<E>- Specified by:
lastIndexOfin interfacejava.util.List<E>- "TrackedGetter"
-
listIterator
public java.util.ListIterator<E> listIterator()
- Specified by:
listIteratorin interfaceIObservableList<E>- Specified by:
listIteratorin interfacejava.util.List<E>- "TrackedGetter"
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
- Specified by:
listIteratorin interfaceIObservableList<E>- Specified by:
listIteratorin interfacejava.util.List<E>- "TrackedGetter"
-
subList
public java.util.List<E> subList(int fromIndex, int toIndex)
- Specified by:
subListin interfaceIObservableList<E>- Specified by:
subListin interfacejava.util.List<E>
-
getterCalled
protected void getterCalled()
-
set
public E set(int index, E element)
- Specified by:
setin interfaceIObservableList<E>- Specified by:
setin interfacejava.util.List<E>
-
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:
java.lang.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)
- Specified by:
removein interfaceIObservableList<E>- Specified by:
removein interfacejava.util.List<E>
-
add
public boolean add(E o)
- Specified by:
addin interfacejava.util.Collection<E>- Specified by:
addin interfaceIObservableList<E>- Specified by:
addin interfacejava.util.List<E>
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
- Specified by:
addAllin interfacejava.util.Collection<E>- Specified by:
addAllin interfaceIObservableList<E>- Specified by:
addAllin interfacejava.util.List<E>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)- Specified by:
addAllin interfaceIObservableList<E>- Specified by:
addAllin interfacejava.util.List<E>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<E>- Specified by:
removein interfaceIObservableList<E>- Specified by:
removein interfacejava.util.List<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<E>- Specified by:
removeAllin interfaceIObservableList<E>- Specified by:
removeAllin interfacejava.util.List<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<E>- Specified by:
retainAllin interfaceIObservableList<E>- Specified by:
retainAllin interfacejava.util.List<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 java.lang.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
-
updateWrappedList
protected void updateWrappedList(java.util.List<E> newList)
-
addListener
protected void addListener(java.lang.Object listenerType, IObservablesListener listener)- Parameters:
listenerType- arbitrary object to identify a type of the listenerlistener- the listener to add; notnull
-
removeListener
protected void removeListener(java.lang.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 java.lang.Object clone() throws java.lang.CloneNotSupportedException- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException
-
-