ObservableList implementations.
The base class provides two functionalities for the implementing classes.
addListener and removeListener methods.
fireChange(javafx.collections.ListChangeListener.Change) method is provided
for notifying the listeners with a Change object.
ListChangeListener.Change object. There are various methods called
next*, like nextAdd(int, int) for new items in the lists or nextRemove(int, java.lang.Object) for
an item being removed from the list.
These methods must be always enclosed in beginChange() and endChange() block.
See the example below.
public void removeOddIndexes() {
beginChange();
try {
for (int i = 1; i < size(); ++i) {
remove(i);
}
} finally {
endChange();
}
}
public void remove(int i) {
beginChange();
try {
E removed = ... //do some stuff that will actually remove the element at index i
nextRemove(i, removed);
} finally {
endChange();
}
}
The try/finally blocks in the example are needed only if there's a possibility for an exception to occur
inside a beginChange() / endChange() blockNote
If you want to create modifiable ObservableList implementation, consider
using ModifiableObservableListBase as a superclass.
Note
In order to create list with sequential access, you should override listIterator(),
iterator() methods and use them in get, size() and other methods accordingly.
ObservableList, ListChangeListener.Change , ModifiableObservableListBase
| Modifier and Type | Field and Description |
|---|---|
| private ListChangeBuilder | |
| private ListListenerHelper |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | addAll(E...
the elements to add elements)Implements javafx. A convenience method for var-arg addition of elements. |
| public final void | addListener(InvalidationListener
The listener to register listener)Implements javafx. Adds an |
| public final void | addListener(ListChangeListener<? super E>
the listener for listening to the list changes listener)Implements javafx. Add a listener to this observable list. |
| protected final void | |
| protected final void | |
| protected final void | fireChange(ListChangeListener.
an object representing the change that was done changeNotifies all listeners of a change |
| private ListChangeBuilder | |
| protected final boolean | Returns: true if there is a listener for this listReturns true if there are some listeners registered for this list. |
| protected final void | nextAdd(int
marks the beginning (inclusive) of the range that was added from, int marks the end (exclusive) of the range that was added to)Adds a new add operation to the change. |
| protected final void | nextPermutation(int
marks the beginning (inclusive) of the range that was permutated from, int marks the end (exclusive) of the range that was permutated to, int[] the permutation in that range. Even if perm)from != 0, the array should
contain the indexes of the list. Therefore, such permutation would not contain indexes of range (0, from)Adds a new permutation operation to the change. |
| protected final void | nextRemove(int
the index where the items were removed idx, List<? extends E> the list of items that were removed removed)Adds a new remove operation to the change with multiple items removed. |
| protected final void | nextRemove(int
the index where the item was removed idx, E the item that was removed removed)Adds a new remove operation to the change with single item removed. |
| protected final void | nextReplace(int
the index where the items were replaced from, int the end index (exclusive) of the range where the new items reside to, List<? extends E> the list of items that were removed removed)Adds a new replace operation to the change. |
| protected final void | nextSet(int
the index of the item that was set idx, E the old value at the old)idx position.Adds a new set operation to the change. |
| protected final void | nextUpdate(int
the position in the list where the updated element resides. pos)Adds a new update operation to the change. |
| public void | remove(int
the start of the range to remove (inclusive) from, int the end of the range to remove (exclusive) to)Implements javafx. A simplified way of calling |
| public boolean | removeAll(E...
the elements to be removed elements)Implements javafx. A convenience method for var-arg usage of the |
| public final void | removeListener(InvalidationListener
The listener to remove listener)Implements javafx. Removes the given listener from the list of listeners, that are notified
whenever the value of the |
| public final void | removeListener(ListChangeListener<? super E>
a listener to remove listener)Implements javafx. Tries to remove a listener from this observable list. |
| public boolean | retainAll(E...
the elements to be retained elements)Implements javafx. A convenience method for var-arg usage of the |
| public boolean | setAll(E...
the elements to set elements)Implements javafx. Clears the ObservableList and adds all the elements passed as var-args. |
| public boolean | setAll(Collection<? extends E>
the collection with elements that will be added to this observableArrayList col)Implements javafx. Clears the ObservableList and adds all elements from the collection. |
| changeBuilder | back to summary |
|---|---|
| private ListChangeBuilder<E> changeBuilder | |
| listenerHelper | back to summary |
|---|---|
| private ListListenerHelper<E> listenerHelper | |
| ObservableListBase | back to summary |
|---|---|
| public ObservableListBase() Creates a default | |
| addAll | back to summary |
|---|---|
| public boolean addAll(E... elements) Implements javafx. Doc from javafx. A convenience method for var-arg addition of elements.
| |
| addListener | back to summary |
|---|---|
| public final void addListener(InvalidationListener listener) Implements javafx. Doc from javafx. Adds an
Note that the same actual
The
| |
| addListener | back to summary |
|---|---|
| public final void addListener(ListChangeListener<? super E> listener) Implements javafx. Doc from javafx. Add a listener to this observable list.
| |
| beginChange | back to summary |
|---|---|
| protected final void beginChange() Begins a change block.
Must be called before any of the
| |
| endChange | back to summary |
|---|---|
| protected final void endChange() Ends the change block.
If the block is the outer-most block for the Ending a nested block doesn't fire a notification.
| |
| fireChange | back to summary |
|---|---|
| protected final void fireChange(ListChangeListener. Notifies all listeners of a change
| |
| getListChangeBuilder | back to summary |
|---|---|
| private ListChangeBuilder | |
| hasListeners | back to summary |
|---|---|
| protected final boolean hasListeners() Returns true if there are some listeners registered for this list.
| |
| nextAdd | back to summary |
|---|---|
| protected final void nextAdd(int from, int to) Adds a new add operation to the change. There's no need to provide the list of added items as they can be found directly in the list under the specified indexes. Note needs to be called inside Note needs to reflect the current state of the list.
| |
| nextPermutation | back to summary |
|---|---|
| protected final void nextPermutation(int from, int to, int[] perm) Adds a new permutation operation to the change.
The permutation on index It's not necessary to provide the smallest permutation possible. It's correct to always call this method
with Note needs to be called inside Note needs to reflect the current state of the list.
| |
| nextRemove | back to summary |
|---|---|
| protected final void nextRemove(int idx, List<? extends E> removed) Adds a new remove operation to the change with multiple items removed. Note needs to be called inside Note needs to reflect the current state of the list.
| |
| nextRemove | back to summary |
|---|---|
| protected final void nextRemove(int idx, E removed) Adds a new remove operation to the change with single item removed. Note needs to be called inside Note needs to reflect the current state of the list.
| |
| nextReplace | back to summary |
|---|---|
| protected final void nextReplace(int from, int to, List<? extends E> removed) Adds a new replace operation to the change.
Equivalent to Note needs to be called inside Note needs to reflect the current state of the list.
| |
| nextSet | back to summary |
|---|---|
| protected final void nextSet(int idx, E old) Adds a new set operation to the change.
Equivalent to Note needs to be called inside Note needs to reflect the current state of the list.
| |
| nextUpdate | back to summary |
|---|---|
| protected final void nextUpdate(int pos) Adds a new update operation to the change. Note needs to be called inside Note needs to reflect the current state of the list.
| |
| remove | back to summary |
|---|---|
| public void remove(int from, int to) Implements javafx. Doc from javafx. A simplified way of calling
| |
| removeAll | back to summary |
|---|---|
| public boolean removeAll(E... elements) Implements javafx. Doc from javafx. A convenience method for var-arg usage of the
| |
| removeListener | back to summary |
|---|---|
| public final void removeListener(InvalidationListener listener) Implements javafx. Doc from javafx. Removes the given listener from the list of listeners, that are notified
whenever the value of the If the given listener has not been previously registered (i.e. it was never added) then this method call is a no-op. If it had been previously added then it will be removed. If it had been added more than once, then only the first occurrence will be removed.
| |
| removeListener | back to summary |
|---|---|
| public final void removeListener(ListChangeListener<? super E> listener) Implements javafx. Doc from javafx. Tries to remove a listener from this observable list. If the listener is not attached to this list, nothing happens.
| |
| retainAll | back to summary |
|---|---|
| public boolean retainAll(E... elements) Implements javafx. Doc from javafx. A convenience method for var-arg usage of the
| |
| setAll | back to summary |
|---|---|
| public boolean setAll(E... elements) Implements javafx. Doc from javafx. Clears the ObservableList and adds all the elements passed as var-args.
| |
| setAll | back to summary |
|---|---|
| public boolean setAll(Collection<? extends E> col) Implements javafx. Doc from javafx. Clears the ObservableList and adds all elements from the collection.
| |