RFR: 8294809: ListenerHelper for managing and disconnecting listeners [v9]

Andy Goryachev angorya at openjdk.org
Mon Nov 14 20:18:30 UTC 2022


On Mon, 14 Nov 2022 10:20:59 GMT, Ajit Ghaisas <aghaisas at openjdk.org> wrote:

>> Andy Goryachev has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 24 additional commits since the last revision:
>> 
>>  - 8294809: review comments
>>  - Merge remote-tracking branch 'origin/master' into 8294809.listener.helper
>>  - 8294809: whitespace
>>  - 8294809: no public api
>>  - 8294809: map change listener
>>  - Merge remote-tracking branch 'origin/master' into 8294809.listener.helper
>>  - 8294809: generics
>>  - 8294809: is alive
>>  - Revert "8294809: removed weak listeners support"
>>    
>>    This reverts commit 2df4a85db638d76cacaf6c54ba669cdb3dd91a18.
>>  - 8294809: removed weak listeners support
>>  - ... and 14 more: https://git.openjdk.org/jfx/compare/a53372a1...470f42c1
>
> modules/javafx.controls/src/test/java/test/javafx/scene/control/TestListenerHelper.java line 94:
> 
>> 92: 
>> 93:     @Test
>> 94:     public void testChangeListener_MultipleProperties() {
> 
> Should we address a hypothetical use case where the `ListenerHelper` has added a ChangeListener for 2 properties as done in this test case and wants to remove only ChangeListener for p1?
> currently `h.disconnet()` removes ChangeListener of both the properties.

If this is a requirement, then multi-property method `addChangeListener(Runnable, ObservableValue ...)` should not be used.  Instead, use a normal `addChangeListener(ObservableValue, *)` and its return `IDisconnectable` to remove the listener.

An example use case for multi-property method is listening for both width and height properties to update a shape or recalculate an area.

-------------

PR: https://git.openjdk.org/jfx/pull/908


More information about the openjfx-dev mailing list