Java Code Examples for javafx.collections.SetChangeListener#Change

The following examples show how to use javafx.collections.SetChangeListener#Change . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeHidingBehavior.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void onHidingModelChange(SetChangeListener.Change<? extends org.eclipse.gef.graph.Node> change) {
	super.onHidingModelChange(change);

	Set<org.eclipse.gef.graph.Node> newHidden = new HashSet<>(change.getSet());
	Set<org.eclipse.gef.graph.Node> oldHidden = new HashSet<>(change.getSet());
	oldHidden.remove(change.getElementAdded());
	oldHidden.add(change.getElementRemoved());

	// check if we have to show/hide/update the pruned neighbors part
	org.eclipse.gef.graph.Node content = getHost().getContent();
	Set<org.eclipse.gef.graph.Node> neighbors = content.getNeighbors();

	if (!containsAny(oldHidden, neighbors) && containsAny(newHidden, neighbors)) {
		createHiddenNeighborsFeedbackPart();
	} else if (containsAny(oldHidden, neighbors) && !containsAny(newHidden, neighbors)) {
		removeHiddenNeighborsFeedbackPart();
	} else {
		// TODO: only necessary when neighbors change
		if (hiddenNeighborsFeedbackPart != null) {
			updateHiddenNeighborsFeedbackPart();
		}
	}
}
 
Example 2
Source File: SubscribeableContentsObsSet.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void fireElementAdded(E elem) {
    SetChangeListener.Change<E> change = new SetChangeListener.Change<E>(this) {
        @Override
        public boolean wasAdded() {
            return true;
        }

        @Override
        public boolean wasRemoved() {
            return false;
        }

        @Override
        public E getElementAdded() {
            return elem;
        }

        @Override
        public E getElementRemoved() {
            return null;
        }
    };
    changeListeners.forEach(l -> l.onChanged(change));
}
 
Example 3
Source File: SubscribeableContentsObsSet.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void fireElementRemoved(E elem) {
    SetChangeListener.Change<E> change = new SetChangeListener.Change<E>(this) {
        @Override
        public boolean wasAdded() {
            return false;
        }

        @Override
        public boolean wasRemoved() {
            return true;
        }

        @Override
        public E getElementAdded() {
            return null;
        }

        @Override
        public E getElementRemoved() {
            return elem;
        }
    };
    changeListeners.forEach(l -> l.onChanged(change));
}
 
Example 4
Source File: DynamicAnchor.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onChanged(
		final SetChangeListener.Change<? extends Parameter<?>> change) {
	if (change.wasRemoved()) {
		change.getElementRemoved().removeListener(valueChangeListener);
	}
	if (change.wasAdded()) {
		change.getElementAdded().addListener(valueChangeListener);
	}
	// if the list of anchorage parameters was changed, recompute
	// positions
	updatePositions();
}
 
Example 5
Source File: SetExpressionHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Fires notifications to all attached {@link InvalidationListener
 * InvalidationListeners}, and {@link SetChangeListener SetChangeListeners}.
 *
 * @param change
 *            The change that needs to be propagated.
 */
@Override
public void fireValueChangedEvent(
		SetChangeListener.Change<? extends E> change) {
	if (change != null) {
		notifyInvalidationListeners();
		// XXX: We do not notify change listeners here, as the identity of
		// the observed value did not change (see
		// https://bugs.openjdk.java.net/browse/JDK-8089169)
		notifySetChangeListeners(
				new AtomicChange<>(observableValue, change));
	}
}
 
Example 6
Source File: SetListenerHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Notifies all attached {@link InvalidationListener}s and
 * {@link SetChangeListener}s about the change.
 *
 * @param change
 *            The change to notify listeners about.
 */
public void fireValueChangedEvent(
		SetChangeListener.Change<? extends E> change) {
	notifyInvalidationListeners();
	if (change != null) {
		notifySetChangeListeners(change);
	}
}
 
Example 7
Source File: SetPropertyExTests.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onChanged(SetChangeListener.Change<? extends E> change) {
	if (addedElementQueue.size() <= 0) {
		fail("Received unexpected change " + change);
	}

	assertEquals(source, change.getSet());

	// check added element
	E expectedAddedElement = addedElementQueue.pollLast();
	assertEquals(expectedAddedElement, change.getElementAdded());
	if (expectedAddedElement != null) {
		assertTrue(change.wasAdded());
	} else {
		assertFalse(change.wasAdded());
	}

	// check removed values
	E expectedRemovedElement = removedElementQueue.pollLast();
	assertEquals(expectedRemovedElement, change.getElementRemoved());
	if (expectedRemovedElement != null) {
		assertTrue(change.wasRemoved());
	} else {
		assertFalse(change.wasRemoved());
	}

	// check string representation
	if (expectedRemovedElement != null) {
		assertEquals("Removed " + expectedRemovedElement + ".",
				change.toString());
	} else {
		assertEquals("Added " + expectedAddedElement + ".",
				change.toString());
	}
}
 
Example 8
Source File: EventStreams.java    From ReactFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <T> EventStream<SetChangeListener.Change<? extends T>> changesOf(ObservableSet<T> set) {
    return new EventStreamBase<SetChangeListener.Change<? extends T>>() {
        @Override
        protected Subscription observeInputs() {
            SetChangeListener<T> listener = c -> emit(c);
            set.addListener(listener);
            return () -> set.removeListener(listener);
        }
    };
}
 
Example 9
Source File: AbstractHidingBehavior.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void onChanged(SetChangeListener.Change<? extends org.eclipse.gef.graph.Node> change) {
	onHidingModelChange(change);
}
 
Example 10
Source File: GraphLayoutBehavior.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void onChanged(SetChangeListener.Change<? extends org.eclipse.gef.graph.Node> change) {
	applyLayout(true, null);
}
 
Example 11
Source File: SetListenerHelperEx.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link SetListenerHelperEx.AtomicChange} for the passed
 * in source, based on the data provided in the passed-in change.
 * <p>
 * This is basically used to allow properties wrapping an
 * {@link ObservableSet} to re-fire change events of their wrapped
 * {@link ObservableSet} with themselves as source.
 *
 * @param source
 *            The new source {@link ObservableSet}.
 * @param change
 *            The change to infer a new change from. It is expected that
 *            the change is in initial state. In either case it will be
 *            reset to initial state.
 */
public AtomicChange(ObservableSet<E> source,
		SetChangeListener.Change<? extends E> change) {
	super(source);

	this.addedElement = change.getElementAdded();
	this.removedElement = change.getElementRemoved();
}