边界似乎不适用于Eclipse RCP应用程序中的NatTable Cells

时间:2015-10-15 06:35:41

标签: eclipse-rcp nattable

我尝试过两者:在Config Registry中设置主题配置并在边框样式中注册样式。但我没有看到边界。还有什么我想念的吗?

在我的postConstruct方法中,我按如下方式初始化NatTable:

    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();

这也是主题配置:

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);
    }
 }

1 个答案:

答案 0 :(得分:0)

我认为我们需要明确条款。要删除边框或网格线吗?因为您在样式配置中指定了边框,所以边框应该在那里。

如果您想摆脱网格线,则需要配置CellLayerPainter

这可以这样做,例如:

configRegistry.registerConfigAttribute(
            CellConfigAttributes.RENDER_GRID_LINES, 
            Boolean.FALSE);
顺便说一下,直接修改代码中的ConfigRegistry并不是一个好习惯。您应该创建IConfiguration(例如AbstractRegistryConfiguration)并将IConfiguration注册到您的NatTable实例。否则NatTable#configure()可能会在配置时覆盖您的更改。

这在此解释:http://www.vogella.com/tutorials/NatTable/article.html#architecture_configuration