Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Row selection when right clicking row header(Position mismatch between clicked row and already selected rows)
Row selection when right clicking row header [message #1031936] Tue, 02 April 2013 11:39 Go to next message
Arye Shemesh is currently offline Arye ShemeshFriend
Messages: 17
Registered: November 2012
Junior Member
Hi,

I'm implementing row selection when right clicking the row header.

I'd like to keep the current selection if the row that was right clicked is already selected as part of multiple row selection.

My code looks like this:

uiBindingRegistry.registerMouseDownBinding(
	new MouseEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, MouseEventMatcher.RIGHT_BUTTON),

	new IMouseAction() {

		ViewportSelectRowAction selectRowAction = new ViewportSelectRowAction(false, false);
					
		@Override
		public void run(NatTable natTable, MouseEvent event) {

			SelectionLayer selectionLayer = ((BodyLayerStack)((GridLayer)natTable.getLayer()).getBodyLayer()).getSelectionLayer();
			int rowPosition = natTable.getRowPositionByY(event.y);

			if(!selectionLayer.isRowPositionSelected(rowPosition)) {
				selectRowAction.run(natTable, event);
			}					-
		}
	});




Sadly, it doesn't work well. When I select a range of rows and right click the header of one of them, the row position I get from the event does not match the row positions marked as selected in the selection layer (typically a shift of 1-2 positions). This leads to clearing the previous multiple row selection and selecting only the specific row that was right clicked.

I tried to get the row position by calling
selectionLayer.getRowPositionByY(event.y)
but it has the same problem.

Is it something I'm doing wrong? a bug?

Regards,
Arye
Re: Row selection when right clicking row header [message #1031953 is a reply to message #1031936] Tue, 02 April 2013 12:04 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1412
Registered: July 2012
Senior Member
Quote:
Is it something I'm doing wrong?

Yes

Quote:
a bug?

No

int rowPosition = natTable.getRowPositionByY(event.y);


This returns the row position in the table. If you have a grid that has a column header with one row, then the row position of the body (which you are requesting) is the row position in the NatTable +1 for the column header.

You need to transform the row position. This is always a good idea because of other layer transformations. Use the LayerUtil for position transformations:
int rowPosition = LayerUtil.convertRowPosition(natTable, natTable.getRowPositionByY(event.y), selectionLayer);


Hope that helps,
Dirk

Re: Row selection when right clicking row header [message #1031996 is a reply to message #1031953] Tue, 02 April 2013 13:00 Go to previous messageGo to next message
Arye Shemesh is currently offline Arye ShemeshFriend
Messages: 17
Registered: November 2012
Junior Member
Hi Dirk,

Thanks a lot for your quick and accurate reply. The issue is resolved using your code.

By the way, row selection when right clicking the row header is quite intuitive (as in excel). Don't you want to add this functionality (by default or as an option) to NatTable?

Thanks again,
Arye
Re: Row selection when right clicking row header [message #1032004 is a reply to message #1031996] Tue, 02 April 2013 13:08 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1412
Registered: July 2012
Senior Member
Quote:
row selection when right clicking the row header is quite intuitive (as in excel). Don't you want to add this functionality (by default or as an option) to NatTable?


Well, if I perform a right click on the row header in Excel, the header menu shows up. So I think your requirement is quite special and now explained how to add it to a NatTable. Smile
But I can have a look on how to add it to NatTable core when I look at the selection stuff.

Thanks for sharing your efforts with us.

Greez,
Dirk
Re: Row selection when right clicking row header [message #1032031 is a reply to message #1032004] Tue, 02 April 2013 13:41 Go to previous message
Arye Shemesh is currently offline Arye ShemeshFriend
Messages: 17
Registered: November 2012
Junior Member
Quote:
Well, if I perform a right click on the row header in Excel, the header menu shows up.



You're right of course. I extracted only the row selection code to simplify the post. My actual code also opens a menu (relies on HeaderMenuConfiguration logic).

Anyway, thanks again for your patience and dedication. It'll be an honor to contribute to NatTable.
Previous Topic:Find dialog improvements
Next Topic:Bug in assigning converters
Goto Forum:
  


Current Time: Fri Nov 28 16:13:37 GMT 2014

Powered by FUDForum. Page generated in 0.01654 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software