protected void internalIncludeItem(T item, Runnable addToData) { backgroundWorker.checkUIAccess(); checkStateBeforeAdd(); addToData.run(); attachListener(item); fireCollectionChanged(Operation.ADD, Collections.singletonList(item)); }
@Override public void sort(SortInfo[] sortInfos) { if (sortInfos.length != 1) { throw new UnsupportedOperationException("Supporting sort by one field only"); } //noinspection unchecked this.sortInfos = sortInfos; if (data.size() > 0) { if (!sortOnDb || containsAllDataFromDb()) { doSort(); fireCollectionChanged(Operation.REFRESH, Collections.emptyList()); } else { refresh(); } } }
protected void internalAddItem(T item, Runnable addToData) { checkNotNullArgument(item, "item is null"); backgroundWorker.checkUIAccess(); checkStateBeforeAdd(); addToData.run(); attachListener(item); modified(item); fireCollectionChanged(Operation.ADD, Collections.singletonList(item)); }
@Override public void excludeItem(T item) { checkNotNullArgument(item, "item is null"); backgroundWorker.checkUIAccess(); checkState(); if (this.item != null && this.item.equals(item)) { setItem(null); } data.remove(item.getId()); detachListener(item); fireCollectionChanged(Operation.REMOVE, Collections.singletonList(item)); }
@Override public void removeItem(T item) { checkNotNullArgument(item, "item is null"); backgroundWorker.checkUIAccess(); checkState(); if (this.item != null && this.item.equals(item)) { setItem(null); } data.remove(item.getId()); detachListener(item); deleted(item); fireCollectionChanged(Operation.REMOVE, Collections.singletonList(item)); }
@Override public void updateItem(T item) { checkNotNullArgument(item, "item is null"); backgroundWorker.checkUIAccess(); checkState(); if (this.item != null && this.item.equals(item)) { T prevItem = item; this.item = item; fireItemChanged(prevItem); } if (data.containsKey(item.getId())) { data.put(item.getId(), item); attachListener(item); fireCollectionChanged(Operation.UPDATE, Collections.singletonList(item)); } }
@Override public void clear() { backgroundWorker.checkUIAccess(); // replaced refresh call with state initialization if (state != State.VALID) { invalidate(); State prevState = state; if (prevState != State.VALID) { valid(); fireStateChanged(prevState); } } // Get items List<Object> collectionItems = new ArrayList<>(data.values()); // Clear container data.clear(); // Notify listeners for (Object obj : collectionItems) { T item = (T) obj; detachListener(item); } setItem(null); fireCollectionChanged(Operation.CLEAR, Collections.emptyList()); }
@SuppressWarnings("unused") protected void afterRefresh(Map<String, Object> parameters, Collection prevIds) { State prevState = state; if (!prevState.equals(State.VALID)) { state = State.VALID; fireStateChanged(prevState); } if (this.item != null && !prevIds.contains(this.item.getId())) { setItem(null); } else if (this.item != null) { setItem(getItem(this.item.getId())); } else { setItem(null); } if (sortInfos != null && sortInfos.length > 0) doSort(); suspended = false; refreshOnResumeRequired = false; fireCollectionChanged(Operation.REFRESH, Collections.emptyList()); checkDataLoadError(); }
refreshOnResumeRequired = false; fireCollectionChanged(Operation.REFRESH, Collections.emptyList());