protected void attachParentListener ( ) { final AutoRelease ar = ClassUtility . getLastClassAnnotation ( this . getClass ( ) , AutoRelease . class ) ; // Only manage automatic release when the annotation exists with true value if ( ar != null && ar . value ( ) && node ( ) != null ) { // TODO check rootnode null when using NullView // Allow to release the model if the root business object doesn't exist anymore node ( ) . parentProperty ( ) . addListener ( new ChangeListener < Node > ( ) { @ Override public void changed ( final ObservableValue < ? extends Node > observable , final Node oldValue , final Node newValue ) { if ( newValue != null ) { AbstractBaseModel . this . hasBeenAttached = true ; } if ( newValue == null && AbstractBaseModel . this . hasBeenAttached ) { AbstractBaseModel . this . hasBeenAttached = false ; release ( ) ; node ( ) . parentProperty ( ) . removeListener ( this ) ; } } } ) ; } }
Attach a custom listener that will release the mode when the rootNode is removed from its parent .