Search code examples
eclipse-rcpnattable

Borders dont appear to NatTable Cells in Eclipse RCP application


I have tried that with both : Setting a theme configuration and Registering a style with border style in Config Registry. But I am not seeing the borders. Is there anything else I am missing?

In my postConstruct method I am initialising NatTable as follows :

    final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration(imageRightUp, imageTreeRightDown);

    TextPainter textPainter = new TextPainter(true, false);
    ImagePainter imagePainter = new ImagePainter(threeDots);
    CellPainterDecorator cellPainterDecorator = new CellPainterDecorator(textPainter, CellEdgeEnum.RIGHT, imagePainter);

    configRegistry.registerConfigAttribute(
            CellConfigAttributes.CELL_PAINTER,
            cellPainterDecorator,
            DisplayMode.NORMAL,
            LABEL_1);

    Style style = new Style();

    style.setAttributeValue(
            CellStyleAttributes.BACKGROUND_COLOR,
            GUIHelper.getColor(44, 104, 125));
    style.setAttributeValue(
            CellStyleAttributes.FOREGROUND_COLOR,
            GUIHelper.COLOR_WHITE);
    style.setAttributeValue(
            CellStyleAttributes.BORDER_STYLE,
            new BorderStyle(5, GUIHelper.COLOR_BLACK, LineStyleEnum.SOLID));

    configRegistry.registerConfigAttribute(
            // attribute to apply
            CellConfigAttributes.CELL_STYLE,
            // value of the attribute
            style,
            // apply during normal rendering i.e not
            // during selection or edit
            DisplayMode.NORMAL,
            // apply the above for all cells with this label
           LABEL_1);

    configRegistry.registerConfigAttribute(
            // attribute to apply
            CellConfigAttributes.CELL_STYLE,
            // value of the attribute
            style,
            // apply during normal rendering i.e not
            // during selection or edit
            DisplayMode.NORMAL,
            // apply the above for all cells with this label
            LABEL_2);

    NatTable natTable = new NatTable(parent, viewportLayer, false);
    GridData d = new GridData(SWT.FILL, SWT.FILL, true, true, 1,1);
    natTable.setLayoutData(d);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultTreeLayerConfiguration(treeLayer));
    natTable.setTheme(modernTheme);
    natTable.configure();

Also this is Theme Configuration :

public class ModernNatTableThemeConfiguration extends DefaultNatTableThemeConfiguration {


    public ModernNatTableThemeConfiguration( Image imageRightUp, Image imageTreeRightDown ){

        TreeImagePainter treeImagePainter = new TreeImagePainter(
                false,
                imageRightUp, imageTreeRightDown, null); //$NON-NLS-1$//$NON-NLS-2$
        this.treeStructurePainter = new BackgroundPainter(new PaddingDecorator(
                new IndentedTreeImagePainter(10, null, CellEdgeEnum.LEFT,
                        treeImagePainter, false, 2, true), 0, 5, 0, 5, false));

       TreeImagePainter treeSelectionImagePainter = new TreeImagePainter(
                false,
                imageRightUp, imageTreeRightDown, null); //$NON-NLS-1$//$NON-NLS-2$
        this.treeStructureSelectionPainter = new BackgroundPainter(
                new PaddingDecorator(new IndentedTreeImagePainter(10, null,
                        CellEdgeEnum.LEFT, treeSelectionImagePainter, false, 2,
                        true), 0, 5, 0, 5, false));

        this.treeBgColor = GUIHelper.getColor(44, 104, 125);
        this.treeFgColor = GUIHelper.getColor(44, 104, 125);
    }
 }

Solution

  • I think we need to clear about the terms. Do you want to remove the borders or the grid lines? Because you specify a border in your style configuration, so the border should be there.

    If you want to get rid of the grid lines, you need to configure the CellLayerPainter.

    This can be done like this for example:

    configRegistry.registerConfigAttribute(
                CellConfigAttributes.RENDER_GRID_LINES, 
                Boolean.FALSE);
    

    BTW, it is not a good practice to directly modify the ConfigRegistry like you are doing in your code. You should create an IConfiguration (e.g. AbstractRegistryConfiguration) and register the IConfiguration to your NatTable instance instead. Otherwise NatTable#configure() might override your changes at configuration time.

    This is explained here: http://www.vogella.com/tutorials/NatTable/article.html#architecture_configuration