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