Search in sources :

Example 11 with ColumnResizeCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.

the class DefaultBodyLayerStackTest method resizeAColumnAndReorderIt.

@Test
public void resizeAColumnAndReorderIt() throws Exception {
    assertEquals(10, this.layerStack.getColumnCount());
    assertEquals(1000, this.layerStack.getWidth());
    // Resize 2
    this.layerStack.doCommand(new ColumnResizeCommand(this.layerStack, 2, 500));
    assertEquals(1400, this.layerStack.getWidth());
    // Reorder 2 -> 4
    this.layerStack.doCommand(new ColumnReorderCommand(this.layerStack, 2, 4));
    assertEquals(0, this.layerStack.getColumnIndexByPosition(0));
    assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
    assertEquals(3, this.layerStack.getColumnIndexByPosition(2));
    assertEquals(2, this.layerStack.getColumnIndexByPosition(3));
    assertEquals(4, this.layerStack.getColumnIndexByPosition(4));
    assertEquals(5, this.layerStack.getColumnIndexByPosition(5));
    assertEquals(6, this.layerStack.getColumnIndexByPosition(6));
    assertEquals(7, this.layerStack.getColumnIndexByPosition(7));
    assertEquals(8, this.layerStack.getColumnIndexByPosition(8));
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 12 with ColumnResizeCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.

the class DefaultBodyLayerStackTest method resizeAColumnAndHideIt.

@Test
public void resizeAColumnAndHideIt() throws Exception {
    assertEquals(10, this.layerStack.getColumnCount());
    assertEquals(1000, this.layerStack.getWidth());
    // Resize 2
    this.layerStack.doCommand(new ColumnResizeCommand(this.layerStack, 2, 500));
    assertEquals(1400, this.layerStack.getWidth());
    assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(1));
    assertEquals(100, this.layerStack.getStartXOfColumnPosition(1));
    assertEquals(2, this.layerStack.getColumnIndexByPosition(2));
    assertEquals(500, this.layerStack.getColumnWidthByPosition(2));
    assertEquals(200, this.layerStack.getStartXOfColumnPosition(2));
    assertEquals(3, this.layerStack.getColumnIndexByPosition(3));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(3));
    assertEquals(700, this.layerStack.getStartXOfColumnPosition(3));
    // Hide 2
    this.layerStack.doCommand(new ColumnHideCommand(this.layerStack, 2));
    assertEquals(9, this.layerStack.getColumnCount());
    assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(1));
    assertEquals(100, this.layerStack.getStartXOfColumnPosition(1));
    assertEquals(3, this.layerStack.getColumnIndexByPosition(2));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(2));
    assertEquals(200, this.layerStack.getStartXOfColumnPosition(2));
    assertEquals(4, this.layerStack.getColumnIndexByPosition(3));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(3));
    assertEquals(300, this.layerStack.getStartXOfColumnPosition(3));
    assertEquals(9, this.layerStack.getColumnIndexByPosition(8));
    assertEquals(100, this.layerStack.getColumnWidthByPosition(8));
    assertEquals(800, this.layerStack.getStartXOfColumnPosition(8));
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) Test(org.junit.Test)

Example 13 with ColumnResizeCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method testEditorResize.

@Test
public void testEditorResize() {
    this.natTable.enableEditingOnAllCells();
    ILayerCell cell = this.natTable.getCellByPosition(4, 4);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    assertEquals(new Rectangle(340, 80, 99, 19), this.natTable.getActiveCellEditor().getEditorControl().getBounds());
    this.natTable.doCommand(new ColumnResizeCommand(this.natTable, 2, 110));
    assertEquals(new Rectangle(340, 80, 99, 19), this.natTable.getActiveCellEditor().getEditorControl().getBounds());
    this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.FocusOut, null);
    // ActiveCellEditor should be closed if a ColumnResizeCommand is
    // executed and the editor loses focus
    assertNull(this.natTable.getActiveCellEditor());
    assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Example 14 with ColumnResizeCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.

the class TextPainter method setNewMinLength.

@Override
protected void setNewMinLength(ILayerCell cell, int contentWidth) {
    int cellLength = cell.getBounds().width;
    if (cellLength < contentWidth) {
        // execute ColumnResizeCommand
        ILayer layer = cell.getLayer();
        layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth, true));
    }
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Example 15 with ColumnResizeCommand

use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand 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

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