Search in sources :

Example 1 with ColumnResizeCommand

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);
    }
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 2 with ColumnResizeCommand

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));
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) Test(org.junit.Test)

Example 3 with ColumnResizeCommand

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"));
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) RowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) RowReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand)

Example 4 with ColumnResizeCommand

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));
    }
}
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) Image(org.eclipse.swt.graphics.Image) RowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)

Example 5 with ColumnResizeCommand

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);
    }
}
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) Transform(org.eclipse.swt.graphics.Transform)

Aggregations

ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)15 Test (org.junit.Test)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)4 IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)4 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)3 RowResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)3 ClientAreaResizeCommand (org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand)2 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)2 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)2 InitializeAutoResizeColumnsCommand (org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand)2 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)2 Shell (org.eclipse.swt.widgets.Shell)2 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)1 RowReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1