Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 282534 - addSelectionListener(...) for table, list, tree and tree table
Summary: addSelectionListener(...) for table, list, tree and tree table
Status: RESOLVED FIXED
Alias: None
Product: Riena
Classification: RT
Component: ridget (show other bugs)
Version: 1.2.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.2.0.M1   Edit
Assignee: Elias Volanakis CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-06 11:12 EDT by Nataliya Sinkevych CLA
Modified: 2011-05-19 07:06 EDT (History)
1 user (show)

See Also:


Attachments
addSelectionListener (36.16 KB, patch)
2009-07-06 11:12 EDT, Nataliya Sinkevych CLA
no flags Details | Diff
Comment #4 - idea (b) (34.69 KB, patch)
2009-07-06 20:59 EDT, Elias Volanakis CLA
no flags Details | Diff
the updated tests (33.90 KB, patch)
2009-07-08 03:55 EDT, Nataliya Sinkevych CLA
elias: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nataliya Sinkevych CLA 2009-07-06 11:12:31 EDT
Created attachment 140874 [details]
addSelectionListener

It should be possible to register the SelectionListener on the following ridgets: TableRidget, ListRidget, TreeRidget, TreeTableRidget
 
Example:
...
tableRidget.addSelectionListener(new ISelectionListener() {

	public void ridgetSelected(SelectionEvent e) {
		System.out.println("SelectionEvent: " + e);			
	}
Comment 1 Christian Campo CLA 2009-07-06 11:22:17 EDT
Elias, can you please validate this patch....
thanks
christian
Comment 2 Nataliya Sinkevych CLA 2009-07-06 11:35:38 EDT
Elias, I've noticed that the old selection of the multiple selection (in MultiSelectionObservable) contains exactly one item less than the new selection. If I select item1 and item2 together, I see that the new selection contains item1 and item2 and the old selection contains item1. I expected in this case the old selection containing no items. May you have a look at this and say if this is a problem or the expected behaviour?

Thanks,
Nataliya 
Comment 3 Elias Volanakis CLA 2009-07-06 19:28:25 EDT
Nataliya,

thanks for your comment. I could reproduce the selection behavior and it does not seem right to me. I'll look at this in more detail.

After modifying the TableSubModule{View/Controller} to accept multiple selection:
- when having 1 item selected and selecting 4 items, the event contains: old:3, new:4
SelectionEvent[source=org.eclipse.riena.internal.ui.ridgets.swt.TableRidget@13cae7, oldSelection=[Adventure, Acclimatisation, Aardwark], newSelection=[Adventure, Acclimatisation, Aardwark, Binoculars]]
- when having 4 items selected and selecting 1 item, the event contains: old:2, new:1
SelectionEvent[source=org.eclipse.riena.internal.ui.ridgets.swt.TableRidget@13cae7, oldSelection=[Adventure, Acclimatisation], newSelection=[Adventure]]

Kind regards,
Elias.
Comment 4 Elias Volanakis CLA 2009-07-06 20:56:28 EDT
The problem is in the way the old selection is computed for multiple selection. Basically the JFace databinding will invoke MultiSelectionObservable.fireListChange() once for each added or removed element in the selection. The result is that oldSelectionList, as computed in the patch, contains the only the very last change.

Nataliya, just curious: are you primarily interested in (a) the SWT selection event or  (b) the change of the selection value?

If it is (b) this could be done relatively easy by adding a property change listener:

  public void addSelectionListener(ISelectionListener selectionListener) {
		Assert.isNotNull(selectionListener, "selectionListener is null"); //$NON-NLS-1$
		if (selectionListeners == null) {
			selectionListeners = new ListenerList<ISelectionListener>(ISelectionListener.class);
			addPropertyChangeListener(ISelectableRidget.PROPERTY_SELECTION, new PropertyChangeListener() {
				public void propertyChange(PropertyChangeEvent evt) {
					notifySelectionListeners((List<?>) evt.getOldValue(), (List<?>) evt.getNewValue());
				}
			});
		}
		selectionListeners.add(selectionListener);
	}

The 'downside' of this is that it fires an event for each change, i.e. if 'a' is selected and now 'a,b,c,d' is selected it will fire: 'a' -> 'a,b', 'a,b' -> 'a,b,c', 'a,b,c,' -> 'a,b,c,d'. The 'upside' is that is also sends a notication when the selected item is deleted, and it avoids sending a notification when the same item is selected (I believe both of these cases are an issue with the attached patch).

If it is (a) I have to think a bit more about how to do this.
Comment 5 Elias Volanakis CLA 2009-07-06 20:59:34 EDT
Created attachment 140920 [details]
Comment #4 - idea (b)

Patch showing comment #4, idea b. Note that tests are broken at the moment (not updated).
Comment 6 Nataliya Sinkevych CLA 2009-07-08 03:55:40 EDT
Created attachment 141053 [details]
the updated tests

Elias, I've updated the tests. Thanks for the support. 

Kind regards,
Nataliya
Comment 7 Elias Volanakis CLA 2009-07-08 14:47:11 EDT
The patch is good to go; marking with iplog+

Christian, Nataliya, before I can commit I need confirmation that:

- Compeople has a Member Committer Agreement
- Nataliya is a compeople employee
- Patch contains no cryptography
- Patch was developed from scratch
- Patch is 100% EPL

Please leave a reply in bugzilla that all of the above is correct.

Comment 8 Christian Campo CLA 2009-07-08 14:58:57 EDT
all of the items you mention are correct

good to go
Comment 9 Elias Volanakis CLA 2009-07-08 15:03:27 EDT
Committed -- Thanks Nataliya!