Search in sources :

Example 16 with SelectColumnCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand 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)

Example 17 with SelectColumnCommand

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

the class MultiColumnResizeCommandTest 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 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));
    // resize one of the selected columns
    ColumnResizeCommand columnResizeCommand = new ColumnResizeCommand(gridLayer, 3, 150, true);
    gridLayer.doCommand(columnResizeCommand);
    // command executed with down scaling enabled, therefore set width 150
    // is first down scaled on setting the value and then up scaled to 150
    // again on accessing the width
    assertEquals(125, gridLayer.getColumnWidthByPosition(2));
    assertEquals(150, gridLayer.getColumnWidthByPosition(3));
    assertEquals(150, gridLayer.getColumnWidthByPosition(4));
    assertEquals(150, 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) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ConfigureScalingCommand(org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand) Test(org.junit.Test)

Example 18 with SelectColumnCommand

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

the class SelectionEventsTest method shouldFireColumnSelectionEvent.

@Test
public void shouldFireColumnSelectionEvent() throws Exception {
    this.nattable.doCommand(new SelectColumnCommand(this.nattable, 5, 5, NO_SHIFT, NO_CTRL));
    assertEquals(2, this.listener.getEventsCount());
    assertTrue(this.listener.containsInstanceOf(ColumnSelectionEvent.class));
    assertTrue(this.listener.containsInstanceOf(ColumnHeaderSelectionEvent.class));
    ColumnSelectionEvent event = (ColumnSelectionEvent) this.listener.getReceivedEvents().get(0);
    assertEquals(5, event.getColumnPositionRanges().iterator().next().start);
    assertEquals(6, event.getColumnPositionRanges().iterator().next().end);
}
Also used : SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) ColumnSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.ColumnSelectionEvent) ColumnHeaderSelectionEvent(org.eclipse.nebula.widgets.nattable.grid.layer.event.ColumnHeaderSelectionEvent) Test(org.junit.Test)

Example 19 with SelectColumnCommand

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

the class ColumnSelectionTest method shouldSetAnchorWithInitialShiftKeyPressed.

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

Example 20 with SelectColumnCommand

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

the class ColumnSelectionTest method shouldExtendFromAnchorWithShiftKeyPressed.

@Test
public void shouldExtendFromAnchorWithShiftKeyPressed() {
    // start from a clear selection state
    this.selectionLayer.clear();
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 4, 0, true, false));
    // select columns to the left
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 2, 0, true, false));
    for (int col = 2; col <= 4; col++) {
        assertTrue("column " + col + " not fully selected", this.selectionLayer.isColumnPositionFullySelected(col));
    }
    assertFalse("column 5 fully selected", this.selectionLayer.isColumnPositionFullySelected(5));
    // select columns to the right
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 6, 0, true, false));
    assertFalse("column 2 fully selected", this.selectionLayer.isColumnPositionFullySelected(2));
    assertFalse("column 3 fully selected", this.selectionLayer.isColumnPositionFullySelected(3));
    for (int col = 4; col <= 6; 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