Search in sources :

Example 11 with SelectRowsCommand

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

the class RowSelectionTest method shouldUpdateAnchorIfDeselected.

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

Example 12 with SelectRowsCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand 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 13 with SelectRowsCommand

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

the class RowSelectionIntegrationTest method shouldPreserveRowSelectionOnSort.

@Test
public void shouldPreserveRowSelectionOnSort() throws Exception {
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    // Unsorted order - Ford motor at top
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 2).toString());
    assertEquals("C General Electric Co", this.nattable.getDataValueByPosition(2, 3).toString());
    // Select 'Ford Motor'
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    // Sort
    this.nattable.doCommand(new SortColumnCommand(this.nattable, 2, false));
    // Sorted order - Alphabet co. at top
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 2).toString());
    assertEquals("C General Electric Co", this.nattable.getDataValueByPosition(2, 3).toString());
    // Ford motor still selected
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
}
Also used : SortColumnCommand(org.eclipse.nebula.widgets.nattable.sort.command.SortColumnCommand) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 14 with SelectRowsCommand

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

the class RowSelectionIntegrationTest method shouldPreserveRowSelectionOnDataUpdates.

@Test
public void shouldPreserveRowSelectionOnDataUpdates() throws Exception {
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    this.eventListFixture.add(0, RowDataFixture.getInstance("Tata motors", "A"));
    // Event layer will conflate list change events
    Thread.sleep(100);
    // Tata motors at top but Ford motors still selected
    assertEquals("Tata motors", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
}
Also used : SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 15 with SelectRowsCommand

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

the class RowSelectionIntegrationTest method onlySelectRowEventsFired.

@Test
public void onlySelectRowEventsFired() {
    this.nattable.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof CellSelectionEvent) {
                fail("CellSelectionEvent fired for row selection");
            }
        }
    });
    this.nattable.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 0, false, false));
    // the second call first clears the selection and then applies the new
    // one clearing by default also fires a CellSelectionEvent with negative
    // values
    this.nattable.doCommand(new SelectRowsCommand(this.selectionLayer, 0, 3, false, false));
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) CellSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Aggregations

SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)35 Test (org.junit.Test)32 RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)12 StructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent)9 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)5 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)5 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)5 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)5 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)2 AbstractDpiConverter (org.eclipse.nebula.widgets.nattable.layer.AbstractDpiConverter)2 IDpiConverter (org.eclipse.nebula.widgets.nattable.layer.IDpiConverter)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)2 EventList (ca.odell.glazedlists.EventList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1