JDK-8258777 : SkinBase: add api to un-/register invalidation-/listChange listeners
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: controls
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-12-21
  • Updated: 2021-05-14
  • Resolved: 2021-04-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
openjfx17Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Description
.. just the same as done for changeListeners:

    /**
     * Subclasses can invoke this method to register that they want to listen to
     * invalidation events for the given property. Registered {@link Consumer} instances
     * will be executed in the order in which they are registered.
     * @param property the property
     * @param consumer the consumer
     */
    protected final void registerInvalidationListener(ObservableValue<?> property, Consumer<ObservableValue<?>> consumer) {
 
    /**
     * Unregisters all invalidation listeners that have been registered using {@link #registerInvalidationListener(ObservableValue, Consumer)}
     * for the given property. The end result is that the given property is no longer observed by any of the invalidation
     * listeners, but it may still have additional listeners registered on it through means outside of
     * {@link #registerInvalidationListener(ObservableValue, Consumer)}.
     *
     * @param property The property for which all listeners should be removed.
     * @return A single chained {@link Consumer} consisting of all {@link Consumer consumers} registered through
     *      {@link #registerInvalidationListener(ObservableValue, Consumer)}. If no consumers have been registered on this
     *      property, null will be returned.
     * @since 9
     */
    protected final Consumer<ObservableValue<?>> unregisterInvalidationListeners(ObservableValue<?> property) {

Internally, this boils down to adding api to LambdaMultiplePropertyChangeListenerHandler (though doing so will make the name a bit .. inappropriate), probably simply duplicating the existing xxChangeYY to xxInvalidationYY and including both in its dispose.

Why?

There are skins (f.i. TextFieldSkin, see JDK-8240506) that rely heavily on manually registered InvalidationListeners - each of which must be removed manually in dispose. With enhanced skin api, those could be registered via the multipleProp listener and automatically removed in dispose.

Comments
Changeset: cc70cdf1 Author: Jeanette Winzenburg <fastegal@openjdk.org> Date: 2021-04-28 11:40:07 +0000 URL: https://git.openjdk.java.net/jfx/commit/cc70cdf19f0069cd485571231f89cf5939c7602f
28-04-2021

might be worth going a step further and add similar api to un/register listChangeListeners, for getting an idea of its effect (in usage), see https://gist.github.com/kleopatra/fcce1e40c48e84b37f62631df348be90 It contains three (dummy) SkinBase implementations for handling a list-valued property (of a dummy control) - SkinBaseObservableListFullSupport: support all invalidation/listChangeListeners - SkinBaseObservableListInvalidationSupport: support invalidationListeners - SkinBaseObservableListNoSupport: no support aside: changeListener support (current api) is not helpful for list-valued properties Advantages of full support: - no manual listeners stored in the skin - automatic disposal
25-01-2021