Details
-
Bug
-
Resolution: Fixed
-
P4
-
8u20
-
Windows 8.1 (64bit), JDK 8u20-b15 (64bit)
Description
This confused me when manually tracking changes to a table's selectedItems via a ListChangeListener. Steps to reproduce:
1. Run the below example.
2. CTRL select the second item in the table so both items are selected.
3. Select _just_ the second item in the table.
https://gist.github.com/ryanjaeb/390351632a2d0c3814d9
You'll get the following output:
--- initial selection on program start ---
Change event...
Change:
Added: name one
--- caused by additionally selecting the second item ---
Change event...
Change:
Added: name two
--- caused by selecting _just_ the second item ---
Change event...
Change:
Removed: name one
Removed: name two
Added: name two
I use logic similar to the processListChange method of my example to add and remove items from another list. Since the "name two" item is removed and added at the same time, I need to make sure I check for that case rather than being able to replay the adds / removes to my other list.
Put another way, the order of handling the added items and removed items for the Change becomes important; the removed items need to be handled first or there's no way to tell if an item was already in the manually managed list or if it was just added as part of the Change.
If an item is both added and removed, should it actually be included in the Change? If it has to be included, would it make more sense to have it split into two separate Changes where it's removed in the first and added in the second?
1. Run the below example.
2. CTRL select the second item in the table so both items are selected.
3. Select _just_ the second item in the table.
https://gist.github.com/ryanjaeb/390351632a2d0c3814d9
You'll get the following output:
--- initial selection on program start ---
Change event...
Change:
Added: name one
--- caused by additionally selecting the second item ---
Change event...
Change:
Added: name two
--- caused by selecting _just_ the second item ---
Change event...
Change:
Removed: name one
Removed: name two
Added: name two
I use logic similar to the processListChange method of my example to add and remove items from another list. Since the "name two" item is removed and added at the same time, I need to make sure I check for that case rather than being able to replay the adds / removes to my other list.
Put another way, the order of handling the added items and removed items for the Change becomes important; the removed items need to be handled first or there's no way to tell if an item was already in the manually managed list or if it was just added as part of the Change.
If an item is both added and removed, should it actually be included in the Change? If it has to be included, would it make more sense to have it split into two separate Changes where it's removed in the first and added in the second?