Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 268135

Summary: [Viewers] [CellEditors] Table with SWT.MULTI and TableViewerEditor problem
Product: [Eclipse Project] Platform Reporter: Alex Bernstein <alexberns>
Component: UIAssignee: Thomas Schindl <tom.schindl>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: agueda, alex.tugarev, bokowski, daniel_megert, galileo, jon.jekeli, klara.ward, Lars.Vogel, loskutov, magdalena+eclipse, marcus, marek.chodorowski, mistria, nicholas.karwath, niklas.deutschmann, oryandunn, pavanesh, pwebster, sptaszkiewicz, strider80, tom.schindl, zalapa
Version: 3.4   
Target Milestone: 4.8 M4   
Hardware: PC   
OS: Windows XP   
See Also: https://git.eclipse.org/r/104279
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=da427eaeb7c25a1a5f391c0d3fc043e91027b7d8
https://git.eclipse.org/r/110983
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=679a28a9a149a4a5985121f848cc95b50069f39a
Whiteboard:
Attachments:
Description Flags
API to control the background of unselected cells
none
Test snippet
none
FocusCellHighlighter that can handle multiselection and keyboard navigation (HACK!)
none
patch v0.1 none

Description Alex Bernstein CLA 2009-03-11 11:34:06 EDT
Build ID: 3.4

Steps To Reproduce:
1. Create Table and TableViewer with couple of columns. Use SWT.MULTI|SWT.H_SCROLL|SWT.V_SCROLL|SWT.FLAT|SWT.FULL_SELECTION flags.

2. Add CellModifiers for each column.

3. Add this code to add cell focus support and enable keyboard navigation:
TableViewer tv = (TableViewer) viewer;
		ColumnViewerEditorActivationStrategy cveas = new ReqActivationStrategy(tv);
		CellNavigationStrategy cns = new CellNavigationStrategy();
		TableViewerFocusCellManager tvfcm = new TableViewerFocusCellManager( tv, new FocusCellOwnerDrawHighlighter( tv ));
		TableViewerEditor.create(tv, tvfcm, cveas, ColumnViewerEditor.TABBING_HORIZONTAL|ColumnViewerEditor.KEYBOARD_ACTIVATION );

where ReqActivationStrategy is

protected class ReqActivationStrategy extends ColumnViewerEditorActivationStrategy
	{
		public ReqActivationStrategy(ColumnViewer viewer) {
			super(viewer);
		}
		@Override
		protected boolean isEditorActivationEvent( ColumnViewerEditorActivationEvent event) {
			if( super.isEditorActivationEvent(event))
				return true;
			if( event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED )
			{
				return event.keyCode == '\r'; 
			}
			return false;
		}
	};



More information:
Problem:
--------

Table stops support multi-select. Selecting multiple rows is impossible.
Comment 1 Paul Webster CLA 2009-03-11 11:39:05 EDT
Is this a regression in 3.4 w.r.t. the table viewer and cell editors?

PW
Comment 2 Alex Bernstein CLA 2009-03-11 11:44:36 EDT
I don't know; this is new functionality we are putting in now.
Comment 3 Paul Webster CLA 2009-03-11 11:47:40 EDT
Adding Tom for his knowledge of Cell Editors.

PW
Comment 4 Alex Bernstein CLA 2009-03-11 12:06:27 EDT
I don't know; this is new functionality we are putting in now.
Comment 5 Alex Bernstein CLA 2009-03-11 12:07:44 EDT
Is there a combination of class types/arguments/flags that should/should not be used and I am overlooking? I have not found any references to this behavior in the javadoc.
Comment 6 Thomas Schindl CLA 2009-03-11 14:21:22 EDT
Well the thing you are seeing is that the visual selection information is removed from the control by the FocusCellOwnerDrawHighlighter.

If you query the underlying control (getSelection()) you'll notice that the selection is still there. It boils down to the fact that you'll have to write your own FocusCellOwnerDrawHighlighter which is not removing the selection information but marks the focus cell differently.

The problem we are having with this keyboard navigation stuff is how keyboard navigation works in a multi-selection mode (what happens if the focus-cell is moving to a row which is not selected, ....) we are not facing in single selection. 

The bug requesting this feature is bug #206692. At least we should fix the JavaDoc as suggested there describing the current situation.
Comment 7 Alex Bernstein CLA 2009-03-11 14:59:25 EDT
Well, I 'd say that cell focus moving out of the selected rows area is by itself fine. It is the modifyCell event that should (maybe) clear the selected rows. Or maybe not. I see no problem in having several rows highlighted as well as some cell highlighted too, especially if cell focus can draw focus rectangle around selected cell (and/or use different background color). There are some operations in the table (and tree) that are applicable to the selection of rows (one or more) and then there are operations that are applicable to cells only. So having both things is fine.

Writing my own FocusCellOwnerDrawHighlighter does not look like a good idea; I would prefer that existing one to support both behaviors. This could ensure that every table and tree have similar look and feel. (Plus, looking at FocusCellOwnerDrawHighlighter source code, there are some calls to methods that are not visible if I wanted to write/replicate the existing behavior). People could overwrite getSelectedCell*Color methods to return some color to distinguish cells from rows, or maybe there would some default (non-null) colors for that.
Comment 8 Thomas Schindl CLA 2009-03-11 15:14:00 EDT
> Writing my own FocusCellOwnerDrawHighlighter does not look like a good idea; I
> would prefer that existing one to support both behaviors. This could ensure
> that every table and tree have similar look and feel. (Plus, looking at
> FocusCellOwnerDrawHighlighter source code, there are some calls to methods that
> are not visible if I wanted to write/replicate the existing behavior). People
> could overwrite getSelectedCell*Color methods to return some color to
> distinguish cells from rows, or maybe there would some default (non-null)
> colors for that.
> 

We could but this is M6 week and we are in API-freeze mode - we also can't simply modify the current behaviour because others might depend on the current one. I'll try to take look later or tomorrow my time how such a highlighter could look like. Boris, Paul?

Tom
Comment 9 Boris Bokowski CLA 2009-03-11 15:26:46 EDT
I don't think we should try to squeeze something in for M6. Stability is more important than feature completeness. We need to document that SWT.MULTI is not supported when you add cell navigation.
Comment 10 Alex Bernstein CLA 2009-03-11 15:50:08 EDT
Boris,
The multi-select is supported, it is just not visible.

Tom,
The default behavior can be as it is today. If there is a flag that flips this, I could use it to have a look-and-feel that I need (i.e. make selected rows visible).

Comment 11 Thomas Schindl CLA 2009-03-11 18:40:33 EDT
Created attachment 128469 [details]
API to control the background of unselected cells

Please note this is not the final solution because inconjunction with Keyboard navigation there are still problems. Boris I thinkl it would be save to include this as API in M6.
Comment 12 Thomas Schindl CLA 2009-03-11 18:42:24 EDT
Created attachment 128470 [details]
Test snippet
Comment 13 Thomas Schindl CLA 2009-03-11 19:11:15 EDT
Alex: I also took a look at the implementation. There's only one call to an protected method which and you could use reflection to call it.
Comment 14 Boris Bokowski CLA 2009-11-26 09:43:06 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 15 Ryan Dunn CLA 2010-11-04 12:58:49 EDT
It doesn't look like this change has been added to 3.5.  How about 3.6?  What's the best way to build a custom jface plugin that includes this change?  I'd like to have this feature for my RCP app.
Comment 16 Dominik Kaspar CLA 2011-06-08 11:06:40 EDT
Created attachment 197612 [details]
FocusCellHighlighter that can handle multiselection and keyboard navigation (HACK!)

I created my own FocusCellHighlighter that can handle multiselection and keyboard navigation. Maybe somebody can use it. ATTENTION: this is a hack, I needed to use reflection to access a protected method from the ColumnViewer.
Comment 17 Henno Vermeulen CLA 2011-12-29 09:51:36 EST
I was having the same issue. Thank you for your "hack", it seems to work fine. It also solves the issue I had that even with single selection, the selected line was not highlighted, at least not very clearly.
Comment 18 Paul Webster CLA 2012-01-03 14:05:46 EST
(In reply to comment #11)
> Created attachment 128469 [details]
> API to control the background of unselected cells
> 

Tom, is this still a viable solution for this problem?

PW
Comment 19 Thomas Schindl CLA 2012-01-04 09:36:08 EST
Well you know this is from nearly 3 years ago - the API looks save to me although not removing the selection at all as done in the FocusHighlighter (HACK!) is probably even better (we could control this using a style-constant or boolean)

Looking at the custom FocusCellHighlighter (HACK!) i think it can be rewritten to use real already existing API because one can fetch the ViewerRow using ColumnViewer#getCell(Point).getViewerRow() and the point can be extracted using TableItem#getBounds(int) - though the performance might not be 100% ok.

Maybe adding an API that allows one to retrieve the ViewerRow based on the Domain-Object though makes more sense so we could add an API like ColumnViewer#getViewerRow(Object).

I'll try to look into this next week - if no progress is made please ping the bug there are many things on my schedule and I can't spend any company time on this.
Comment 20 agueda martinez CLA 2012-01-31 15:02:44 EST
(In reply to comment #19)
> Well you know this is from nearly 3 years ago - the API looks save to me
> although not removing the selection at all as done in the FocusHighlighter
> (HACK!) is probably even better (we could control this using a style-constant
> or boolean)
> 
> Looking at the custom FocusCellHighlighter (HACK!) i think it can be rewritten
> to use real already existing API because one can fetch the ViewerRow using
> ColumnViewer#getCell(Point).getViewerRow() and the point can be extracted using
> TableItem#getBounds(int) - though the performance might not be 100% ok.
> 
> Maybe adding an API that allows one to retrieve the ViewerRow based on the
> Domain-Object though makes more sense so we could add an API like
> ColumnViewer#getViewerRow(Object).
> 
> I'll try to look into this next week - if no progress is made please ping the
> bug there are many things on my schedule and I can't spend any company time on
> this.

Hello Tom

Have you had the chance to continue the work on this bug?
Comment 21 Marek Chodorowski CLA 2012-02-16 02:22:02 EST
Created attachment 211087 [details]
patch v0.1

I think the patch created by Dominik can be implemented without reflection now. The current API allows to access getViewerRowFromItem() method. Could you please check if this patch is working for you?
Comment 22 Galileo Perez CLA 2012-02-23 09:14:12 EST
Patch v0.1 looks ok
Comment 23 Marek Chodorowski CLA 2012-03-30 11:29:25 EDT
Is there any update on this?
Comment 24 Jonathan Jekeli CLA 2012-11-02 12:47:36 EDT
Any ideas on when this patch will be implemented in the API?
Comment 25 Klara Ward CLA 2016-09-06 09:20:37 EDT
Any news on this? Having the same problem.
Comment 26 Andrey Loskutov CLA 2016-09-06 09:29:45 EDT
(In reply to Klara Ward from comment #25)
> Any news on this? Having the same problem.

It would be useful if someone who is interested in the fix, will provide a Gerrit review based on patch from comment 21.
Comment 27 Marcus Hirt CLA 2017-08-23 09:46:24 EDT
Does Klara need to be an Eclipse committer to review this?
Comment 28 Klara Ward CLA 2017-08-23 10:02:52 EDT
(In reply to Marcus Hirt from comment #27)
> Does Klara need to be an Eclipse committer to review this?

From what I understand, a committer needs to create a Gerrit review?
Comment 29 Marcus Hirt CLA 2017-08-23 13:46:39 EDT
You should have the approval to sign the ECA in you mailbox. :)
Comment 30 Klara Ward CLA 2017-09-04 08:34:08 EDT
My ECA is approved. 
Looking into creating a Gerrit review.
Comment 31 Klara Ward CLA 2017-09-04 08:34:26 EDT
My ECA is approved. 
Looking into creating a Gerrit review.
Comment 32 Klara Ward CLA 2017-09-04 11:25:02 EDT
Gerrit review at: https://git.eclipse.org/r/#/c/104279/
(Had thought it would be automatically added to this bug)
Comment 33 Thomas Schindl CLA 2017-09-04 11:26:17 EDT
(In reply to Klara Ward from comment #32)
> Gerrit review at: https://git.eclipse.org/r/#/c/104279/
> (Had thought it would be automatically added to this bug)

Only if you would have written "Bug" ;-)
Comment 34 Thomas Schindl CLA 2017-09-05 07:17:50 EDT
I'll try to get to this end of the week - please ping the bug if nothing has happened until next week
Comment 35 Klara Ward CLA 2017-09-05 10:33:30 EDT
(In reply to Thomas Schindl from comment #33)
> (In reply to Klara Ward from comment #32)
> > Gerrit review at: https://git.eclipse.org/r/#/c/104279/
> > (Had thought it would be automatically added to this bug)
> 
> Only if you would have written "Bug" ;-)

I tried to amend that, but not sure it helped :)
Comment 36 Klara Ward CLA 2017-09-05 10:33:43 EDT
(In reply to Thomas Schindl from comment #33)
> (In reply to Klara Ward from comment #32)
> > Gerrit review at: https://git.eclipse.org/r/#/c/104279/
> > (Had thought it would be automatically added to this bug)
> 
> Only if you would have written "Bug" ;-)

I tried to amend that, but not sure it helped :)
Comment 37 Klara Ward CLA 2017-09-05 10:34:52 EDT
(In reply to Thomas Schindl from comment #34)
> I'll try to get to this end of the week - please ping the bug if nothing has
> happened until next week

Thanks.
I tried to add a test, but it proved quite difficult, the color does not change after programmatic selection, or maybe I messed up.
Should there also be a new snippet?
Comment 38 Mickael Istria CLA 2017-09-07 02:46:59 EDT
(In reply to Klara Ward from comment #37)
> I tried to add a test, but it proved quite difficult, the color does not
> change after programmatic selection, or maybe I messed up.

Did you try to create and send an SWT event to mimic a user action and trigger all listeners?
Comment 39 Klara Ward CLA 2017-09-08 08:07:03 EDT
(In reply to Mickael Istria from comment #38)
> (In reply to Klara Ward from comment #37)
> > I tried to add a test, but it proved quite difficult, the color does not
> > change after programmatic selection, or maybe I messed up.
> 
> Did you try to create and send an SWT event to mimic a user action and
> trigger all listeners?

Nope, did not try that. Will make an attempt.
I found no other tests that change a selection and check the color, but maybe they are in other projects than eclipse.platform.ui?
Comment 41 Dani Megert CLA 2017-11-03 07:23:06 EDT
You probably didn't install the API baseline and hence did not see the error about the missing @since tag on the new API. Please fix this.
Comment 42 Klara Ward CLA 2017-11-03 11:13:25 EDT
What should the since version be?
Comment 43 Dani Megert CLA 2017-11-03 12:01:22 EDT
(In reply to Klara Ward from comment #42)
> What should the since version be?

As said before, you should set the API Baseline. Out of the box you should have an error on the project saying that you have to do that. Once you set it, it will give you the error about the missing @since tag and also offer a Quick Fix to add the correct tag.
Comment 44 Eclipse Genie CLA 2017-11-03 12:51:15 EDT
New Gerrit change created: https://git.eclipse.org/r/110983
Comment 46 Lars Vogel CLA 2017-11-03 12:56:17 EDT
(In reply to Klara Ward from comment #42)
> What should the since version be?

Klara, here is some documentation about the API baseline. If you need more info, please let me know, I'm happy to extend the description. 

http://www.vogella.com/tutorials/EclipsePlatformDevelopment/article.html#configure-api-baseline
Comment 47 Dani Megert CLA 2017-11-03 12:57:24 EDT
(In reply to Lars Vogel from comment #46)
> (In reply to Klara Ward from comment #42)
> > What should the since version be?
> 
> Klara, here is some documentation about the API baseline. If you need more
> info, please let me know, I'm happy to extend the description. 
> 
> http://www.vogella.com/tutorials/EclipsePlatformDevelopment/article.html#configure-api-baseline
> 

Why do you reopen the fixed bug?
Comment 48 Thomas Schindl CLA 2017-11-03 17:57:55 EDT
Sorry my fault - but I thought that OOMPH correctly setup the complete eclipse with a base-line.
Comment 49 Klara Ward CLA 2017-11-06 09:48:39 EST
I must have failed that Oomph step somehow. Will make a new attempt.

Thanks Andrey for fixing.
Comment 50 Thomas Schindl CLA 2017-11-06 09:53:34 EST
I don't think you failed a step because i tested your patch in a oomph workspace and did not see an error