@Override public void removeItem(T item) { checkNotNullArgument(item, "item is null"); checkState(); checkPermission();
@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; } } }
protected void internalIncludeItem(T item, Runnable addToCollection) { backgroundWorker.checkUIAccess(); checkState(); checkPermission(); if (getCollection() == null) { initCollection(); } doNotModify = true; try { // Don't add the same object instance twice if (!containsObjectInstance(item)) addToCollection.run(); MetaProperty inverseProperty = metaProperty.getInverse(); if (inverseProperty != null) item.setValue(inverseProperty.getName(), masterDs.getItem()); // attach listener only after setting value to the link property attachListener(item); fireCollectionChanged(Operation.ADD, Collections.singletonList(item)); } finally { doNotModify = false; } }
backgroundWorker.checkUIAccess(); checkState(); checkPermission();