Search in sources :

Example 6 with ColumnResizeCommand

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

the class ColumnResizeDragMode method updateColumnWidth.

private void updateColumnWidth(ILayer natLayer, MouseEvent e) {
    int dragWidth = e.x - this.startX;
    int newColumnWidth = this.originalColumnWidth + dragWidth;
    if (newColumnWidth < getColumnWidthMinimum()) {
        newColumnWidth = getColumnWidthMinimum();
    }
    // trigger the ColumnResizeCommand with downScaling enabled
    // as the user performed a drag operation the newColumnWidth is the
    // value on the screen, which needs to be down scaled in the DataLayer
    natLayer.doCommand(new ColumnResizeCommand(natLayer, this.columnPositionToResize, newColumnWidth, true));
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) Point(org.eclipse.swt.graphics.Point)

Example 7 with ColumnResizeCommand

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

the class RichTextCellPainter method paintCell.

@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
    IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
    setupGCFromConfig(gc, cellStyle);
    String htmlText = CellDisplayConversionUtils.convertDataType(cell, configRegistry);
    Rectangle painterBounds = new Rectangle(bounds.x, bounds.y - this.richTextPainter.getParagraphSpace(), bounds.width, bounds.height);
    this.richTextPainter.paintHTML(htmlText, gc, painterBounds);
    int height = this.richTextPainter.getPreferredSize().y - 2 * this.richTextPainter.getParagraphSpace();
    if (performRowResize(height, painterBounds)) {
        cell.getLayer().doCommand(new RowResizeCommand(cell.getLayer(), cell.getRowPosition(), GUIHelper.convertVerticalDpiToPixel(height) + (cell.getBounds().height - bounds.height)));
    }
    if (performColumnResize(this.richTextPainter.getPreferredSize().x, painterBounds)) {
        cell.getLayer().doCommand(new ColumnResizeCommand(cell.getLayer(), cell.getColumnPosition(), GUIHelper.convertHorizontalDpiToPixel(this.richTextPainter.getPreferredSize().x) + (cell.getBounds().width - bounds.width)));
    }
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) Rectangle(org.eclipse.swt.graphics.Rectangle) RowResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)

Example 8 with ColumnResizeCommand

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

the class FreezeHandlerTest method testFreezeColumnResize.

@Test
public void testFreezeColumnResize() {
    this.compositeFreezeLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 1500, 400);
        }
    });
    // Fire this command so that the viewport can be initialized
    this.compositeFreezeLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL)));
    this.compositeFreezeLayer.doCommand(new FreezeColumnCommand(this.compositeFreezeLayer, 2));
    assertEquals(3, this.freezeLayer.getColumnCount());
    assertEquals(7, this.viewportLayer.getColumnCount());
    assertEquals(300, this.viewportLayer.getOrigin().getX());
    this.compositeFreezeLayer.doCommand(new ColumnResizeCommand(this.freezeLayer, 2, 200));
    assertEquals(3, this.freezeLayer.getColumnCount());
    assertEquals(7, this.viewportLayer.getColumnCount());
    assertEquals(400, this.viewportLayer.getOrigin().getX());
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) Shell(org.eclipse.swt.widgets.Shell) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 9 with ColumnResizeCommand

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

the class FreezeHandlerTest method testFreezeAllColumnsResize.

@Test
public void testFreezeAllColumnsResize() {
    this.compositeFreezeLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 1500, 400);
        }
    });
    // Fire this command so that the viewport can be initialized
    this.compositeFreezeLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL)));
    this.compositeFreezeLayer.doCommand(new FreezeColumnCommand(this.compositeFreezeLayer, 9));
    assertEquals(10, this.freezeLayer.getColumnCount());
    assertEquals(0, this.viewportLayer.getColumnCount());
    assertEquals(1000, this.viewportLayer.getOrigin().getX());
    this.compositeFreezeLayer.doCommand(new ColumnResizeCommand(this.freezeLayer, 2, 200));
    assertEquals(10, this.freezeLayer.getColumnCount());
    assertEquals(0, this.viewportLayer.getColumnCount());
    assertEquals(1100, this.viewportLayer.getOrigin().getX());
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) Shell(org.eclipse.swt.widgets.Shell) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) Test(org.junit.Test)

Example 10 with ColumnResizeCommand

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

the class AutoResizeColumnsTest method shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected.

/**
 * Scenario: Multiple columns are selected but a non selected column is auto
 * resized.
 */
@Test
public void shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected() throws Exception {
    GridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
    setClientAreaProvider(gridLayer);
    // Resize grid column 1, 2
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 1, 10));
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
    assertEquals(10, gridLayer.getColumnWidthByPosition(1));
    assertEquals(10, gridLayer.getColumnWidthByPosition(2));
    // Fully select columns 1, 2
    SelectionLayer selectionLayer = ((DefaultBodyLayerStack) gridLayer.getBodyLayer()).getSelectionLayer();
    selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 0, 0, false, false));
    selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 1, 0, true, false));
    assertEquals(2, selectionLayer.getFullySelectedColumnPositions().length);
    // Resize grid column 5
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 5, 10));
    assertEquals(10, gridLayer.getColumnWidthByPosition(5));
    // Auto resize column 5
    InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 5, this.configRegistry, this.gcFactory);
    gridLayer.doCommand(command);
    // Columns 1 and 2 should not be resized
    assertEquals(10, gridLayer.getColumnWidthByPosition(1));
    assertEquals(10, gridLayer.getColumnWidthByPosition(2));
    assertTrue(gridLayer.getColumnWidthByPosition(5) > 10);
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) 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) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) Test(org.junit.Test)

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