javaswtnattablenebula

How to configure indentation for non decorated items in a Nebula NatTable


I am trying to style a NatTable tree so that the indentation of non-decorated items matches that of decorated items. So items without children and items with children have the same indentation, basically.

The example that I am following using the following configuration:

public class PerfLogTreeConfiguration extends AbstractRegistryConfiguration {

private static final int fTreeIndent = 10;
private static final int fIconSpacing = 2;

private TreeImagePainter fTreeImagePainter = new TreeImagePainter(false,
        GUIHelper.getImage("right"), //$NON-NLS-1$
        GUIHelper.getImage("right_down"), null); //$NON-NLS-1$

private IndentedTreeImagePainter indentedTreeImagePainter = new IndentedTreeImagePainter(
        fTreeIndent,
        null,
        CellEdgeEnum.LEFT,
        fTreeImagePainter, 
        false,
        fIconSpacing,
        true);
private PaddingDecorator paddingDecorator = new PaddingDecorator(
        indentedTreeImagePainter,
        0,
        5,
        0,
        5, 
        true);
private ICellPainter fTreeStructurePainter = new BackgroundPainter(paddingDecorator);

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    configRegistry.registerConfigAttribute(TreeConfigAttributes.TREE_STRUCTURE_PAINTER, fTreeStructurePainter,
            DisplayMode.NORMAL);

}

A is the intended layour and B is what I am currently getting.


Solution

  • To achieve this you need to pass a leaf image to the TreeImagePainter

    TreeImagePainter fTreeImagePainter = new TreeImagePainter(false,
            GUIHelper.getImage("right"), //$NON-NLS-1$
            GUIHelper.getImage("right_down"), //$NON-NLS-1$
            GUIHelper.getImage("leaf")); //$NON-NLS-1$
    

    The provided leaf image is actually an empty image that is used as spacer. Using this also the children of expanded nodes will get an additional spacing. But that is needed to make it possible to differentiate between children of expanded nodes and nodes without children.