Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » MouseOver, MouseOut listeners for Tablecells possible?
MouseOver, MouseOut listeners for Tablecells possible? [message #986475] Tue, 20 November 2012 15:20 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Is it possible to have MouseOver, MouseOut listeners for Tablecells or for ButtonCellPainters?
Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986481 is a reply to message #986475] Tue, 20 November 2012 15:39 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Currently not. I came across this too recently, and this is related to some missing or wrong event handlings. We need to refactor event handling of SWT events and NatTable events to make this possible. This is a future task, which is not targeted yet.

If you find a suitable solution without a lot of refactoring, feel free to contribute.

Greez,
Dirk
Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986498 is a reply to message #986481] Tue, 20 November 2012 16:21 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Hey Dirk - how about this thread? http://sourceforge.net/projects/nattable/forums/forum/744994/topic/5238652

MouseMove seem to be available in NatTable.
Do you know, what the right way is, to subscribe for mouse events, to know which object the mouse is currently moving above?
Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986501 is a reply to message #986498] Tue, 20 November 2012 16:34 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Indeed, I completely forgot about that thread. Without digging too deep right now, you can register a mouse listener to the NatTable itself. As NatTable is a Canvas, you can register it directly. You can then get the event in your listener and translate the position to NatTable cell coordinates. As far as I can see, this is what was done in the topic you referred.

There is a NatTableContentTooltip in core where you can have a look how to translate the coordinate to the corresponding cell.
Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986515 is a reply to message #986501] Tue, 20 November 2012 17:39 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Thnx Dirk!
I managed to get the cell/row which the mouse is hovering on, by the following code:
RowHeaderLayerStack rowHeaderLayer;
	ColumnHeaderLayerStack columnHeaderLayer;
	
	
	public void addListener(final NatTable natTable){
		MouseMoveListener mlistener = new MouseMoveListener() {
			
			@Override
			public void mouseMove(MouseEvent event) {
				int x = event.x;
				int y = event.y;
				System.out.println("x "+x+" y "+y);
				
				int col = natTable.getColumnPositionByX(event.x) - rowHeaderLayer.getColumnCount();
				int row = natTable.getRowPositionByY(event.y) - columnHeaderLayer.getRowCount(); 
				
				if(col>=0 && row >=0){
					System.out.println("col "+col + "row "+row);
				}
			}
		};


Two more questions:


  • how do I repaint the cell, when I changed something in it? E.g. if I change the cell renderer state?
  • and more important: can I navigate more precisely, than on table-cell level? Means can I find out, which object I am point on inside the cell? E.g. which cell-decorator is responsible for the current area?

Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986605 is a reply to message #986515] Wed, 21 November 2012 07:52 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi Alex,

glad to hear you found a solution. Although IMHO this is more a workaround and should be integrated into NatTable. Wink Nevertheless, it works!

In NatTable we have the concept of commands and events. To keep it short, if you want to repaint only a cell if something has changed, you should fire a CellVisualChangeEvent. But you need to know that events are propagated the layer stack upwards. So to inform all layers about the change, you'll need to fire the event on the lowest layer (mostly the DataLayer is a good choice).

I'm not quite sure what you mean by "navigate more precisely, than on table-cell level". You can get the ILayerCell by calling this:
ILayerCell cell = natTable.getCellByPosition(col, row);

Having the ILayerCell you are able to get a lot of information. The ILayerCell comes with some information on the cell itself. There are also some helper classes to extract information associated with the cell. Note that you always need the current ConfigRegistry instance to do this
//get the foreground style information for a cell
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);

//get the cell painter used to render a cell
ICellPainter cellPainter = cell.getLayer().getCellPainter(cell.getColumnPosition(), cell.getRowPosition(), cell, configRegistry);

These code fragments are used within the NatTable framework itself. But I'm not sure why you would need this. Setting these values programmatically shouldn't work I guess. The concept for styling and all other configurations is label based. I haven't tried that yet, and possibly this doesn't work because of the current concept on interpreting the layer stack, but maybe you could temporarily add a special label to the label stack of the ILayerCell to change the rendering on mouse over.

Greez,
Dirk
Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986623 is a reply to message #986605] Wed, 21 November 2012 09:00 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
No Message Body

[Updated on: Wed, 21 November 2012 09:02]

Report message to a moderator

Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986625 is a reply to message #986605] Wed, 21 November 2012 09:00 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
No Message Body

[Updated on: Wed, 21 November 2012 09:02]

Report message to a moderator

Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986627 is a reply to message #986625] Wed, 21 November 2012 09:03 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Thnx again Dirk!
By "navigate more precisely, than on table-cell level" i mean the following usecase:

- I would render some Links inside my cells.
- Additionally I would render some further widgets inside cells.

Now I need to differntiate not only which cell was currently clicked,
but what which widget inside the Shell was clicked.

Is somehow supported by NatTable?
Re: MouseOver, MouseOut listeners for Tablecells possible? [message #986637 is a reply to message #986627] Wed, 21 November 2012 09:33 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I have to admit that I'm not sure if this is supported. NatTable is custom painted, so I wonder how it would be possible to render further widgets into the NatTable cells. On the other hand, we are doing this with the editors in some kind of way. So the only suggestion I can make at this point is to direct you to the sources of the NatTable editors. There you can have a look on how rendering, activation and so on is handled. Currently NatTable uses a singleton concept for the current active editor. Which works fine for most cases, but also has some downsites.
Previous Topic:NatTable does not fit to empty space
Next Topic:How can I set the summary row on a fixed position (below the body)?
Goto Forum:
  


Current Time: Sat Apr 20 03:02:10 GMT 2024

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

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

Back to the top