Search in sources :

Example 6 with SelectColumnCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.

the class ColumnGroupsCommandHandlerTest method shouldUngroupFirstAndLastSelectedColumn.

@Test
public void shouldUngroupFirstAndLastSelectedColumn() {
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 0, 0, false, true));
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 1, 0, false, true));
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 2, 0, false, true));
    final String columnGroupName = "Test Group 3";
    this.handler.loadSelectedColumnsIndexesWithPositions();
    this.handler.handleGroupColumnsCommand(columnGroupName);
    // Test ungrouping first column
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 0, 0, false, true));
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 2, 0, false, true));
    this.handler.handleUngroupCommand();
    Assert.assertEquals(1, getColumnIndexesInGroup(1).size());
    Assert.assertEquals(1, getColumnIndexesInGroup(1).get(0).intValue());
    Assert.assertEquals(0, this.selectionLayer.getColumnPositionByIndex(0));
    Assert.assertEquals(2, this.selectionLayer.getColumnPositionByIndex(2));
    Assert.assertEquals(1, this.selectionLayer.getColumnPositionByIndex(1));
}
Also used : SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) Test(org.junit.Test)

Example 7 with SelectColumnCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.

the class MultiRowResizeCommandTest method testMultiResizeWithDownscaleOnSelection.

@Test
public void testMultiResizeWithDownscaleOnSelection() {
    GridLayer gridLayer = new DummyGridLayerStack();
    IDpiConverter dpiConverter = new AbstractDpiConverter() {

        @Override
        protected void readDpiFromDisplay() {
            this.dpi = 120;
        }
    };
    gridLayer.doCommand(new ConfigureScalingCommand(dpiConverter, dpiConverter));
    setClientAreaProvider(gridLayer);
    // select columns
    gridLayer.doCommand(new SelectColumnCommand(gridLayer, 3, 1, false, false));
    gridLayer.doCommand(new SelectColumnCommand(gridLayer, 4, 1, false, true));
    gridLayer.doCommand(new SelectColumnCommand(gridLayer, 5, 1, false, true));
    // scaling enabled, therefore default height of 20 pixels is up scaled
    // to 25
    assertEquals(25, gridLayer.getRowHeightByPosition(2));
    assertEquals(25, gridLayer.getRowHeightByPosition(3));
    assertEquals(25, gridLayer.getRowHeightByPosition(4));
    assertEquals(25, gridLayer.getRowHeightByPosition(5));
    assertEquals(25, gridLayer.getRowHeightByPosition(6));
    // select rows
    gridLayer.doCommand(new SelectRowsCommand(gridLayer, 1, new int[] { 3, 4, 5 }, false, true, -1));
    // resize one of the selected columns
    RowResizeCommand columnResizeCommand = new RowResizeCommand(gridLayer, 3, 50, true);
    gridLayer.doCommand(columnResizeCommand);
    // command executed with down scaling enabled, therefore set height 50
    // is first down scaled on setting the value and then up scaled to 50
    // again on accessing the height
    assertEquals(25, gridLayer.getRowHeightByPosition(2));
    assertEquals(50, gridLayer.getRowHeightByPosition(3));
    assertEquals(50, gridLayer.getRowHeightByPosition(4));
    assertEquals(50, gridLayer.getRowHeightByPosition(5));
    assertEquals(25, gridLayer.getRowHeightByPosition(6));
}
Also used : AbstractDpiConverter(org.eclipse.nebula.widgets.nattable.layer.AbstractDpiConverter) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) IDpiConverter(org.eclipse.nebula.widgets.nattable.layer.IDpiConverter) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ConfigureScalingCommand(org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 8 with SelectColumnCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.

the class MultiColumnResizeCommandTest method testMultiResizeWithoutDownscaleOnSelection.

@Test
public void testMultiResizeWithoutDownscaleOnSelection() {
    DummyGridLayerStack gridLayer = new DummyGridLayerStack();
    IDpiConverter dpiConverter = new AbstractDpiConverter() {

        @Override
        protected void readDpiFromDisplay() {
            this.dpi = 120;
        }
    };
    gridLayer.doCommand(new ConfigureScalingCommand(dpiConverter, dpiConverter));
    setClientAreaProvider(gridLayer);
    // scaling enabled, therefore default width of 100 pixels is up scaled
    // to 125
    assertEquals(125, gridLayer.getColumnWidthByPosition(2));
    assertEquals(125, gridLayer.getColumnWidthByPosition(3));
    assertEquals(125, gridLayer.getColumnWidthByPosition(4));
    assertEquals(125, gridLayer.getColumnWidthByPosition(5));
    assertEquals(125, gridLayer.getColumnWidthByPosition(6));
    // select columns
    gridLayer.doCommand(new SelectColumnCommand(gridLayer, 3, 1, false, false));
    gridLayer.doCommand(new SelectColumnCommand(gridLayer, 4, 1, false, true));
    gridLayer.doCommand(new SelectColumnCommand(gridLayer, 5, 1, false, true));
    // resize one of the selected columns
    ColumnResizeCommand columnResizeCommand = new ColumnResizeCommand(gridLayer, 3, 150);
    gridLayer.doCommand(columnResizeCommand);
    // command executed with down scaling disabled, therefore set width 150
    // is up scaled to 188
    assertEquals(125, gridLayer.getColumnWidthByPosition(2));
    assertEquals(188, gridLayer.getColumnWidthByPosition(3));
    assertEquals(188, gridLayer.getColumnWidthByPosition(4));
    assertEquals(188, gridLayer.getColumnWidthByPosition(5));
    assertEquals(125, gridLayer.getColumnWidthByPosition(6));
}
Also used : AbstractDpiConverter(org.eclipse.nebula.widgets.nattable.layer.AbstractDpiConverter) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) IDpiConverter(org.eclipse.nebula.widgets.nattable.layer.IDpiConverter) ConfigureScalingCommand(org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand) Test(org.junit.Test)

Example 9 with SelectColumnCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.

the class ColumnSelectionTest method onlyOneCellSelectedAtAnyTime.

@Test
public void onlyOneCellSelectedAtAnyTime() {
    this.selectionLayer.getSelectionModel().setMultipleSelectionAllowed(false);
    this.selectionLayer.clear();
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 1, 0, false, true));
    Collection<PositionCoordinate> cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    assertEquals(1, cells.size());
    assertEquals(1, this.selectionLayer.getSelectedColumnPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedColumnPositions()[0]);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    // select another column with control mask
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 2, 0, false, true));
    cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    assertEquals(1, cells.size());
    assertEquals(1, this.selectionLayer.getSelectedColumnPositions().length);
    assertEquals(2, this.selectionLayer.getSelectedColumnPositions()[0]);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    // select additional columns with shift mask
    // only the last column should be selected afterwards
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 5, 0, true, false));
    cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    assertEquals(1, cells.size());
    assertEquals(1, this.selectionLayer.getSelectedColumnPositions().length);
    assertEquals(5, this.selectionLayer.getSelectedColumnPositions()[0]);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
}
Also used : SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 10 with SelectColumnCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.

the class ColumnSelectionTest method shouldUpdateAnchorIfDeselected.

@Test
public void shouldUpdateAnchorIfDeselected() {
    // start from a clear selection state
    this.selectionLayer.clear();
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 2, 0, true, false));
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 4, 0, true, false));
    assertEquals(2, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getRowPosition());
    for (int col = 2; col <= 4; col++) {
        assertTrue("column " + col + " not fully selected", this.selectionLayer.isColumnPositionFullySelected(col));
    }
    // deselect column 2
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 2, 0, false, true));
    assertEquals(3, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getRowPosition());
    assertFalse("column 2 fully selected", this.selectionLayer.isColumnPositionFullySelected(2));
    for (int col = 3; col <= 4; col++) {
        assertTrue("column " + col + " not fully selected", this.selectionLayer.isColumnPositionFullySelected(col));
    }
}
Also used : SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) Test(org.junit.Test)

Aggregations

SelectColumnCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand)21 Test (org.junit.Test)21 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)4 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)3 AbstractDpiConverter (org.eclipse.nebula.widgets.nattable.layer.AbstractDpiConverter)3 IDpiConverter (org.eclipse.nebula.widgets.nattable.layer.IDpiConverter)3 ConfigureScalingCommand (org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand)3 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)3 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)2 EventList (ca.odell.glazedlists.EventList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)1 ColumnHeaderSelectionEvent (org.eclipse.nebula.widgets.nattable.grid.layer.event.ColumnHeaderSelectionEvent)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)1