@Override void run() { if (_object.listeners() != null) { _object.listeners().remove(_listener); if (_object.listeners().isEmpty()) _object.listeners(null); } }
@Override final Action onVisitingTObject(TObject object) { Action action = super.onVisitingTObject(object); if (action == Action.VISIT) if (object.listeners() == null) return Action.SKIP; return action; }
@Override protected final void onResourceDelete(final TObject object) { if (object.listeners() != null) { invoke( object, new Invocation() { @Override void run(Object listener) { ((ResourceListener) listener).onDelete(); } }); } }
@Override protected final void onKeyedClear(TObject object) { if (object.listeners() != null) { invoke( object, new Invocation() { @Override void run(Object listener) { ((KeyListener) listener).onClear(); } }); } }
@Override protected final void onIndexedWrite(TObject object, final int index) { if (object.listeners() != null) { invoke( object, new Invocation() { @Override void run(Object listener) { ((IndexListener) listener).onSet(index); } }); } }
@SuppressWarnings("unchecked") @Override protected final void onKeyedRemoval(TObject object, final Object key) { if (object.listeners() != null) { invoke( object, new Invocation() { @Override void run(Object listener) { ((KeyListener) listener).onRemove(key); } }); } }
@Override void run() { if (_object instanceof TIndexed) { if (_object.listeners() != null) { invoke( _object, new Invocation() { @Override void run(Object listener) { if (listener instanceof IndexListener) ((IndexListener) listener).onSet(_index); } }); } } }
@Override void run() { if (_object instanceof TIndexed) { if (_object.listeners() != null) { invoke( _object, new Invocation() { @Override void run(Object listener) { if (listener instanceof PropertyListener) ((PropertyListener) listener).onPropertyChanged(_propertyName); } }); } } }
private static void invoke(TObject object, final Invocation invocation) { for (Object listener : object.listeners()) { if (listener instanceof CustomExecutorListener) { final CustomExecutorListener cel = (CustomExecutorListener) listener; cel.Executor.execute( new Runnable() { @Override public void run() { invocation.run(cel.Listener); } }); } else { try { invocation.run(listener); } catch (Exception e) { Log.userCodeException(e); } } } }
@Override void run() { if (_object.listeners() == null) _object.listeners(new PlatformSet<Object>()); _object.listeners().add(_listener); }