javafx.collections.ObservableSet Java Examples
The following examples show how to use
javafx.collections.ObservableSet.
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: SetExpressionHelperEx.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * Removes the given {@link ChangeListener} from this * {@link SetChangeListener}. If it was registered more than once, removes * only one occurrence. * * @param listener * The {@link ChangeListener} to remove. */ public void removeListener( ChangeListener<? super ObservableSet<E>> listener) { // 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 (lockChangeListeners) { changeListeners = new ArrayList<>(changeListeners); } // 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()); remove() may thus not be // used. for (Iterator<ChangeListener<? super ObservableSet<E>>> iterator = changeListeners .iterator(); iterator.hasNext();) { if (iterator.next().equals(listener)) { iterator.remove(); break; } } if (changeListeners.isEmpty()) { changeListeners = null; } }
Example #2
Source File: Subscription.java From ReactFX with BSD 2-Clause "Simplified" License | 6 votes |
/** * Dynamically subscribes to all elements of the given observable set. * When an element is added to the set, it is automatically subscribed to. * When an element is removed from the set, it is automatically unsubscribed * from. * @param elems observable set of elements that will be subscribed to * @param f function to subscribe to an element of the set. * @return An aggregate subscription that tracks elementary subscriptions. * When the returned subscription is unsubscribed, all elementary * subscriptions are unsubscribed as well, and no new elementary * subscriptions will be created. */ static <T> Subscription dynamic( ObservableSet<T> elems, Function<? super T, ? extends Subscription> f) { Map<T, Subscription> elemSubs = new HashMap<>(); elems.forEach(t -> elemSubs.put(t, f.apply(t))); Subscription setSub = EventStreams.changesOf(elems).subscribe(ch -> { if(ch.wasRemoved()) { Subscription sub = elemSubs.remove(ch.getElementRemoved()); assert sub != null; sub.unsubscribe(); } if(ch.wasAdded()) { T elem = ch.getElementAdded(); assert !elemSubs.containsKey(elem); elemSubs.put(elem, f.apply(elem)); } }); return () -> { setSub.unsubscribe(); elemSubs.forEach((t, sub) -> sub.unsubscribe()); }; }
Example #3
Source File: SetPropertyExTests.java From gef with Eclipse Public License 2.0 | 6 votes |
@Test public void changeListenerRegistrationAndDeregistration() { SetProperty<Integer> property = propertyProvider.get(); // register listener ChangeExpector<Integer> changeListener = null; changeListener = new ChangeExpector<>(property); property.addListener(changeListener); // add second listener (and remove again) ChangeExpector<Integer> changeListener2 = null; changeListener2 = new ChangeExpector<>(property); property.addListener(changeListener2); property.removeListener(changeListener2); ObservableSet<Integer> newValue = FXCollections .observableSet(new HashSet<Integer>()); changeListener.addExpectation(property.get(), newValue); newValue.add(1); property.set(newValue); changeListener.check(); }
Example #4
Source File: XPathAutocompleteProvider.java From pmd-designer with BSD 2-Clause "Simplified" License | 6 votes |
/** Gets the index of the currently focused item. */ private int getFocusIdx() { if (!autoCompletePopup.isShowing()) { return -1; } List<ObservableSet<PseudoClass>> collect = autoCompletePopup.getItems() .stream() .map(this::getStyleableNode) .filter(Objects::nonNull) .map(Node::getPseudoClassStates) .collect(Collectors.toList()); for (int i = 0; i < collect.size(); i++) { if (collect.get(i).contains(PseudoClass.getPseudoClass("focused"))) { return i; } } return -1; }
Example #5
Source File: SetExpressionHelperEx.java From gef with Eclipse Public License 2.0 | 6 votes |
private void notifyListeners(ObservableSet<E> oldValue, ObservableSet<E> currentValue) { if (currentValue != oldValue) { notifyInvalidationListeners(); if (changeListeners != null) { try { lockChangeListeners = true; for (ChangeListener<? super ObservableSet<E>> l : changeListeners) { l.changed(observableValue, oldValue, currentValue); } } finally { lockChangeListeners = false; } } if (oldValue == null || !oldValue.equals(currentValue)) { notifySetListeners(oldValue, currentValue); } } }
Example #6
Source File: SimpleSetPropertyEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void removeListener( ChangeListener<? super ObservableSet<E>> listener) { if (helper != null) { helper.removeListener(listener); } }
Example #7
Source File: SetExpressionHelperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Adds a new {@link ChangeListener} to this {@link SetExpressionHelperEx}. * 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(ChangeListener<? super ObservableSet<E>> listener) { if (changeListeners == null) { changeListeners = 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 (lockChangeListeners) { changeListeners = new ArrayList<>(changeListeners); } changeListeners.add(listener); }
Example #8
Source File: ReadOnlySetPropertyBaseEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void removeListener( ChangeListener<? super ObservableSet<E>> listener) { if (helper != null) { helper.removeListener(listener); } }
Example #9
Source File: ReadOnlySetPropertyBaseEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void addListener(ChangeListener<? super ObservableSet<E>> listener) { if (helper == null) { helper = new SetExpressionHelperEx<>(this); } helper.addListener(listener); }
Example #10
Source File: ReadOnlySetWrapperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void removeListener( ChangeListener<? super ObservableSet<E>> listener) { if (helper != null) { helper.removeListener(listener); } }
Example #11
Source File: ReadOnlySetWrapperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void addListener(ChangeListener<? super ObservableSet<E>> listener) { if (helper == null) { helper = new SetExpressionHelperEx<>(this); } helper.addListener(listener); }
Example #12
Source File: ReadOnlySetWrapperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void removeListener( ChangeListener<? super ObservableSet<E>> listener) { if (helper != null) { helper.removeListener(listener); } }
Example #13
Source File: BindingUtils.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Creates a new {@link ObjectBinding} that contains the values mapped to * the specified key. * * @param setMultimap * The {@link ObservableSetMultimap} from which the values are to * be retrieved. * @param <K> * The key type of the {@link ObservableSetMultimap}. * @param <V> * The value type of the {@link ObservableSetMultimap}. * * * @param key * the key of the mapping * @return A new {@code ObjectBinding}. */ public static <K, V> SetBinding<V> valuesAt( final ObservableSetMultimap<K, V> setMultimap, final K key) { if (setMultimap == null) { throw new UnsupportedOperationException( "setMultimap may not be null."); } return new SetBinding<V>() { { super.bind(setMultimap); } @Override protected ObservableSet<V> computeValue() { return FXCollections.observableSet(setMultimap.get(key)); } @Override public void dispose() { super.unbind(setMultimap); } @Override public ObservableList<?> getDependencies() { return FXCollections.singletonObservableList(setMultimap); } }; }
Example #14
Source File: ReadOnlySetWrapperEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void addListener( ChangeListener<? super ObservableSet<E>> listener) { if (helper == null) { helper = new SetExpressionHelperEx<>(this); } helper.addListener(listener); }
Example #15
Source File: SimpleSetPropertyEx.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void addListener(ChangeListener<? super ObservableSet<E>> listener) { if (helper == null) { helper = new SetExpressionHelperEx<>(this); } helper.addListener(listener); }
Example #16
Source File: BindingUtils.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Creates a new {@link ObjectBinding} that contains the values mapped to * the specified key. * * @param <K> * The key type of the {@link ObservableSetMultimap}. * @param <V> * The value type of the {@link ObservableSetMultimap}. * * @param setMultimap * The {@link ObservableSetMultimap} from which the values are to * be retrieved. * @param key * the key of the mapping * @return A new {@code ObjectBinding}. */ public static <K, V> SetBinding<V> valuesAt( final ObservableSetMultimap<K, V> setMultimap, final ObservableValue<K> key) { if (setMultimap == null) { throw new UnsupportedOperationException( "setMultimap may not be null."); } if (key == null) { throw new UnsupportedOperationException("key may not be null"); } return new SetBinding<V>() { { super.bind(setMultimap); } @Override protected ObservableSet<V> computeValue() { return FXCollections .observableSet(setMultimap.get(key.getValue())); } @Override public void dispose() { super.unbind(setMultimap); } @Override public ObservableList<?> getDependencies() { return FXCollections.unmodifiableObservableList( FXCollections.observableArrayList(setMultimap, key)); } }; }
Example #17
Source File: SetPropertyExTests.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public void changed( ObservableValue<? extends ObservableSet<E>> observable, ObservableSet<E> oldValue, ObservableSet<E> newValue) { if (oldValueQueue.size() <= 0) { fail("Received unexpected change."); } assertEquals(source, observable); assertEquals(oldValueQueue.pollLast(), oldValue); assertEquals(newValueQueue.pollLast(), newValue); }
Example #18
Source File: EventStreams.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
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 #19
Source File: EventStreams.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
/** * Returns an event stream that emits all the events emitted from any of * the event streams in the given observable set. When an event stream is * added to the set, the returned stream will start emitting its events. * When an event stream is removed from the set, its events will no longer * be emitted from the returned stream. */ public static <T> EventStream<T> merge( ObservableSet<? extends EventStream<T>> set) { return new EventStreamBase<T>() { @Override protected Subscription observeInputs() { return Subscription.dynamic(set, s -> s.subscribe(this::emit)); } }; }
Example #20
Source File: EventStreams.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
/** * A more general version of {@link #merge(ObservableSet)} for a set of * arbitrary element type and a function to obtain an event stream from * the element. * @param set observable set of elements * @param f function to obtain an event stream from an element */ public static <T, U> EventStream<U> merge( ObservableSet<? extends T> set, Function<? super T, ? extends EventStream<U>> f) { return new EventStreamBase<U>() { @Override protected Subscription observeInputs() { return Subscription.dynamic( set, t -> f.apply(t).subscribe(this::emit)); } }; }
Example #21
Source File: SetPropertyExTests.java From gef with Eclipse Public License 2.0 | 5 votes |
public void addExpectation(ObservableSet<E> oldValue, ObservableSet<E> newValue) { // We check that the reference to the observable value is correct, // thus do not copy the passed in values. oldValueQueue.addFirst(oldValue); newValueQueue.addFirst(newValue); }
Example #22
Source File: SelectionHandler.java From LogFX with GNU General Public License v3.0 | 4 votes |
ObservableSet<SelectableNode> getSelectedItems() { return selectionManager.getSelectedItems(); }
Example #23
Source File: User.java From bisq-core with GNU Affero General Public License v3.0 | 4 votes |
public ObservableSet<PaymentAccount> getPaymentAccountsAsObservable() { return paymentAccountsAsObservable; }
Example #24
Source File: SetPropertyExTests.java From gef with Eclipse Public License 2.0 | 4 votes |
public SetChangeExpector(ObservableSet<E> source) { this.source = source; }
Example #25
Source File: Modpack.java From SmartModInserter with GNU Lesser General Public License v3.0 | 4 votes |
public ObservableSet<ModReference> getMods() { return mods; }
Example #26
Source File: Datastore.java From SmartModInserter with GNU Lesser General Public License v3.0 | 4 votes |
public ObservableSet<Modpack> getModpacks() { return modpacks; }
Example #27
Source File: SessionModel.java From VocabHunter with Apache License 2.0 | 4 votes |
public ObservableSet<WordModel> getSelectedWords() { return selectedWords; }
Example #28
Source File: ThreadElement.java From jstackfx with Apache License 2.0 | 4 votes |
public ObservableSet<ThreadReference> getHoldingLocks() { return holdingLocks.get(); }
Example #29
Source File: SelectionHandler.java From LogFX with GNU General Public License v3.0 | 4 votes |
ObservableSet<SelectableNode> getSelectedItems() { return selectedItems; }
Example #30
Source File: Config.java From LogFX with GNU General Public License v3.0 | 4 votes |
public ObservableSet<File> getObservableFiles() { return properties.observableFiles; }