Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Can't indent tree column of TreeLayer
Can't indent tree column of TreeLayer [message #911963] Wed, 12 September 2012 16:56 Go to next message
Tom Hochstein is currently offline Tom Hochstein
Messages: 12
Registered: July 2009
Junior Member
I prefer my left-aligned cells to have a bit of margin to match the default SWT table look-and-feel. It doesn't appear that I can do this with TreeLayer without copying the whole implementation.
Re: Can't indent tree column of TreeLayer [message #912251 is a reply to message #911963] Thu, 13 September 2012 07:45 Go to previous messageGo to next message
Dirk Fauth is currently online Dirk Fauth
Messages: 1267
Registered: July 2012
Senior Member
You are right that this is something that isn't addressed correctly at the moment.

But there is a workaround where you don't have to override the whole implementation. Extend TreeLayer and override getCellPainter() like this:

@Override
public ICellPainter getCellPainter(int columnPosition, int rowPosition, ILayerCell cell, IConfigRegistry configRegistry) {
	ICellPainter cellPainter = super.getCellPainter(columnPosition, rowPosition, cell, configRegistry);
		
	if (columnPosition == TREE_COLUMN_NUMBER) {
		cellPainter = new BackgroundPainter(new PaddingDecorator(
			new CellPainterDecorator(cellPainter, CellEdgeEnum.LEFT, indentedTreeImagePainter),
			0, 0, 0, 5));
	}
		
	return cellPainter;
}


To explain on that:
On rendering the NatTable asks its layers for the cell painter to use. Ususally this is the painter configured via NatTable configuration or specialized configuration by labels. In the special case of TreeLayer, the underlying painter is wrapped to be decorated with the tree image for expand/collapse. If you want to add padding, you have to wrap the created painter with a PaddingDecorator like shown above.

This is surely some part we have to look at when looking at the configuration of TreeLayer in general.

Hopefully my workaround solves your issue for the moment.

Greez,
Dirk
Re: Can't indent tree column of TreeLayer [message #912437 is a reply to message #912251] Thu, 13 September 2012 15:32 Go to previous messageGo to next message
Tom Hochstein is currently offline Tom Hochstein
Messages: 12
Registered: July 2009
Junior Member
Thanks, Dirk. One problem with your suggestion is that indentedTreeImagePainter is private.

In the meantime, I've moved off of the mainline to version 2.3.2 from sourceforge.

Is it good enough to override getCellPainter() with a simple PaddingDecorator() wrap? Seems to be working.

@Override
public ICellPainter getCellPainter(int columnPosition, int rowPosition,
        LayerCell cell, IConfigRegistry configRegistry) {
    ICellPainter cellPainter = super.getCellPainter(columnPosition,
            rowPosition, cell, configRegistry);
    if (columnPosition == TREE_COLUMN_NUMBER) {
        cellPainter = new PaddingDecorator(cellPainter, 0, 0, 0, 5);
    }
    return cellPainter;
}


Tom
Re: Can't indent tree column of TreeLayer [message #912443 is a reply to message #912437] Thu, 13 September 2012 15:40 Go to previous messageGo to next message
Dirk Fauth is currently online Dirk Fauth
Messages: 1267
Registered: July 2012
Senior Member
Ah ok, this is indeed a problem.

I wouldn't suggest to move back to 2.3.2 on SourceForge. There are a lot of bugfixes and improvements in the current head. And we are planning to do an official 0.9 release at the end of this month. So if this is a bug that can't be worked around, feel free to open a bug in bugzilla, so it can be fixed before release.

I'm not quite sure if the background rendering is processed correctly with your proposed solution. But if you don't configure different background color for your tree column, this shouldn't be an issue for you.
Re: Can't indent tree column of TreeLayer [message #912447 is a reply to message #912443] Thu, 13 September 2012 15:45 Go to previous message
Tom Hochstein is currently offline Tom Hochstein
Messages: 12
Registered: July 2009
Junior Member
Thanks. I will indeed move back to head.
Previous Topic:Tree node text doesn't use full cell width
Next Topic:GlazedLists & EMF
Goto Forum:
  


Current Time: Wed Sep 03 07:03:05 GMT 2014

Powered by FUDForum. Page generated in 0.22851 seconds