Search in sources :

Example 1 with CellPainterDecorator

use of org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator in project nebula.widgets.nattable by eclipse.

the class ComboBoxFilterRowConfiguration method configureRegistry.

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, this.cellEditor, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
    configRegistry.registerConfigAttribute(FilterRowConfigAttributes.TEXT_MATCHING_MODE, TextMatchingMode.REGULAR_EXPRESSION);
    ICellPainter cellPainter = new CellPainterDecorator(new TextPainter() {

        {
            this.paintFg = false;
        }

        // override the preferred width and height to be 0, as otherwise
        // the String that is generated in the background for multiple
        // selection will be taken into account for auto resizing
        @Override
        public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
            return 0;
        }

        @Override
        public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
            return 0;
        }
    }, CellEdgeEnum.RIGHT, this.filterIconPainter);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
}
Also used : IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) GC(org.eclipse.swt.graphics.GC) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 2 with CellPainterDecorator

use of org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator in project nebula.widgets.nattable by eclipse.

the class EditableGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    DefaultGridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
    DataLayer columnHeaderDataLayer = (DataLayer) gridLayer.getColumnHeaderDataLayer();
    columnHeaderDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    IDataProvider dataProvider = bodyDataLayer.getDataProvider();
    // NOTE: Register the accumulator on the body data layer.
    // This ensures that the labels are bound to the column index and are
    // unaffected by column order.
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
    natTable.addConfiguration(editableGridConfiguration(columnLabelAccumulator, dataProvider));
    final ColumnHeaderCheckBoxPainter columnHeaderCheckBoxPainter = new ColumnHeaderCheckBoxPainter(bodyDataLayer);
    final ICellPainter column9HeaderPainter = new BeveledBorderDecorator(new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, columnHeaderCheckBoxPainter));
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, column9HeaderPainter, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
        }

        @Override
        public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
            uiBindingRegistry.registerFirstSingleClickBinding(new CellPainterMouseEventMatcher(GridRegion.COLUMN_HEADER, MouseEventMatcher.LEFT_BUTTON, columnHeaderCheckBoxPainter), new ToggleCheckBoxColumnAction(columnHeaderCheckBoxPainter, bodyDataLayer));
        }
    });
    natTable.configure();
    return natTable;
}
Also used : AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) CellPainterMouseEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.CellPainterMouseEventMatcher) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) BeveledBorderDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator) ToggleCheckBoxColumnAction(org.eclipse.nebula.widgets.nattable.edit.action.ToggleCheckBoxColumnAction) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnHeaderCheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ColumnHeaderCheckBoxPainter) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) UiBindingRegistry(org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry)

Example 3 with CellPainterDecorator

use of org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator in project nebula.widgets.nattable by eclipse.

the class Rendering_cells_as_a_link_and_button method addButtonToColumn.

private void addButtonToColumn(IConfigRegistry configRegistry) {
    this.buttonPainter = new ButtonCellPainter(new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter(GUIHelper.getImage("preferences"))));
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, this.buttonPainter, DisplayMode.NORMAL, BUTTON_CELL_LABEL);
    // Add your listener to the button
    this.buttonPainter.addClickListener(new MyMouseAction());
    // Set the color of the cell. This is picked up by the button painter to
    // style the button
    Style style = new Style();
    style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_WHITE);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, BUTTON_CELL_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.SELECT, BUTTON_CELL_LABEL);
}
Also used : Style(org.eclipse.nebula.widgets.nattable.style.Style) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) ButtonCellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ButtonCellPainter) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter)

Example 4 with CellPainterDecorator

use of org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator in project nebula.widgets.nattable by eclipse.

the class CellPainterFactory method getCellPainter.

/**
 * @param backgroundKey
 *            The key of the background painter to use
 * @param decoratorKeys
 *            The list of keys of decorator painter to use
 * @param contentKey
 *            The key of the content painter to use
 * @param painterProperties
 *            The properties to set to the painters
 * @return The {@link ICellPainter} construct that should be used for
 *         rendering
 */
public ICellPainter getCellPainter(String backgroundKey, List<String> decoratorKeys, String contentKey, Map<String, Object> painterProperties) {
    ICellPainter painter = null;
    // resolve content painter
    ICellPainter contentPainter = null;
    if (isContentPainterKey(contentKey)) {
        contentPainter = getContentPainter(contentKey, painterProperties);
    } else if (!NONE.equalsIgnoreCase(contentKey)) {
        // fallback for unknown content painter key
        contentPainter = getContentPainter(TEXT_PAINTER_KEY, painterProperties);
    }
    // intermediate result = content painter
    painter = contentPainter;
    // resolve decorators
    String decoratorKey = null;
    for (int i = decoratorKeys.size() - 1; i >= 0; i--) {
        decoratorKey = decoratorKeys.get(i);
        if (DECORATOR_KEY.equalsIgnoreCase(decoratorKey)) {
            CellPainterDecorator decorator = new CellPainterDecorator();
            decorator.setPaintBackground(false);
            decorator.setBaseCellPainter(painter);
            Image image = (Image) painterProperties.get(NatTableCSSConstants.DECORATOR_IMAGE);
            CellEdgeEnum edge = (CellEdgeEnum) painterProperties.get(NatTableCSSConstants.DECORATOR_EDGE);
            Integer spacing = (Integer) painterProperties.get(NatTableCSSConstants.DECORATOR_SPACING);
            Boolean paintDecorationDependent = (Boolean) painterProperties.get(NatTableCSSConstants.PAINT_DECORATION_DEPENDENT);
            decorator.setDecoratorCellPainter(new ImagePainter(image, false));
            decorator.setCellEdge(edge);
            decorator.setSpacing(spacing);
            decorator.setPaintDecorationDependent(paintDecorationDependent);
            painter = decorator;
        } else {
            CellPainterWrapper decorator = getDecoratorPainter(decoratorKey, painterProperties, painter);
            if (decorator != null) {
                painter = decorator;
            }
        }
    }
    // add background painter
    if (backgroundKey != null) {
        CellPainterWrapper bgPainter = getBackgroundPainter(backgroundKey, painterProperties, painter);
        if (bgPainter != null) {
            bgPainter.setWrappedPainter(painter);
            painter = bgPainter;
        }
    }
    return painter;
}
Also used : CellEdgeEnum(org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum) CellPainterWrapper(org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) Image(org.eclipse.swt.graphics.Image) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) ImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter) ColumnGroupExpandCollapseImagePainter(org.eclipse.nebula.widgets.nattable.group.painter.ColumnGroupExpandCollapseImagePainter) IndentedTreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter) TreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.TreeImagePainter) BackgroundImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundImagePainter) RowGroupExpandCollapseImagePainter(org.eclipse.nebula.widgets.nattable.group.painter.RowGroupExpandCollapseImagePainter)

Example 5 with CellPainterDecorator

use of org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator in project nebula.widgets.nattable by eclipse.

the class TableDecorationConfiguration method configureRegistry.

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.TOP, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_ONE_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.BOTTOM, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_TWO_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.LEFT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_THREE_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_FOUR_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.TOP_LEFT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_FIVE_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.TOP_RIGHT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_SIX_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.BOTTOM_LEFT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_SEVEN_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.BOTTOM_RIGHT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_EIGHT_LABEL);
}
Also used : TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter)

Aggregations

CellPainterDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator)6 TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)5 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)4 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)3 ImagePainter (org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter)3 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 ToggleCheckBoxColumnAction (org.eclipse.nebula.widgets.nattable.edit.action.ToggleCheckBoxColumnAction)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 ColumnLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator)2 ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)2 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)2 ColumnHeaderCheckBoxPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ColumnHeaderCheckBoxPainter)2 SortedList (ca.odell.glazedlists.SortedList)1 TreeList (ca.odell.glazedlists.TreeList)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)1 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)1