Search in sources :

Example 11 with RowDeleteEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.

the class RowHideShowLayerStructuralChangeEventTest method testHandleMultipleRowDeleteEvent.

@Test
public void testHandleMultipleRowDeleteEvent() {
    // test start order: 0 1 2 3 4
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(2, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(3));
    assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(4));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
    assertEquals("three", this.rowHideShowLayer.getDataValueByPosition(0, 2));
    assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 3));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 4));
    // hide row at position 2: 0 1 3 4
    List<Integer> rowsToHide = new ArrayList<Integer>();
    rowsToHide.add(2);
    this.rowHideShowLayer.hideRowPositions(rowsToHide);
    assertEquals(4, this.rowHideShowLayer.getRowCount());
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(3));
    assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(4));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
    assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 2));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 3));
    // delete rows in the middle
    this.contents.remove(1);
    this.contents.remove(1);
    this.contents.remove(1);
    this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, new Range(1, 4)));
    assertEquals(2, this.rowHideShowLayer.getRowCount());
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 1));
}
Also used : ArrayList(java.util.ArrayList) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 12 with RowDeleteEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.

the class SelectionLayerStructuralChangeEventHandlerTest method shouldLeaveSelectionUnchangedIfASelectedRowIsNotModified.

@Test
public void shouldLeaveSelectionUnchangedIfASelectedRowIsNotModified() throws Exception {
    this.selectionModel.addSelection(2, 3);
    SelectionLayerStructuralChangeEventHandler handler = new SelectionLayerStructuralChangeEventHandler(this.selectionLayer);
    handler.handleLayerEvent(new RowDeleteEvent(this.dataLayer, 5));
    Assert.assertFalse(this.selectionModel.isEmpty());
    Assert.assertTrue(this.selectionModel.isRowPositionSelected(3));
}
Also used : SelectionLayerStructuralChangeEventHandler(org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Test(org.junit.Test)

Example 13 with RowDeleteEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.

the class SelectionLayerStructuralChangeEventHandlerTest method shouldLeaveSelectionUnchangedIfTheFollowingRowIsModified.

@Test
public void shouldLeaveSelectionUnchangedIfTheFollowingRowIsModified() throws Exception {
    this.selectionModel.addSelection(3, 4);
    SelectionLayerStructuralChangeEventHandler handler = new SelectionLayerStructuralChangeEventHandler(this.selectionLayer);
    handler.handleLayerEvent(new RowDeleteEvent(this.dataLayer, 5));
    Assert.assertFalse(this.selectionModel.isEmpty());
    Assert.assertTrue(this.selectionModel.isRowPositionSelected(4));
}
Also used : SelectionLayerStructuralChangeEventHandler(org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Test(org.junit.Test)

Example 14 with RowDeleteEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.

the class SelectionLayerStructuralChangeEventHandlerTest method shouldClearSelectionIfASelectedRowIsModified.

@Test
public void shouldClearSelectionIfASelectedRowIsModified() throws Exception {
    this.selectionModel.addSelection(2, 3);
    SelectionLayerStructuralChangeEventHandler handler = new SelectionLayerStructuralChangeEventHandler(this.selectionLayer);
    handler.handleLayerEvent(new RowDeleteEvent(this.dataLayer, 3));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : SelectionLayerStructuralChangeEventHandler(org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Test(org.junit.Test)

Example 15 with RowDeleteEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionIfListIsCleared.

@Test
public void shouldClearSelectionIfListIsCleared() {
    this.selectionModel.addSelection(3, 4);
    this.selectionModel.handleLayerEvent(new RowDeleteEvent(this.dataLayer, new Range(0, 9)));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Aggregations

RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)36 Test (org.junit.Test)35 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)10 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)9 ArrayList (java.util.ArrayList)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)4 SelectionLayerStructuralChangeEventHandler (org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler)4 DiscardDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand)2 SaveDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand)2 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)2 RowInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent)2 EventList (ca.odell.glazedlists.EventList)1 FilterList (ca.odell.glazedlists.FilterList)1 SortedList (ca.odell.glazedlists.SortedList)1 TransformedList (ca.odell.glazedlists.TransformedList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1