private void initListEvents ( ) { this . listChangeListener = new ListChangeListener < SourceType > ( ) { @ Override public void onChanged ( Change < ? extends SourceType > listEvent ) { // We have to stage delete events, because if we process them // separately, there will be unwanted ChangeEvents on the // targetList List < TargetType > deleteStaging = new ArrayList <> ( ) ; while ( listEvent . next ( ) ) { if ( listEvent . wasUpdated ( ) ) { processUpdateEvent ( listEvent ) ; } else if ( listEvent . wasReplaced ( ) ) { processReplaceEvent ( listEvent , deleteStaging ) ; } else if ( listEvent . wasAdded ( ) ) { processAddEvent ( listEvent ) ; } else if ( listEvent . wasRemoved ( ) ) { processRemoveEvent ( listEvent , deleteStaging ) ; } } // Process the staged elements processStagingLists ( deleteStaging ) ; } } ; modelListProperty ( ) . addListener ( new WeakListChangeListener <> ( listChangeListener ) ) ; }
If the list changed we want the recreate the targetType representation