-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8294809: ListenerHelper for managing and disconnecting listeners #908
8294809: ListenerHelper for managing and disconnecting listeners #908
Conversation
👋 Welcome back angorya! A progress list of the required criteria for merging this PR into |
Webrevs
|
Mailing list message from John Hendrikx on openjfx-dev: Hi Andy, There is another PR that will help with this: It adds a `when` method on `ObservableValue`: ????? default ObservableValue<T> when(ObservableValue<Boolean> condition) This method can be used for all kinds of things, and one of them is that It would work like this: ? ? ObservableValue<Boolean> active = new SimpleBooleanProperty(true); ? ? MySkin() { ? ? void dispose() { Also, it's possible to extend (and later expose) the It has these methods, but more can be added: ???? Subscription subscribe(ObservableValue<T> observableValue, ?? ? Subscription subscribeInvalidations(ObservableValue<?> It could be used like this to manage subscriptions: ???? Subscription subscription = Subscriptions can be chained: ???? Subscription subscription = They can then be released all at once by doing: ???? subscription.unsubscribe(); Reading your proposal I see you might be looking to support weak Perhaps we can collaborate on this.? Nir Lisker also has interests in I added some more comments inline. --John On 12/10/2022 23:05, Andy Goryachev wrote:
`Subscription` has some of these, and the `when` proposal would not need
Both `Subscription` and the `when` proposal could do this. `Subcription`
Yes, `Subscription#unsubscribe` or for `when` by toggling the boolean
I suppose that could be a signature like: ????? Subscription#subscribeInvalidations(Runnable runnable,
I'm guessing you mean for invalidation listeners, as for change
`Subscription` has this. |
Mailing list message from Nir Lisker on openjfx-dev: Hi, I agree with John. The work on managing listeners has been in the works for Listeners are deeply ingrained in JavaFX. This work is not done in a The history can be traced back through this (broken) thread: On Thu, Oct 13, 2022 at 9:40 AM John Hendrikx <john.hendrikx at gmail.com>
-------------- next part -------------- |
Thank you @nlisker and @hjohn for providing the link and explanations. You are right, ListenerHelper is somewhat similar to Subscription in that it allows for quick disconnect(). It is, however, designed for a different purpose, that goes beyond what is needed from a simple listener management. Specifically,
to summarize, I see some minor overlap between Subscription and ListenerHelper, but mostly these are two different beasts designed for two different purposes. I do agree with the call to cooperate! Would love to. what do you think? |
You have a very good point here, considering the purpose of this class. Let me see if support for weak listeners should be removed. Thank you! |
Support for weak listeners cannot be removed, for example in a situation when Control gets removed from the scene graph and therefore becomes eligible for collection. |
they don't need to be exposed, will convert them to edit: already |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks ready to go in. I left a few minor comments and questions, but I am approving it as is.
modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/ListenerHelper.java
Show resolved
Hide resolved
modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/ListenerHelper.java
Outdated
Show resolved
Hide resolved
modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/ListenerHelper.java
Show resolved
Hide resolved
modules/javafx.controls/src/test/java/test/javafx/scene/control/TestListenerHelper.java
Show resolved
Hide resolved
modules/javafx.controls/src/test/java/test/javafx/scene/control/TestListenerHelper.java
Show resolved
Hide resolved
@andy-goryachev-oracle This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 2 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@kevinrushforth, @aghaisas) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/IDisconnectable.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK, although I left another comment on the (now less so) redundant test.
modules/javafx.controls/src/test/java/test/javafx/scene/control/TestListenerHelper.java
Show resolved
Hide resolved
/integrate |
@andy-goryachev-oracle This pull request has not yet been marked as ready for integration. |
oh no, all the approvals have been invalidated... |
/integrate |
@andy-goryachev-oracle |
/sponsor |
Going to push as commit 3376228.
Your commit was automatically rebased without conflicts. |
@kevinrushforth @andy-goryachev-oracle Pushed as commit 3376228. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
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:
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.
Where It Will Be Useful
JDK-8294589 "MenuBarSkin: memory leak when changing skin"
and other skins, as a replacement for LambdaMultiplePropertyChangeListenerHandler.
#908
#914
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx pull/908/head:pull/908
$ git checkout pull/908
Update a local copy of the PR:
$ git checkout pull/908
$ git pull https://git.openjdk.org/jfx pull/908/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 908
View PR using the GUI difftool:
$ git pr show -t 908
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/908.diff