BaseObservableList

Gaja Sutra gajasutra at gmail.com
Wed Dec 14 09:31:02 PST 2011


> Not sure how would that IterableChangeableBuilder work. Can you give 
> an example?
[Sorry, I forgotten the openjfx-dev list the first time]

An already applied change contains the track of removed items, but only 
indexes of added.

  * public void nextAdd(int from?, int to?) {...}
  * public void nextRemove(int position, ArrayList<E> removedItems) {...}

A runnable change contains the to-be-added items, but only indexes of 
to-be-removed.

  * public void nextAdd(int position, ArrayList<E> toBeAddedItems) {...}
  * public void nextRemove(int from?, int to?) {...}

Applying a runnable change is like your setAll method but with 
caller-specified operation list (the runnable change) between 
begin-commit [no rollback, if no exception support: simpler and probably 
sufficient for collections].

|// I don't have ListChangeListener.Change source code
// then I have not reused ||ListChangeListener.Change
// (but it is probably possible and avoid RunnableChange).
||public class BatchObservableList<E> extends BaseObservableList<E> {

     public void runBatch(final RunnableChange batch) {
         changeBuilder.beginComplexChange();
         for (final ListChange<E> change : batch) {
             switch (change.type) {
             case ADD:
                 addAll(change.from, change.added);
                 break;
             case REMOVE:
                 removeRange(change.from, change.to);
             break;
             }
         }
         changeBuilder.endComplexChange();
         // this calls the ListChangeListeners using just one Change object
     }
}

enum ListOperation {
     ADD, REMOVE; // etc.
}

static class ListChange<E> {
     ListOperation type;
     int from;
     int to;
     List<E> added;
}|


More information about the openjfx-dev mailing list