Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » How to get row/column index based on position at CompositeLayer
How to get row/column index based on position at CompositeLayer [message #1186039] Thu, 14 November 2013 12:39 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I have a NatTable as a layer. Its underlying layer is a CompositeLayer with a column header layer and a body layer (ViewportLayer -> SelectionLayer -> ColumnHideShowLayer -> DataLayer).

Is it possible to get body layer row index from row position defined on the whole NatTable?
Re: How to get row/column index based on position at CompositeLayer [message #1186056 is a reply to message #1186039] Thu, 14 November 2013 12:53 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
http://www.eclipse.org/forums/index.php/t/489312/
Re: How to get row/column index based on position at CompositeLayer [message #1186068 is a reply to message #1186056] Thu, 14 November 2013 13:01 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Awesome. I didn't found that myself Embarrassed
Re: How to get row/column index based on position at CompositeLayer [message #1186173 is a reply to message #1186068] Thu, 14 November 2013 14:27 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, it's not working as I would expect.

Let's say the column header has 2 rows. Then, when I call
LayerUtil.convertRowPosition(compositeLayer, 0, bodyDataLayer);
LayerUtil.convertRowPosition(compositeLayer, 1, bodyDataLayer);
LayerUtil.convertRowPosition(compositeLayer, 2, bodyDataLayer);
LayerUtil.convertRowPosition(compositeLayer, 3, bodyDataLayer);

it returns 0, 0, 0, 1. That's confusing since I can't determine when the row position is really part of the bodyDataLayer.
I would expect -1, -1, 0, 1. Or am I missing the point here?
Re: How to get row/column index based on position at CompositeLayer [message #1186180 is a reply to message #1186173] Thu, 14 November 2013 14:33 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Would need to dig into that in more detail. Maybe CompositeLayer.localToUnderlyingRowPosition() is more appropriate in case of CompositeLayers.
Re: How to get row/column index based on position at CompositeLayer [message #1186186 is a reply to message #1186180] Thu, 14 November 2013 14:39 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
That doesn't help much
layer.localToUnderlyingRowPosition(0)
layer.localToUnderlyingRowPosition(1)
layer.localToUnderlyingRowPosition(2)
layer.localToUnderlyingRowPosition(3)
layer.localToUnderlyingRowPosition(3)

returns 0, 1, 0, 1, 2. It's correct, but I can't determine which layer the result belongs to.
Re: How to get row/column index based on position at CompositeLayer [message #1186201 is a reply to message #1186186] Thu, 14 November 2013 14:50 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Not sure then, if you look at the action bindings you will notice that there the transformations are done accordingly. The commands usually carry the position information which is transfered on their way down the layer stack.

I'm currently stuck with other issues, but you should be able to debug and follow the way of a command e.g. selection. The command initally receives the x,y coordinates which are transfered into NatTable coordinates. In a grid you have the similar situation as the GridLayer is a CompositeLayer. There the transformation needs to be hidden in some way.
Re: How to get row/column index based on position at CompositeLayer [message #1186243 is a reply to message #1186201] Thu, 14 November 2013 15:24 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Commands convert their position within AbstractPositionCommand#convertToTargetLayer(ILayer targetLayer) using the LayerCommandUtil class.
If I understand the code correctly, The LayerCommandUtil goes recursively through the layer stack to find the appropriate target position.

So when I use this code
LayerCommandUtil.convertRowPositionToTargetContext(new RowPositionCoordinate(compositeLayer, 0), bodyDataLayer);
LayerCommandUtil.convertRowPositionToTargetContext(new RowPositionCoordinate(compositeLayer, 1), bodyDataLayer);
LayerCommandUtil.convertRowPositionToTargetContext(new RowPositionCoordinate(compositeLayer, 2), bodyDataLayer);
LayerCommandUtil.convertRowPositionToTargetContext(new RowPositionCoordinate(compositeLayer, 3), bodyDataLayer);

it returns null, null, 0, 1. That's what I would expect. IMHO, this could be moved to the LayerUtil class.
Re: How to get row/column index based on position at CompositeLayer [message #1186260 is a reply to message #1186243] Thu, 14 November 2013 15:39 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Thanks for investigating on this and finding the LayerCommandUtil helper class. Seems this is what you are searching for.

Quote:
IMHO, this could be moved to the LayerUtil class.


As the methods are static helper methods we could of course think about moving them to one big LayerUtil class. But I don't want to change too much of already working code and API in the current architecture. I'm not sure how many people are using it already in some code. But I should consider that information to be documented somewhere.

BTW: why do you need the information?
Re: How to get row/column index based on position at CompositeLayer [message #1186273 is a reply to message #1186260] Thu, 14 November 2013 15:49 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I use export to XSL. Some rows has a check box where I can select/unselect it to say whether they should be exported.
I had to create my own NatExporter class where I filter those rows.

BTW do you think it's a good idea to catch the FileNotFoundException in FileOutputStreamProvider#getOutputStream()?

When a user try to export to an opened file, nothing happens and the user could think that export was successful.
I have to check log file to see that the export fail because of java.io.FileNotFoundException.

[Updated on: Thu, 14 November 2013 15:57]

Report message to a moderator

Re: How to get row/column index based on position at CompositeLayer [message #1186732 is a reply to message #1186273] Thu, 14 November 2013 21:23 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
BTW do you think it's a good idea to catch the FileNotFoundException in FileOutputStreamProvider#getOutputStream()?


Well do you think it is a good idea to throw an exception in framework code that can not be handled in user code?
Re: How to get row/column index based on position at CompositeLayer [message #1186849 is a reply to message #1186732] Thu, 14 November 2013 22:43 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hmm I've never written a framework yet. But why not? If you throw a runtime exception, then:

1. I can catch it in a higher level and tell the user that the file is opened and should be closed before export
2. Even if I don't catch it because it's a runtime exception, the Eclipse itself has an error handler AFAIK
3. Every application should catch unchecked exceptions in the most high place and respond to it appropriately (at least log it).

This way I'm not able to detect something is going wrong until I check out the log file. Many users usually don't know about log files at all.
Re: How to get row/column index based on position at CompositeLayer [message #1186888 is a reply to message #1186849] Thu, 14 November 2013 23:09 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
NatTable comes with bindings that directly execute actions. Users may not be aware of them nor would they be able to catch the exception as they don't know where to catch.

NatTable is a SWT control, so it is not necessary that a Eclipse platform is running to deal with the exception.

I agree that there might be possibilities to deal with it in another way, e.g. Showing an error dialog ourself, or fire the exception and deal with it at another place in code. These are usual discussions in Java programming.

In the current architecture I don't want to change things too much. But for the next generation architecture we can consider these things appropriately.
Re: How to get row/column index based on position at CompositeLayer [message #1187797 is a reply to message #1186888] Fri, 15 November 2013 09:33 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Sure, I didn't mean that as a complaint.
Re: How to get row/column index based on position at CompositeLayer [message #1187838 is a reply to message #1187797] Fri, 15 November 2013 09:58 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Didn't understood it as a complaint. Smile

The discussion on exception handling is one of the most common in the Java world. The problem here is that with the current architecture, people might not be aware that a RuntimeException could occur. Now somebody presses Ctrl+E while having a NatTable instance focused, and then the application crashes because of the exception. As the developer wasn't aware, there is software that breaks. And still the developer wouldn't know how to catch, as his architecture is possibly not able to catch at higher levels.

I agree that it is not the perfect solution, but for now I don't have another idea that doesn't possibly break running applications.

But shouldn't it be possible for you to simply create your own FileOutputStreamProvider or extend the existing, and throw the exception instead of catching it? It seems you would need to copy a lot of code, but this way you should be able to implement it the way it fits your needs.

P.S. feel free to introduce your ideas, they might become valuable with the new architecture were we want to get rid of such architectural issues
Previous Topic:Select a cell programmatically
Next Topic:Sorting with different row heights
Goto Forum:
  


Current Time: Fri Mar 29 14:36:33 GMT 2024

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

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

Back to the top