Search in sources :

Example 16 with SelectRowsCommand

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

the class RowSelectionIntegrationTest method testColumnSelectionProcessing.

@SuppressWarnings("rawtypes")
@Test
public void testColumnSelectionProcessing() {
    final List selectedObjects = new ArrayList();
    // add a listener to see how many rows are selected
    this.selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            selectedObjects.addAll(selection.toList());
        }
    });
    // first execute column selection with default configuration to see that
    // all rows get selected
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 1, 0, false, false));
    assertEquals(10, selectedObjects.size());
    // now clear set the flag for column selection processing to false and
    // fire the event again
    selectedObjects.clear();
    this.selectionProvider.setProcessColumnSelection(false);
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 1, 0, false, false));
    assertEquals(0, selectedObjects.size());
    // now select a cell to verify that other selections are still processed
    this.selectionLayer.doCommand(new SelectRowsCommand(this.selectionLayer, 1, 1, false, false));
    assertEquals(1, selectedObjects.size());
}
Also used : SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) EventList(ca.odell.glazedlists.EventList) List(java.util.List) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 17 with SelectRowsCommand

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

the class MultiRowResizeCommandTest 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 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);
    gridLayer.doCommand(columnResizeCommand);
    // command executed with down scaling disabled, therefore set height 50
    // is up scaled to 63
    assertEquals(25, gridLayer.getRowHeightByPosition(2));
    assertEquals(63, gridLayer.getRowHeightByPosition(3));
    assertEquals(63, gridLayer.getRowHeightByPosition(4));
    assertEquals(63, 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) IDpiConverter(org.eclipse.nebula.widgets.nattable.layer.IDpiConverter) ConfigureScalingCommand(org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 18 with SelectRowsCommand

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldOnlyRemoveSelectionForDeleted.

@Test
public void shouldOnlyRemoveSelectionForDeleted() {
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, new int[] { 1, 2 }, true, false, 1));
    assertEquals(2, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(2, this.selectionLayer.getSelectedRowCount());
    // Ford motor at top and selected
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
    boolean fordFound = false;
    boolean alphabetFound = false;
    for (Range selection : this.selectionLayer.getSelectedRowPositions()) {
        for (int i = selection.start; i < selection.end; i++) {
            if ("B Ford Motor".equals(this.listFixture.get(i).getSecurity_description())) {
                fordFound = true;
            }
            if ("A Alphabet Co.".equals(this.listFixture.get(i).getSecurity_description())) {
                alphabetFound = true;
            }
        }
    }
    assertTrue("B Ford Motor not found", fordFound);
    assertTrue("A Alphabet Co. not found", alphabetFound);
    this.listFixture.remove(0);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
    // another value on top now
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("A Alphabet Co.", getSelected().getSecurity_description());
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 19 with SelectRowsCommand

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRetainRowSelectionOnMove.

@Test
public void shouldRetainRowSelectionOnMove() throws Exception {
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    // Ford motor at top and selected
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    RowDataFixture ford = getSelected();
    // move selected to the bottom
    this.listFixture.remove(ford);
    this.listFixture.add(ford);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
    // Tata motors at top but Ford motors still selected
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    assertEquals(this.listFixture.size() - 1, this.selectionLayer.getFullySelectedRowPositions()[0]);
}
Also used : StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 20 with SelectRowsCommand

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveSelectionOnDelete.

@Test
public void shouldRemoveSelectionOnDelete() {
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    // Ford motor at top and selected
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    this.listFixture.remove(0);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
    // another value on top now
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
    // selection should be empty since the selected row was deleted
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) 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