Class AbstractObservableList<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- org.eclipse.core.databinding.observable.list.AbstractObservableList<E>
-
- Type Parameters:
E- the list element type
- All Implemented Interfaces:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,IObservable,IObservableCollection<E>,IObservableList<E>
- Direct Known Subclasses:
ComputedList,MultiList
public abstract class AbstractObservableList<E> extends java.util.AbstractList<E> implements IObservableList<E>
Subclasses should override at least get(int index) and size().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
- Implementation Note:
- If methods are added to the interface which this class implements then implementations of those methods must be added to this class.
-
-
Constructor Summary
Constructors Constructor Description AbstractObservableList()AbstractObservableList(Realm realm)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(E o)booleanaddAll(int index, java.util.Collection<? extends E> c)booleanaddAll(java.util.Collection<? extends E> c)voidaddChangeListener(IChangeListener listener)Adds the given change listener to the list of change listeners.voidaddDisposeListener(IDisposeListener listener)Adds the given dispose listener to the list of dispose listeners.voidaddListChangeListener(IListChangeListener<? super E> listener)Adds the given list change listener to the list of list change listeners.voidaddStaleListener(IStaleListener listener)Adds the given stale listener to the list of stale listeners.protected voidcheckRealm()Asserts that the realm is the current realm.booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)voiddispose()Disposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.protected abstract intdoGetSize()booleanequals(java.lang.Object o)protected voidfireChange()Fires change event.protected voidfireListChange(ListDiff<E> diff)protected voidfireStale()Fires stale event.protected voidfirstListenerAdded()RealmgetRealm()Returns the realm for this observable.inthashCode()protected booleanhasListeners()Returns whether this observable list has any registered listeners.intindexOf(java.lang.Object o)booleanisDisposed()Returns whether the observable has been disposedbooleanisEmpty()booleanisStale()Returns whether the state of this observable is stale and is expected to change soon.java.util.Iterator<E>iterator()intlastIndexOf(java.lang.Object o)protected voidlastListenerRemoved()Emove(int oldIndex, int newIndex)Moves the element located atoldIndextonewIndex.booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)voidremoveChangeListener(IChangeListener listener)Removes the given change listener from the list of change listeners.voidremoveDisposeListener(IDisposeListener listener)Removes the given dispose listener from the list of dispose listeners.voidremoveListChangeListener(IListChangeListener<? super E> listener)Removes the given list change listener from the list of list change listeners.voidremoveStaleListener(IStaleListener listener)Removes the given stale listener from the list of stale listeners.booleanretainAll(java.util.Collection<?> c)intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a)-
Methods inherited from class java.util.AbstractList
add, clear, get, listIterator, listIterator, remove, removeRange, set, subList
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.core.databinding.observable.list.IObservableList
get, getElementType, listIterator, listIterator, remove, set, subList
-
-
-
-
Constructor Detail
-
AbstractObservableList
public AbstractObservableList(Realm realm)
- Parameters:
realm- the realm; notnull
-
AbstractObservableList
public AbstractObservableList()
-
-
Method Detail
-
hasListeners
protected boolean hasListeners()
Returns whether this observable list has any registered listeners.- Returns:
- whether this observable list has any registered listeners.
- Since:
- 1.2
-
isStale
public boolean isStale()
Description copied from interface:IObservableReturns whether the state of this observable is stale and is expected to change soon. A non-stale observable that becomes stale will notify its stale listeners. A stale object that becomes non-stale does so by changing its state and notifying its change listeners, it does not notify its stale listeners about becoming non-stale. Clients that do not expect asynchronous changes may ignore staleness of observable objects.- Specified by:
isStalein interfaceIObservable- Returns:
- true if this observable's state is stale and will change soon.
-
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
-
addChangeListener
public void addChangeListener(IChangeListener listener)
Description copied from interface:IObservableAdds the given change listener to the list of change listeners. Change listeners are notified about changes of the state of this observable in a generic way, without specifying the change that happened. To get the changed state, a change listener needs to query for the current state of this observable.- Specified by:
addChangeListenerin interfaceIObservable- Parameters:
listener- the listener to add; notnull
-
removeChangeListener
public void removeChangeListener(IChangeListener listener)
Description copied from interface:IObservableRemoves the given change listener from the list of change listeners. Has no effect if the given listener is not registered as a change listener.- Specified by:
removeChangeListenerin interfaceIObservable- Parameters:
listener- the listener to remove; notnull
-
addStaleListener
public void addStaleListener(IStaleListener listener)
Description copied from interface:IObservableAdds the given stale listener to the list of stale listeners. Stale listeners are notified when an observable object becomes stale, not when is becomes non-stale.- Specified by:
addStaleListenerin interfaceIObservable- Parameters:
listener- the listener to add; notnull- See Also:
IObservable.isStale()
-
removeStaleListener
public void removeStaleListener(IStaleListener listener)
Description copied from interface:IObservableRemoves the given stale listener from the list of stale listeners. Has no effect if the given listener is not registered as a stale listener.- Specified by:
removeStaleListenerin interfaceIObservable- Parameters:
listener- the listener to remove; notnull
-
addDisposeListener
public void addDisposeListener(IDisposeListener listener)
Description copied from interface:IObservableAdds the given dispose listener to the list of dispose listeners. Dispose listeners are notified when an observable has been disposed.- Specified by:
addDisposeListenerin interfaceIObservable- Parameters:
listener- the listener to add- Since:
- 1.2
-
removeDisposeListener
public void removeDisposeListener(IDisposeListener listener)
Description copied from interface:IObservableRemoves the given dispose listener from the list of dispose listeners. Has no effect if the given listener is not registered as a dispose listener.- Specified by:
removeDisposeListenerin interfaceIObservable- Parameters:
listener- the listener to remove- Since:
- 1.2
-
fireChange
protected void fireChange()
Fires change event. Must be invoked from the current realm.
-
fireStale
protected void fireStale()
Fires stale event. Must be invoked from the current realm.
-
firstListenerAdded
protected void firstListenerAdded()
-
lastListenerRemoved
protected void lastListenerRemoved()
-
isDisposed
public boolean isDisposed()
Description copied from interface:IObservableReturns whether the observable has been disposed- Specified by:
isDisposedin interfaceIObservable- Returns:
- whether the observable has been disposed
- Since:
- 1.2
-
dispose
public void dispose()
Description copied from interface:IObservableDisposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.- Specified by:
disposein interfaceIObservable
-
size
public final int size()
-
doGetSize
protected abstract int doGetSize()
- Returns:
- the size
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(java.lang.Object o)
-
iterator
public java.util.Iterator<E> iterator()
-
toArray
public java.lang.Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
add
public boolean add(E o)
-
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 boolean remove(java.lang.Object o)
-
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>- Overrides:
containsAllin classjava.util.AbstractCollection<E>
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)- Specified by:
addAllin interfaceIObservableList<E>- Specified by:
addAllin interfacejava.util.List<E>- Overrides:
addAllin classjava.util.AbstractList<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfaceIObservableList<E>- Specified by:
indexOfin interfacejava.util.List<E>- Overrides:
indexOfin classjava.util.AbstractList<E>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfaceIObservableList<E>- Specified by:
lastIndexOfin interfacejava.util.List<E>- Overrides:
lastIndexOfin classjava.util.AbstractList<E>
-
getRealm
public Realm getRealm()
Description copied from interface:IObservableReturns the realm for this observable. Unless otherwise specified, getters and setters must be accessed from within this realm. Listeners will be within this realm when they receive events from this observable.Because observables can only be accessed from within one realm, and they always fire events on that realm, their state can be observed in an incremental way. It is always safe to call getters of an observable from within a change listener attached to that observable.
- Specified by:
getRealmin interfaceIObservable- Returns:
- the realm
-
checkRealm
protected void checkRealm()
Asserts that the realm is the current realm.- Throws:
AssertionFailedException- if the realm is not the current realm- See Also:
Realm.isCurrent()
-
-