protected void internalIncludeItem(T item, Runnable addToData) { backgroundWorker.checkUIAccess(); checkStateBeforeAdd(); addToData.run(); attachListener(item); fireCollectionChanged(Operation.ADD, Collections.singletonList(item)); }
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 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)); } }
protected void afterLoadValues(Map<String, Object> params, ValueLoadContext context, List<KeyValueEntity> entities) { ds.detachListener(ds.data.values()); ds.data.clear(); boolean hasEnumerations = ds.metaClass.getOwnProperties().stream() .anyMatch(p -> p.getRange().isEnum()); if (!hasEnumerations) { for (KeyValueEntity entity : entities) { ds.data.put(entity.getId(), entity); ds.attachListener(entity); entity.setMetaClass(ds.metaClass); } } else { List<MetaProperty> enumProperties = getEnumProperties(ds.metaClass); for (KeyValueEntity entity : entities) { convertEnumValues(entity, enumProperties); ds.data.put(entity.getId(), entity); ds.attachListener(entity); entity.setMetaClass(ds.metaClass); } } }
/** * This method is invoked by {@link #loadData(Map)} method immediately after loading entities from {@code DataSupplier}. * <p>If you override this method, be sure to call {@code super()}. If you process the loaded entities somehow, * call {@code super()} after processing. * * @param params datasource parameters, as described in {@link CollectionDatasource#refresh(java.util.Map)} * @param context {@code LoadContext} which was used for loading data * @param entities loaded entities */ protected void afterLoadData(@SuppressWarnings("unused") Map<String, Object> params, LoadContext context, Collection<T> entities) { detachListener(data.values()); data.clear(); for (T entity : entities) { data.put(entity.getId(), entity); attachListener(entity); } lastQuery = context.getQuery(); }