javafx.collections.SetChangeListener Java Examples

The following examples show how to use javafx.collections.SetChangeListener. 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: 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 #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: ModpackTabController.java    From SmartModInserter with GNU Lesser General Public License v3.0 6 votes vote down vote up
private TreeItem<Object> getModpackTreeItem(Modpack modpack) {
    TreeItem<Object> item = new TreeItem<>(modpack);
    for (ModReference mod : modpack.getMods()) {
        item.getChildren().add(getModTreeItem(mod));
    }
    modpack.getMods().addListener((SetChangeListener<ModReference>) change -> {
        if (change.wasAdded()) {
            Platform.runLater(() -> item.getChildren().add(getModTreeItem(change.getElementAdded())));
        } else if (change.wasRemoved()) {
            Platform.runLater(() -> {
                item.getChildren().stream().filter(item2 -> item2.getValue() == change.getElementRemoved()).findAny().ifPresent(item3 -> item.getChildren().remove(item3));
            });
        }
    });
    return item;
}
 
Example #4
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 #5
Source File: SetListenerHelperEx.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Notifies the attached {@link SetChangeListener}s about the related
 * change.
 *
 * @param change
 *            The applied change.
 */
protected void notifySetChangeListeners(Change<? extends E> change) {
	if (setChangeListeners != null) {
		try {
			lockSetChangeListeners = true;
			for (SetChangeListener<? super E> l : setChangeListeners) {
				try {
					l.onChanged(change);
				} catch (Exception e) {
					Thread.currentThread().getUncaughtExceptionHandler()
							.uncaughtException(Thread.currentThread(), e);
				}
			}
		} finally {
			lockSetChangeListeners = false;
		}
	}
}
 
Example #6
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 #7
Source File: User.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void readPersisted() {
    UserPayload persisted = storage.initAndGetPersistedWithFileName("UserPayload", 100);
    userPayload = persisted != null ? persisted : new UserPayload();

    checkNotNull(userPayload.getPaymentAccounts(), "userPayload.getPaymentAccounts() must not be null");
    checkNotNull(userPayload.getAcceptedLanguageLocaleCodes(), "userPayload.getAcceptedLanguageLocaleCodes() must not be null");
    paymentAccountsAsObservable = FXCollections.observableSet(userPayload.getPaymentAccounts());
    currentPaymentAccountProperty = new SimpleObjectProperty<>(userPayload.getCurrentPaymentAccount());
    userPayload.setAccountId(String.valueOf(Math.abs(keyRing.getPubKeyRing().hashCode())));

    // language setup
    if (!userPayload.getAcceptedLanguageLocaleCodes().contains(LanguageUtil.getDefaultLanguageLocaleAsCode()))
        userPayload.getAcceptedLanguageLocaleCodes().add(LanguageUtil.getDefaultLanguageLocaleAsCode());
    String english = LanguageUtil.getEnglishLanguageLocaleCode();
    if (!userPayload.getAcceptedLanguageLocaleCodes().contains(english))
        userPayload.getAcceptedLanguageLocaleCodes().add(english);

    paymentAccountsAsObservable.addListener((SetChangeListener<PaymentAccount>) change -> {
        userPayload.setPaymentAccounts(new HashSet<>(paymentAccountsAsObservable));
        persist();
    });
    currentPaymentAccountProperty.addListener((ov) -> {
        userPayload.setCurrentPaymentAccount(currentPaymentAccountProperty.get());
        persist();
    });
}
 
Example #8
Source File: BisqSetup.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private void maybeShowSecurityRecommendation() {
    String key = "remindPasswordAndBackup";
    user.getPaymentAccountsAsObservable().addListener((SetChangeListener<PaymentAccount>) change -> {
        if (!walletsManager.areWalletsEncrypted() && !user.isPaymentAccountImport() && preferences.showAgain(key) && change.wasAdded() &&
                displaySecurityRecommendationHandler != null)
            displaySecurityRecommendationHandler.accept(key);
    });
}
 
Example #9
Source File: AssetService.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public void onAllServicesInitialized() {
    tradeStatsByTickerSymbol = getTradeStatsByTickerSymbol();
    tradeStatisticsManager.getObservableTradeStatisticsSet().addListener((SetChangeListener<TradeStatistics2>) change -> {
        // At startup if a user has downloaded the app long after the release he might receive a lots of trade statistic
        // objects from the seed node. We don't want to trigger the expensive getTradeStatsByTickerSymbol call in
        // between so we delay 20 sec. to be sure to call it after the data has been processed.
        // To use a listener would be better but that requires bigger effort at the p2p lib side.
        if (timer == null)
            timer = UserThread.runAfter(() -> {
                tradeStatsByTickerSymbol = getTradeStatsByTickerSymbol();
                updateList();
                timer = null;
            }, 20);
    });
}
 
Example #10
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 #11
Source File: SetListenerHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Removes the given {@link SetChangeListener} from this
 * {@link SetListenerHelperEx}. If its was registered more than once,
 * removes one occurrence.
 *
 * @param listener
 *            The listener to remove.
 */
public void removeListener(SetChangeListener<? super E> listener) {
	if (setChangeListeners == null) {
		return;
	}

	// XXX: Prevent ConcurrentModificationExceptions (in case listeners are
	// added during notifications); as we only create a new multi-set in the
	// locked case, memory should not be waisted.
	if (lockSetChangeListeners) {
		setChangeListeners = new ArrayList<>(setChangeListeners);
	}
	// XXX: We have to ignore the hash code when removing listeners, as
	// otherwise unbinding will be broken (JavaFX bindings violate the
	// contract between equals() and hashCode(): JI-9028554); remove() may
	// thus not be used.
	for (Iterator<SetChangeListener<? super E>> iterator = setChangeListeners
			.iterator(); iterator.hasNext();) {
		if (iterator.next().equals(listener)) {
			iterator.remove();
			break;
		}
	}
	if (setChangeListeners.isEmpty()) {
		setChangeListeners = null;
	}
}
 
Example #12
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 #13
Source File: SetListenerHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds a new {@link SetChangeListener} to this {@link SetListenerHelperEx}.
 * If the same listener is added more than once, it will be registered more
 * than once and will receive multiple change events.
 *
 * @param listener
 *            The listener to add.
 */
public void addListener(SetChangeListener<? super E> listener) {
	if (setChangeListeners == null) {
		setChangeListeners = new ArrayList<>();
	}
	// XXX: Prevent ConcurrentModificationExceptions (in case listeners are
	// added during notifications); as we only create a new multi-set in the
	// locked case, memory should not be waisted.
	if (lockSetChangeListeners) {
		setChangeListeners = new ArrayList<>(setChangeListeners);
	}
	setChangeListeners.add(listener);
}
 
Example #14
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 #15
Source File: BisqSetup.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
private void maybeShowSecurityRecommendation() {
    String key = "remindPasswordAndBackup";
    user.getPaymentAccountsAsObservable().addListener((SetChangeListener<PaymentAccount>) change -> {
        if (!walletsManager.areWalletsEncrypted() && preferences.showAgain(key) && change.wasAdded() &&
                displaySecurityRecommendationHandler != null)
            displaySecurityRecommendationHandler.accept(key);
    });
}
 
Example #16
Source File: User.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void readPersisted() {
    UserPayload persisted = storage.initAndGetPersistedWithFileName("UserPayload", 100);
    userPayload = persisted != null ? persisted : new UserPayload();

    checkNotNull(userPayload.getPaymentAccounts(), "userPayload.getPaymentAccounts() must not be null");
    checkNotNull(userPayload.getAcceptedLanguageLocaleCodes(), "userPayload.getAcceptedLanguageLocaleCodes() must not be null");
    paymentAccountsAsObservable = FXCollections.observableSet(userPayload.getPaymentAccounts());
    currentPaymentAccountProperty = new SimpleObjectProperty<>(userPayload.getCurrentPaymentAccount());
    userPayload.setAccountId(String.valueOf(Math.abs(keyRing.getPubKeyRing().hashCode())));

    // language setup
    if (!userPayload.getAcceptedLanguageLocaleCodes().contains(LanguageUtil.getDefaultLanguageLocaleAsCode()))
        userPayload.getAcceptedLanguageLocaleCodes().add(LanguageUtil.getDefaultLanguageLocaleAsCode());
    String english = LanguageUtil.getEnglishLanguageLocaleCode();
    if (!userPayload.getAcceptedLanguageLocaleCodes().contains(english))
        userPayload.getAcceptedLanguageLocaleCodes().add(english);

    paymentAccountsAsObservable.addListener((SetChangeListener<PaymentAccount>) change -> {
        userPayload.setPaymentAccounts(new HashSet<>(paymentAccountsAsObservable));
        persist();
    });
    currentPaymentAccountProperty.addListener((ov) -> {
        userPayload.setCurrentPaymentAccount(currentPaymentAccountProperty.get());
        persist();
    });
}
 
Example #17
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 #18
Source File: SimpleSetPropertyEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(SetChangeListener<? super E> listener) {
	if (helper == null) {
		helper = new SetExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #19
Source File: ReadOnlySetWrapperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(SetChangeListener<? super E> listener) {
	if (helper == null) {
		helper = new SetExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #20
Source File: ReadOnlySetWrapperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(SetChangeListener<? super E> listener) {
	if (helper == null) {
		helper = new SetExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #21
Source File: ReadOnlySetPropertyBaseEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(SetChangeListener<? super E> listener) {
	if (helper == null) {
		helper = new SetExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #22
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 #23
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 #24
Source File: ReadOnlySetWrapperEx.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void removeListener(SetChangeListener<? super E> listener) {
	if (helper != null) {
		helper.removeListener(listener);
	}
}
 
Example #25
Source File: SimpleSetPropertyEx.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void removeListener(SetChangeListener<? super E> listener) {
	if (helper != null) {
		helper.removeListener(listener);
	}
}
 
Example #26
Source File: ReadOnlySetWrapperEx.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void removeListener(SetChangeListener<? super E> listener) {
	if (helper != null) {
		helper.removeListener(listener);
	}
}
 
Example #27
Source File: SubscribeableContentsObsSet.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Helper method for adding a change listener that can be removed by calling
 * {@link Subscription#unsubscribe() unsubscribe} on the returned {@link Subscription}.
 */
public Subscription addChangeListener(SetChangeListener<? super E> listener) {
    addListener(listener);
    return () -> removeListener(listener);
}
 
Example #28
Source File: SubscribeableContentsObsSet.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void addListener(SetChangeListener<? super E> listener) {
    changeListeners.add(listener);
}
 
Example #29
Source File: SubscribeableContentsObsSet.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void removeListener(SetChangeListener<? super E> listener) {
    changeListeners.remove(listener);
}
 
Example #30
Source File: ReadOnlySetPropertyBaseEx.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void removeListener(SetChangeListener<? super E> listener) {
	if (helper != null) {
		helper.removeListener(listener);
	}
}