Search in sources :

Example 61 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.

the class BoxingStyleTest method retrievedCellShouldHaveConfiguredBackground.

// Background color
@Test
public void retrievedCellShouldHaveConfiguredBackground() {
    // Register background color for body cells in normal mode
    final Color backgroundColor = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
    this.cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, backgroundColor);
    this.configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, this.cellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE);
    // Check for background color styling
    ILayerCell cell = this.natTable.getCellByPosition(2, 2);
    IStyle cellStyle = this.configRegistry.getConfigAttribute(CellConfigAttributes.CELL_STYLE, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
    Assert.assertEquals(backgroundColor, cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    // set up painter
    this.cellPainter.setupGCFromConfig(this.gc, cellStyle);
    Assert.assertEquals(backgroundColor, this.gc.getBackground());
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) Color(org.eclipse.swt.graphics.Color) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 62 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.

the class TextCellEditor method activateCell.

@Override
protected Control activateCell(final Composite parent, Object originalCanonicalValue) {
    this.text = createEditorControl(parent);
    // editor is activated by keypress
    if (originalCanonicalValue instanceof Character) {
        this.text.setText(originalCanonicalValue.toString());
        selectText(this.selectionMode != null ? this.selectionMode : EditorSelectionEnum.END);
    } else // if there is no initial value, handle the original canonical value to
    // transfer it to the text control
    {
        setCanonicalValue(originalCanonicalValue);
        selectText(this.selectionMode != null ? this.selectionMode : EditorSelectionEnum.ALL);
    }
    if (!isEditable()) {
        this.text.setEditable(false);
    }
    // show an error decoration if this is enabled
    this.decorationProvider.createErrorDecorationIfRequired(this.text);
    // conversion/validation
    if (this.inputConversionErrorHandler instanceof RenderErrorHandling) {
        IStyle conversionErrorStyle = this.configRegistry.getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, DisplayMode.EDIT, this.labelStack.getLabels());
        ((RenderErrorHandling) this.inputConversionErrorHandler).setErrorStyle(conversionErrorStyle);
    }
    if (this.inputValidationErrorHandler instanceof RenderErrorHandling) {
        IStyle validationErrorStyle = this.configRegistry.getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, DisplayMode.EDIT, this.labelStack.getLabels());
        ((RenderErrorHandling) this.inputValidationErrorHandler).setErrorStyle(validationErrorStyle);
    }
    // ContentProposalAdapter
    if (this.controlContentAdapter != null) {
        configureContentProposalAdapter(new ContentProposalAdapter(this.text, this.controlContentAdapter, this.proposalProvider, this.keyStroke, this.autoActivationCharacters));
    }
    this.text.forceFocus();
    return this.text;
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) RenderErrorHandling(org.eclipse.nebula.widgets.nattable.edit.config.RenderErrorHandling) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 63 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.

the class ImagePainter method getCellPainterAt.

@Override
public ICellPainter getCellPainterAt(int x, int y, ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
    Image image = getImage(cell, configRegistry);
    if (image != null) {
        Rectangle imageBounds = image.getBounds();
        IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
        int x0 = bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width);
        int y0 = bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height);
        if (x >= x0 && x < x0 + imageBounds.width && y >= y0 && y < y0 + imageBounds.height) {
            return super.getCellPainterAt(x, y, cell, gc, bounds, configRegistry);
        }
    }
    return null;
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image)

Example 64 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.

the class PasswordTextPainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    // check for the configuration of a echo character in the corresponding
    // cell style
    IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
    Character configEchoChar = cellStyle.getAttributeValue(CellStyleAttributes.PASSWORD_ECHO_CHAR);
    if (configEchoChar != null) {
        this.echoChar = configEchoChar;
    }
    super.paintCell(cell, gc, rectangle, configRegistry);
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle)

Example 65 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.

the class VerticalTextImagePainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    if (this.paintBg) {
        super.paintCell(cell, gc, rectangle, configRegistry);
    }
    Rectangle originalClipping = gc.getClipping();
    gc.setClipping(rectangle.intersection(originalClipping));
    IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
    setupGCFromConfig(gc, cellStyle);
    boolean underline = renderUnderlined(cellStyle);
    boolean strikethrough = renderStrikethrough(cellStyle);
    String text = convertDataType(cell, configRegistry);
    // calculate the text to display, adds dots if the text is longer than
    // the available row height and adds new lines instead of spaces if word
    // wrapping is enabled
    text = getTextToDisplay(cell, gc, rectangle.height, text);
    int numberOfNewLines = getNumberOfNewLines(text);
    // if the content width is bigger than the available column width
    // we're extending the column width (only if word wrapping is enabled)
    int fontHeight = gc.getFontMetrics().getHeight();
    int contentWidth = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
    int contentToCellDiff = (cell.getBounds().width - rectangle.width);
    if ((contentWidth > rectangle.width) && this.calculateByTextHeight) {
        ILayer layer = cell.getLayer();
        layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
    }
    if (text != null && text.length() > 0) {
        if (numberOfNewLines == 1) {
            int contentHeight = Math.min(getLengthFromCache(gc, text), rectangle.height);
            GraphicsUtils.drawVerticalText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight + this.spacing), underline, strikethrough, this.paintBg, gc, SWT.UP);
        } else {
            // draw every line by itself because of the alignment, otherwise
            // the whole text is always aligned right
            int xStartPos = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth);
            // $NON-NLS-1$
            String[] lines = text.split("\n");
            for (String line : lines) {
                int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.height);
                GraphicsUtils.drawVerticalText(line, xStartPos + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth + this.spacing), underline, strikethrough, this.paintBg, gc, SWT.UP);
                // after every line calculate the x start pos new
                xStartPos += fontHeight;
                xStartPos += this.lineSpacing;
            }
        }
    }
    gc.setClipping(originalClipping);
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle)

Aggregations

IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)97 BorderStyle (org.eclipse.nebula.widgets.nattable.style.BorderStyle)50 Style (org.eclipse.nebula.widgets.nattable.style.Style)49 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)24 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)7 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 HashMap (java.util.HashMap)5 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)5 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)5 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)5 ExtendedPersonWithAddress (org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress)5 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)5 VisualRefreshCommand (org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand)4 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)4 ExtendedReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor)4 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 DefaultDoubleDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultDoubleDisplayConverter)4 GroupByDataLayer (org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByDataLayer)4 GroupByHeaderLayer (org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderLayer)4