protected void reattachListeners(Collection prevColl, Collection coll) { if (prevColl != null) for (Object entity : prevColl) { if (entity instanceof Instance) detachListener((Instance) entity); } if (coll != null) for (Object entity : coll) { if (entity instanceof Instance) attachListener((Instance) entity); } }
for (T t : collection) { if (t.equals(item)) { detachListener(t); if (collection instanceof List) { List list = (List) collection;
detachListener(item); // to avoid duplication in any case attachListener(item);
T entity = iterator.next(); if (entity.equals(item)) { detachListener(entity); iterator.remove();
@Override public void clear() { backgroundWorker.checkUIAccess(); checkState(); Collection<T> collection = getCollection(); if (collection != null) { Collection<T> collectionItems = new ArrayList<>(collection); doNotModify = true; try { // Clear collection collection.clear(); // Notify listeners for (T item : collectionItems) { if (metaProperty.getRange().getCardinality() == Range.Cardinality.ONE_TO_MANY) { MetaProperty inverseProperty = metaProperty.getInverse(); if (inverseProperty == null) { throw new UnsupportedOperationException("No inverse property for " + metaProperty); } item.setValue(inverseProperty.getName(), null); } // detach listener only after setting value to the link property detachListener(item); } setItem(null); fireCollectionChanged(Operation.CLEAR, Collections.emptyList()); } finally { doNotModify = false; } } }
@Override public void excludeItem(T item) { checkNotNullArgument(item, "item is null"); backgroundWorker.checkUIAccess(); checkState(); checkPermission(); Collection<T> collection = getCollection(); if (collection != null) { if (this.item != null && this.item.equals(item)) { setItem(null); } doNotModify = true; try { collection.remove(item); MetaProperty inverseProperty = metaProperty.getInverse(); if (inverseProperty != null) item.setValue(inverseProperty.getName(), null); // detach listener only after setting value to the link property detachListener(item); fireCollectionChanged(Operation.REMOVE, Collections.singletonList(item)); } finally { doNotModify = false; } } }