Bug 570667 - Table.select does not notify listeners added via addSelectionListener
Summary: Table.select does not notify listeners added via addSelectionListener
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.18   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-26 09:33 EST by Ingo Mohr CLA
Modified: 2021-01-27 17:51 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ingo Mohr CLA 2021-01-26 09:33:36 EST
Hi folks,

I got this problem:

See the snippet:
https://github.com/ingomohr/eclipse-swt-table.select-doesnt-fire-listener/blob/main/swtbug-tableselection/src/TableDefaultSelectionListener.java

The listener should be notified whenever table.select is called.
However, it only gets fired up when I click a TableItem with the mouse.

Found this bug in Eclipse 2020-06 and in 2020-12 (didn't check 2020_09).
Comment 1 Thomas Wolf CLA 2021-01-26 11:28:20 EST
Not sure it's a bug, and not sure it can be changed. I see quite a lot of code in Eclipse platform that manipulates the SWT selection on a widget programmatically and the fires events explicitly, either on SWT or on JFace level.

Besides, IIRC this behavior has been like that for a long time.
Comment 2 Ingo Mohr CLA 2021-01-27 17:30:25 EST
Hi Thomas,

thanks for your feedback.

If this is no bug, then isn't this rather bad design?: "You can add a selection listener here - and depending on how the seleciton changes, this might or might not notify your listener."

>> "I see quite a lot of code in Eclipse platform that manipulates the SWT selection on a widget programmatically and the fires events explicitly, either on SWT or on JFace level."

To me, this is quite some bug-workaround stuff imho.

If select() has the problem of not fireing the added listeners, why can the select() impl not just notify the listeners itself?

I normally use the JFace TableViewer, and when I set a StructuredSelection programmatically, all SelectionChangedListeners get notified. So, the current behavior is also inconsistent with JFace - and also with general listener concepts: If I have an object that can have a selection and lets clients add selectionListeners, I would expect the listeners to be fired whenever (and how-ever) the selection changes. Wouldn't you?

Cheers
Ingo
Comment 3 Thomas Wolf CLA 2021-01-27 17:51:13 EST
I stumbled over this a few times in the past. I think the use case is to modify the selection several times programmatically on SWT level, then fire the event when done. For instance, one might want to deselect everything, then select rows 3 and 4 and 7 to 9, then possibly fire an event.

The javadoc of Table.addSelectionListener() says

  "...will be notified when the user changes the receiver's selection"
                            ^^^^^^^^

Seems consistent with the implemented behavior.