Search in sources :

Example 6 with RowDeleteEvent

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

the class DataChangeLayerTest method shouldRemoveChangeOnRowDelete.

@Test
public void shouldRemoveChangeOnRowDelete() {
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    assertEquals("Homer", this.dataLayer.getDataValue(0, 2));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 2, "Lovejoy"));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 2));
    assertEquals("Homer", this.dataLayer.getDataValue(0, 2));
    // delete the row that has changes
    this.dataModel.remove(2);
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, 2));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 2));
    assertEquals("Bart", this.dataLayer.getDataValue(0, 2));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 1 is dirty", this.dataChangeLayer.isRowDirty(2));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 2));
    assertTrue("changed columns are not empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertTrue("changed rows are not empty", this.dataChangeLayer.changedRows.isEmpty());
    assertTrue("changes are not empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Test(org.junit.Test)

Example 7 with RowDeleteEvent

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

the class DataChangeLayerTest method shouldSaveAfterDelete.

@Test
public void shouldSaveAfterDelete() {
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 9));
    assertEquals("Flanders", this.dataLayer.getDataValue(1, 10));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 9, "Lovejoy"));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 9));
    assertEquals("Flanders", this.dataLayer.getDataValue(1, 10));
    // delete a row before the change
    this.dataModel.remove(2);
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 8));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 8));
    assertEquals("Flanders", this.dataLayer.getDataValue(1, 9));
    assertEquals("Flanders", this.dataChangeLayer.getDataValueByPosition(1, 9));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 8).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertTrue("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(8));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 8));
    assertFalse("changed columns are empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertFalse("changed rows are empty", this.dataChangeLayer.changedRows.isEmpty());
    assertFalse("changes are empty", this.dataChangeLayer.dataChanges.isEmpty());
    // now discard and check that previous state is restored correctly
    this.dataChangeLayer.doCommand(new SaveDataChangesCommand());
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 8));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 8));
    assertEquals("Flanders", this.dataLayer.getDataValue(1, 9));
    assertEquals("Flanders", this.dataChangeLayer.getDataValueByPosition(1, 9));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 8).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 1 is dirty", this.dataChangeLayer.isRowDirty(8));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 8));
    assertTrue("changed columns are not empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertTrue("changed rows are not empty", this.dataChangeLayer.changedRows.isEmpty());
    assertTrue("changes are not empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Test(org.junit.Test)

Example 8 with RowDeleteEvent

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

the class DataChangeLayerTest method shouldDiscardAfterDelete.

@Test
public void shouldDiscardAfterDelete() {
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 9));
    assertEquals("Flanders", this.dataLayer.getDataValue(1, 10));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 9, "Lovejoy"));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 9));
    assertEquals("Flanders", this.dataLayer.getDataValue(1, 10));
    // delete a row before the change
    this.dataModel.remove(2);
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 8));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 8));
    assertEquals("Flanders", this.dataLayer.getDataValue(1, 9));
    assertEquals("Flanders", this.dataChangeLayer.getDataValueByPosition(1, 9));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 8).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertTrue("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(8));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 8));
    assertFalse("changed columns are empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertFalse("changed rows are empty", this.dataChangeLayer.changedRows.isEmpty());
    assertFalse("changes are empty", this.dataChangeLayer.dataChanges.isEmpty());
    // now discard and check that previous state is restored correctly
    this.dataChangeLayer.doCommand(new DiscardDataChangesCommand());
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 8));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 8));
    assertEquals("Flanders", this.dataLayer.getDataValue(1, 9));
    assertEquals("Flanders", this.dataChangeLayer.getDataValueByPosition(1, 9));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 8).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 1 is dirty", this.dataChangeLayer.isRowDirty(8));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 8));
    assertTrue("changed columns are not empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertTrue("changed rows are not empty", this.dataChangeLayer.changedRows.isEmpty());
    assertTrue("changes are not empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : DiscardDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Test(org.junit.Test)

Example 9 with RowDeleteEvent

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

the class DataChangeLayerTest method shouldUpdateChangeOnRowDelete.

@Test
public void shouldUpdateChangeOnRowDelete() {
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 3));
    assertEquals("Bart", this.dataLayer.getDataValue(0, 3));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 3, "Lovejoy"));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    assertEquals("Homer", this.dataLayer.getDataValue(0, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 3));
    assertEquals("Bart", this.dataLayer.getDataValue(0, 3));
    // delete a row before the change
    this.dataModel.remove(2);
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 2));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 2));
    assertEquals("Bart", this.dataLayer.getDataValue(0, 2));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertTrue("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(2));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 2));
    assertFalse("changed columns are empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertFalse("changed rows are empty", this.dataChangeLayer.changedRows.isEmpty());
    assertFalse("changes are empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Test(org.junit.Test)

Example 10 with RowDeleteEvent

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

the class RowHideShowLayerStructuralChangeEventTest method testHandleRowDeleteEvent.

@Test
public void testHandleRowDeleteEvent() {
    // 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 row index 1: value "two")
    this.contents.remove(1);
    this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, 1));
    assertEquals(3, this.rowHideShowLayer.getRowCount());
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(2, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(3));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 1));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 2));
}
Also used : ArrayList(java.util.ArrayList) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) 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