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:
Iterable<E>
,Collection<E>
,List<E>
,IObservable
,IObservableCollection<E>
,IObservableList<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
ConstructorDescriptionCreates an empty writable list in the default realm with anull
element type.WritableList
(Collection<E> collection, Object elementType) Constructs a new instance in the default realm containing the elements of the given collection.WritableList
(List<E> toWrap, Object elementType) Constructs a new instance with the default realm.WritableList
(Realm realm) Creates an empty writable list with anull
element type.WritableList
(Realm realm, Collection<E> collection, Object elementType) Constructs a new instance in the default realm containing the elements of the given collection.WritableList
(Realm realm, List<E> toWrap, Object elementType) Creates a writable list containing elements of the given type, wrapping an existing client-supplied list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends E> c) boolean
addAll
(Collection<? extends E> c) protected void
addListener
(Object listenerType, IObservablesListener listener) void
clear()
protected Object
clone()
protected void
fireEvent
(ObservableEvent event) protected void
getRealm()
protected boolean
protected void
move
(int oldIndex, int newIndex) Moves the element located atoldIndex
tonewIndex
.remove
(int index) boolean
boolean
removeAll
(Collection<?> c) protected void
removeListener
(Object listenerType, IObservablesListener listener) boolean
retainAll
(Collection<?> c) static <T> WritableList<T>
withElementType
(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 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
-
Constructor Details
-
WritableList
public WritableList()Creates an empty writable list in the default realm with anull
element type. -
WritableList
Creates an empty writable list with anull
element type.- Parameters:
realm
- the observable's realm
-
WritableList
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
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
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
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 Details
-
set
- Specified by:
set
in interfaceIObservableList<E>
- Specified by:
set
in interfaceList<E>
- Overrides:
set
in classObservableList<E>
-
move
Description copied from class:ObservableList
Moves the element located atoldIndex
tonewIndex
. 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:
move
in interfaceIObservableList<E>
- Overrides:
move
in 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:
-
remove
- Specified by:
remove
in interfaceIObservableList<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classObservableList<E>
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceIObservableList<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classObservableList<E>
-
add
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceIObservableList<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classObservableList<E>
-
addAll
- Specified by:
addAll
in interfaceIObservableList<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classObservableList<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceIObservableList<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classObservableList<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceIObservableList<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classObservableList<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceIObservableList<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in classObservableList<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classObservableList<E>
-
withElementType
- Parameters:
elementType
- can benull
- Returns:
- new list with the default realm.
-
addListener
- Parameters:
listenerType
- arbitrary object to identify a type of the listenerlistener
- the listener to add; notnull
-
removeListener
- Parameters:
listenerType
- arbitrary object to identify a type of the listenerlistener
- the listener to remove; notnull
-
hasListeners
protected boolean hasListeners() -
fireEvent
-
firstListenerAdded
protected void firstListenerAdded() -
lastListenerRemoved
protected void lastListenerRemoved() -
getRealm
- Returns:
- Returns the realm.
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-