Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8294809

ListenerHelper for managing and disconnecting listeners

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx20
    • None
    • javafx
    • b10

      Introduction

      There is a number of places where various listeners (strong as well as weak) are added, to be later disconnected in one go. For example, Skin implementations use dispose() method to clean up the listeners installed in the corresponding Control (sometimes using LambdaMultiplePropertyChangeListenerHandler class).

      This pattern is also used by app developers, but there is no public utility class to do that, so every one must invent their own, see for instance
      https://github.com/andy-goryachev/FxTextEditor/blob/master/src/goryachev/fx/FxDisconnector.java

      Proposal

      It might be beneficial to create a class (ListenerHelper, feel free to suggest a better name) which:

      - provides convenient methods like addChangeListener, addInvalidationListener, addWeakChangeListener, etc.
      - keeps track of the listeners and the corresponding ObservableValues
      - provides a single disconnect() method to remove all the listeners in one go.
      - optionally, it should be possible to add a lambda (Runnable) to a group of properties
      - optionally, there should be a boolean flag to fire the lambda immediately
      - strongly suggest implementing an IDisconnectable functional interface with a single disconnect() method

      Make it Public Later

      Initially, I think we could place the new class in package com.sun.javafx.scene.control; to be made publicly accessible later.

            angorya Andy Goryachev
            angorya Andy Goryachev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: