Class WritableList<E>
- java.lang.Object
-
- org.eclipse.core.databinding.observable.AbstractObservable
-
- org.eclipse.core.databinding.observable.list.ObservableList<E>
-
- org.eclipse.core.databinding.observable.list.WritableList<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>
public class WritableList<E> extends ObservableList<E>
Mutable observable list backed by an ArrayList.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 inherited from class org.eclipse.core.databinding.observable.list.ObservableList
wrappedList
-
-
Constructor Summary
Constructors Constructor Description WritableList()Creates an empty writable list in the default realm with anullelement type.WritableList(java.util.Collection<E> collection, java.lang.Object elementType)Constructs a new instance in the default realm containing the elements of the given collection.WritableList(java.util.List<E> toWrap, java.lang.Object elementType)Constructs a new instance with the default realm.WritableList(Realm realm)Creates an empty writable list with anullelement type.WritableList(Realm realm, java.util.Collection<E> collection, java.lang.Object elementType)Constructs a new instance in the default realm containing the elements of the given collection.WritableList(Realm realm, java.util.List<E> toWrap, java.lang.Object elementType)Creates a writable list containing elements of the given type, wrapping an existing client-supplied list.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)booleanadd(E element)booleanaddAll(int index, java.util.Collection<? extends E> c)booleanaddAll(java.util.Collection<? extends E> c)protected voidaddListener(java.lang.Object listenerType, IObservablesListener listener)voidclear()protected java.lang.Objectclone()protected voidfireEvent(ObservableEvent event)protected voidfirstListenerAdded()RealmgetRealm()protected booleanhasListeners()protected voidlastListenerRemoved()Emove(int oldIndex, int newIndex)Moves the element located atoldIndextonewIndex.Eremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)protected voidremoveListener(java.lang.Object listenerType, IObservablesListener listener)booleanretainAll(java.util.Collection<?> c)Eset(int index, E element)static <T> WritableList<T>withElementType(java.lang.Object elementType)-
Methods inherited from class org.eclipse.core.databinding.observable.list.ObservableList
addListChangeListener, contains, containsAll, equals, fireChange, fireListChange, get, getElementType, getterCalled, hashCode, indexOf, isEmpty, isStale, iterator, lastIndexOf, listIterator, listIterator, removeListChangeListener, setStale, size, subList, toArray, toArray, toString, updateWrappedList
-
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
-
-
-
-
Constructor Detail
-
WritableList
public WritableList()
Creates an empty writable list in the default realm with anullelement type.
-
WritableList
public WritableList(Realm realm)
Creates an empty writable list with anullelement type.- Parameters:
realm- the observable's realm
-
WritableList
public WritableList(java.util.List<E> toWrap, java.lang.Object elementType)
Constructs a new instance with the default realm. Note that for backwards compatibility reasons, the contents of the created WritableList will change with the contents of the given list. If this is not desired,WritableList(Collection, Object)should be used by casting the first argument toCollection.- Parameters:
toWrap- The java.util.List to wrapelementType- can benull
-
WritableList
public WritableList(java.util.Collection<E> collection, java.lang.Object elementType)
Constructs a new instance in the default realm containing the elements of the given collection. Changes to the given collection after calling this method do not affect the contents of the created WritableList.- Parameters:
collection- the collection to copyelementType- can benull- Since:
- 1.2
-
WritableList
public WritableList(Realm realm, java.util.List<E> toWrap, java.lang.Object elementType)
Creates a writable list containing elements of the given type, wrapping an existing client-supplied list. Note that for backwards compatibility reasons, the contents of the created WritableList will change with the contents of the given list. If this is not desired,WritableList(Realm, Collection, Object)should be used by casting the second argument toCollection.- Parameters:
realm- the observable's realmtoWrap- The java.util.List to wrapelementType- can benull
-
WritableList
public WritableList(Realm realm, java.util.Collection<E> collection, java.lang.Object elementType)
Constructs a new instance in the default realm containing the elements of the given collection. Changes to the given collection after calling this method do not affect the contents of the created WritableList.- Parameters:
realm- the observable's realmcollection- the collection to copyelementType- can benull- Since:
- 1.2
-
-
Method Detail
-
set
public E set(int index, E element)
- Specified by:
setin interfaceIObservableList<E>- Specified by:
setin interfacejava.util.List<E>- Overrides:
setin classObservableList<E>
-
move
public E move(int oldIndex, int newIndex)
Description copied from class:ObservableListMoves 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>- Overrides:
movein classObservableList<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.
- 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>- Overrides:
removein classObservableList<E>
-
add
public boolean add(E element)
- Specified by:
addin interfacejava.util.Collection<E>- Specified by:
addin interfaceIObservableList<E>- Specified by:
addin interfacejava.util.List<E>- Overrides:
addin classObservableList<E>
-
add
public void add(int index, E element)- Specified by:
addin interfacejava.util.List<E>- Overrides:
addin classObservableList<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>- Overrides:
addAllin classObservableList<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>- Overrides:
addAllin classObservableList<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>- Overrides:
removein classObservableList<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>- Overrides:
removeAllin classObservableList<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>- Overrides:
retainAllin classObservableList<E>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<E>- Specified by:
clearin interfacejava.util.List<E>- Overrides:
clearin classObservableList<E>
-
withElementType
public static <T> WritableList<T> withElementType(java.lang.Object elementType)
- Parameters:
elementType- can benull- Returns:
- new list with the default realm.
-
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
-
-