use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class AutoResizeColumnsTest method autoResizeOneColumn.
/**
* These sequence of actions were causing a nasty bug in AutoResize
*/
@Test
public void autoResizeOneColumn() throws Exception {
GridLayer gridLayer = new DummyGridLayerStack();
setClientAreaProvider(gridLayer);
// Resize column
gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
assertEquals(10, gridLayer.getColumnWidthByPosition(2));
// Auto resize the one column
InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 2, this.configRegistry, this.gcFactory);
gridLayer.doCommand(command);
// Note: the actual resized width is platform specific (font
// dependency),
// hence we can't compare against a fixed value.
int columnWidth = gridLayer.getColumnWidthByPosition(2);
assertTrue(columnWidth > 10);
// Reorder columns
gridLayer.doCommand(new ColumnReorderCommand(gridLayer, 2, 1));
assertEquals(columnWidth, gridLayer.getColumnWidthByPosition(1));
// Select all columns
gridLayer.doCommand(new SelectAllCommand());
// Resize all selected columns
command = new InitializeAutoResizeColumnsCommand(gridLayer, 1, this.configRegistry, this.gcFactory);
gridLayer.doCommand(command);
for (int columnPosition = 1; columnPosition <= 20; columnPosition++) {
assertTrue("column " + columnPosition + " should have been resized, but it is still its original width", gridLayer.getColumnWidthByPosition(columnPosition) != 100);
}
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class ResizeColumnTest method reiszeColumnInATableWithNoRows.
/**
* Test for bug NTBL-431
*/
@Test
public void reiszeColumnInATableWithNoRows() throws Exception {
NatTableFixture natTable = new NatTableFixture(new DummyGridLayerStack(5, 0), true);
assertEquals(100, natTable.getColumnWidthByPosition(2));
natTable.doCommand(new ColumnResizeCommand(natTable, 2, 150));
assertEquals(150, natTable.getColumnWidthByPosition(2));
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class PersistenceIntegrationTest method saveStateToPropeties.
public void saveStateToPropeties() throws Exception {
// Resize column 2 to 200px
assertEquals(100, this.natTableFixture.getColumnWidthByPosition(2));
this.natTableFixture.doCommand(new ColumnResizeCommand(this.natTableFixture, 2, 200));
assertEquals(200, this.natTableFixture.getColumnWidthByPosition(2));
// Resize row 2 to 100px
assertEquals(20, this.natTableFixture.getRowHeightByPosition(2));
this.natTableFixture.doCommand(new RowResizeCommand(this.natTableFixture, 2, 100));
assertEquals(100, this.natTableFixture.getRowHeightByPosition(2));
// Reorder column 1 --> 5 (grid coordinates)
// 0, 1, 2, 3, 4, 5,.. --> 1, 2, 3, 0, 4, 5,..
assertEquals(0, this.natTableFixture.getColumnIndexByPosition(1));
this.natTableFixture.doCommand(new ColumnReorderCommand(this.natTableFixture, 1, 5));
assertEquals(1, this.natTableFixture.getColumnIndexByPosition(1));
// Reorder row 1 --> 5 (grid coordinates)
// 0, 1, 2, 3, 4, 5,.. --> 1, 2, 3, 0, 4, 5,..
assertEquals(0, this.natTableFixture.getRowIndexByPosition(1));
this.natTableFixture.doCommand(new RowReorderCommand(this.natTableFixture, 1, 5));
assertEquals(1, this.natTableFixture.getRowIndexByPosition(1));
// Hide column with index 3 (grid coordinates)
assertEquals(3, this.natTableFixture.getColumnIndexByPosition(3));
this.natTableFixture.doCommand(new ColumnHideCommand(this.natTableFixture, 3));
assertEquals(0, this.natTableFixture.getColumnIndexByPosition(3));
this.natTableFixture.saveState(TEST_PERSISTENCE_PREFIX, this.properties);
// Ensure that properties got persisted
assertEquals("true", this.properties.get("testPrefix.COLUMN_HEADER.columnWidth.resizableByDefault"));
assertEquals("100", this.properties.get("testPrefix.COLUMN_HEADER.columnWidth.defaultSize"));
assertEquals("true", this.properties.get("testPrefix.COLUMN_HEADER.rowHeight.resizableByDefault"));
assertEquals("40", this.properties.get("testPrefix.ROW_HEADER.columnWidth.defaultSize"));
assertEquals("true", this.properties.get("testPrefix.ROW_HEADER.rowHeight.resizableByDefault"));
assertEquals("true", this.properties.get("testPrefix.ROW_HEADER.columnWidth.resizableByDefault"));
assertEquals("40", this.properties.get("testPrefix.ROW_HEADER.rowHeight.defaultSize"));
assertEquals("20", this.properties.get("testPrefix.CORNER.rowHeight.defaultSize"));
assertEquals("true", this.properties.get("testPrefix.CORNER.columnWidth.resizableByDefault"));
assertEquals("true", this.properties.get("testPrefix.CORNER.rowHeight.resizableByDefault"));
assertEquals("20", this.properties.get("testPrefix.BODY.rowHeight.defaultSize"));
assertEquals("true", this.properties.get("testPrefix.BODY.rowHeight.resizableByDefault"));
assertEquals("true", this.properties.get("testPrefix.BODY.columnWidth.resizableByDefault"));
assertEquals("1,2,3,0,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,", this.properties.get("testPrefix.BODY.columnIndexOrder"));
assertEquals("1:100,", this.properties.get("testPrefix.BODY.rowHeight.sizes"));
assertEquals("1:200,", this.properties.get("testPrefix.BODY.columnWidth.sizes"));
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class ImagePainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, bounds, configRegistry);
}
Image image = getImage(cell, configRegistry);
if (image != null) {
Rectangle imageBounds = image.getBounds();
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
int contentHeight = imageBounds.height;
if (this.calculateByHeight && (contentHeight > bounds.height)) {
int contentToCellDiff = (cell.getBounds().height - bounds.height);
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff, true));
}
int contentWidth = imageBounds.width;
if (this.calculateByWidth && (contentWidth > bounds.width)) {
int contentToCellDiff = (cell.getBounds().width - bounds.width);
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
}
gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height));
}
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class VerticalTextPainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
if (this.paintFg) {
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
int fontHeight = gc.getFontMetrics().getHeight();
String text = convertDataType(cell, configRegistry);
// Draw Text
text = getTextToDisplay(cell, gc, rectangle.height, text);
int numberOfNewLines = getNumberOfNewLines(text);
// if the content height is bigger than the available column width
// we're extending the column width (only if word wrapping is
// enabled)
int contentHeight = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
int contentToCellDiff = (cell.getBounds().width - rectangle.width);
if ((contentHeight > rectangle.width) && this.calculateByTextHeight) {
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentHeight + contentToCellDiff, true));
}
if (text != null && text.length() > 0) {
Transform originalTransform = new Transform(gc.getDevice());
gc.getTransform(originalTransform);
Transform transform = new Transform(gc.getDevice());
gc.getTransform(transform);
if (numberOfNewLines == 1) {
int contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.height);
if (!isRotateClockwise()) {
transform.rotate(-90f);
int xOffset = -rectangle.x + (-contentWidth - rectangle.y) - CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentWidth);
int yOffset = rectangle.x + -rectangle.y + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
transform.translate(xOffset, yOffset);
} else {
transform.rotate(90f);
int horizontalPadding = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight);
if (horizontalPadding != 0) {
horizontalPadding += gc.getFontMetrics().getLeading();
}
int xOffset = rectangle.y - rectangle.x + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentWidth);
int yOffset = -contentHeight - rectangle.y - rectangle.x - horizontalPadding + this.spacing;
transform.translate(xOffset, yOffset);
}
gc.setTransform(transform);
gc.drawText(text, rectangle.x, rectangle.y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
int length = gc.textExtent(text).x;
paintDecoration(cellStyle, gc, rectangle.x, rectangle.y, length, fontHeight);
} else {
// draw every line by itself because of the alignment,
// otherwise the whole text is always aligned right
// $NON-NLS-1$
String[] lines = text.split("\n");
boolean firstline = true;
int previousXOffset = 0;
for (String line : lines) {
int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.height);
if (!isRotateClockwise()) {
int xOffset = -rectangle.x + (-lineContentWidth - rectangle.y) - CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth);
if (firstline) {
transform.rotate(-90f);
int yOffset = rectangle.x + -rectangle.y + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
transform.translate(xOffset, yOffset);
firstline = false;
} else {
transform.translate(xOffset - previousXOffset, fontHeight + this.lineSpacing);
}
previousXOffset = xOffset;
} else {
int xOffset = rectangle.y - rectangle.x + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth);
if (firstline) {
transform.rotate(90f);
int horizontalPadding = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight);
if (horizontalPadding != 0) {
horizontalPadding += gc.getFontMetrics().getLeading();
}
int yOffset = -contentHeight - rectangle.y - rectangle.x - horizontalPadding + this.spacing + (fontHeight * (numberOfNewLines - 1)) + (this.lineSpacing * (numberOfNewLines - 1));
transform.translate(xOffset, yOffset);
firstline = false;
} else {
transform.translate(xOffset - previousXOffset, -fontHeight - this.lineSpacing);
}
previousXOffset = xOffset;
}
gc.setTransform(transform);
gc.drawText(line, rectangle.x, rectangle.y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
int length = gc.textExtent(line).x;
paintDecoration(cellStyle, gc, rectangle.x, rectangle.y, length, fontHeight);
}
}
gc.setTransform(originalTransform);
if (originalTransform != null) {
originalTransform.dispose();
}
if (transform != null) {
transform.dispose();
}
}
gc.setClipping(originalClipping);
resetGC(gc);
}
}
Aggregations