private void applyDiff(ListDiff diff, final List list) { diff.accept(new ListDiffVisitor() { public void handleAdd(int index, Object element) { list.add(index, element); } public void handleRemove(int index, Object element) { list.remove(index); } public void handleReplace(int index, Object oldElement, Object newElement) { list.set(index, newElement); } }); }
/** * Returns true if the diff contains no added, removed, moved or replaced * elements. * * @return true if the diff contains no added, removed, moved or replaced * elements. * @since 1.2 */ public boolean isEmpty() { return getDifferences().length == 0; }
@Override protected void doUpdateList(List<E> source, ListDiff<E> diff) { diff.applyTo(source); }
diff.getDifferences(); destination.clear(); diff.accept(new ListDiffVisitor<S>() { boolean useMoveAndReplace = updateListStrategy.useMoveAndReplace();
/** * Updates the property on the source with the specified change. * * @param source * the property source * @param list * the new list * @param diff * a diff describing the change * @noreference This method is not intended to be referenced by clients. * @since 1.6 */ public final void setList(S source, List<E> list, ListDiff<E> diff) { if (source != null && !diff.isEmpty()) { doSetList(source, list, diff); } }
/** * Updates the property on the source with the specified change. * * @param source * the property source * @param list * the new list * @param diff * a diff describing the change * @noreference This method is not intended to be referenced by clients. * @since 1.6 */ public final void setList(S source, List<E> list, ListDiff<E> diff) { if (source != null && !diff.isEmpty()) { doSetList(source, list, diff); } }
public void handleListChange(ListChangeEvent event) { event.diff.accept(new ListDiffVisitor() { public void handleAdd(int index, Object element) { IObservable dependency = (IObservable) element; dependency.addChangeListener(dependencyListener); dependency.addStaleListener(dependencyListener); } public void handleRemove(int index, Object element) { IObservable dependency = (IObservable) element; dependency.removeChangeListener(dependencyListener); dependency.removeStaleListener(dependencyListener); } }); } };
public ListDiffEntry[] getDifferences() { if (differences == null) differences = Diffs.computeListDiff(oldList, getList()) .getDifferences(); return differences; } });
@Override protected void doUpdateList(List<E> source, ListDiff<E> diff) { diff.applyTo(source); }
private void updateList(List<E> list, ListDiff<E> diff) { if (!diff.isEmpty()) { boolean wasUpdating = updating; updating = true; try { property.updateList(source, diff); simplePropertyModCount++; } finally { updating = wasUpdating; } notifyIfChanged(null); } }
private void applyDiff(ListDiff<? extends E> diff, final List<E> list) { diff.accept(new ListDiffVisitor<E>() { @Override public void handleAdd(int index, E element) { list.add(index, element); } @Override public void handleRemove(int index, E element) { list.remove(index); } @Override public void handleReplace(int index, E oldElement, E newElement) { list.set(index, newElement); } }); }
public ListDiffEntry[] getDifferences() { if (lazyDiff == null) { lazyDiff = Diffs.computeListDiff(oldList, newList); } return lazyDiff.getDifferences(); } };
@SuppressWarnings("rawtypes") @Override protected void doSetList(Object source, List list, ListDiff diff) { List< ? > currentList = doGetList(source); diff.applyTo(currentList); }
private void updateList(List<E> list, ListDiff<E> diff) { if (!diff.isEmpty()) { boolean wasUpdating = updating; updating = true; try { property.updateList(source, diff); simplePropertyModCount++; } finally { updating = wasUpdating; } notifyIfChanged(null); } }
private void applyDiff(ListDiff diff, final List list) { diff.accept(new ListDiffVisitor() { @Override public void handleAdd(int index, Object element) { list.add(index, element); } @Override public void handleRemove(int index, Object element) { list.remove(index); } @Override public void handleReplace(int index, Object oldElement, Object newElement) { list.set(index, newElement); } }); }
/** * @see java.lang.Object#toString() */ public String toString() { ListDiffEntry[] differences = getDifferences(); StringBuffer buffer = new StringBuffer(); buffer.append(getClass().getName()); if (differences == null || differences.length == 0) { buffer.append("{}"); //$NON-NLS-1$ } else { buffer.append("{"); //$NON-NLS-1$ for (int i = 0; i < differences.length; i++) { if (i > 0) buffer.append(", "); //$NON-NLS-1$ buffer.append("difference[") //$NON-NLS-1$ .append(i).append("] [") //$NON-NLS-1$ .append( differences[i] != null ? differences[i] .toString() : "null") //$NON-NLS-1$ .append("]"); //$NON-NLS-1$ } buffer.append("}"); //$NON-NLS-1$ } return buffer.toString(); } }
@SuppressWarnings("rawtypes") @Override protected void doSetList(Object source, List list, ListDiff diff) { List< ? > currentList = doGetList(source); diff.applyTo(currentList); }
private void notifyIfChanged(ListDiff<E> diff) { if (hasListeners()) { List<E> oldList = cachedList; List<E> newList = cachedList = new ArrayList<E>(getList()); if (diff == null) diff = Diffs.computeListDiff(oldList, newList); if (!diff.isEmpty() || stale) { stale = false; fireListChange(diff); } } }
@Override public void handleListChange(ListChangeEvent event) { event.diff.accept(new ListDiffVisitor() { @Override public void handleAdd(int index, Object element) { IObservable dependency = (IObservable) element; dependency.addChangeListener(dependencyListener); dependency.addStaleListener(dependencyListener); } @Override public void handleRemove(int index, Object element) { IObservable dependency = (IObservable) element; dependency.removeChangeListener(dependencyListener); dependency.removeStaleListener(dependencyListener); } }); } };
private ListDiff offsetListDiff(int offset, ListDiff diff) { return Diffs.createListDiff(offsetListDiffEntries(offset, diff .getDifferences())); }