Search in sources :

Example 1 with RowDeleteEvent

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

the class DataChangeLayerIdIndexTest method shouldUpdateOnMultiRowDelete.

@Test
public void shouldUpdateOnMultiRowDelete() {
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 3, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 5, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 7, "Lovejoy"));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 9, "Lovejoy"));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 0));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 3));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 4));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 5));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 6));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 7));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 8));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 9));
    // delete all the Simpsons
    this.dataModel.remove(8);
    this.dataModel.remove(6);
    this.dataModel.remove(4);
    this.dataModel.remove(2);
    this.dataModel.remove(0);
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, new Range(0, 1), new Range(2, 3), new Range(4, 5), new Range(6, 7), new Range(8, 9)));
    assertEquals(13, this.dataModel.size());
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 0));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 2));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 3));
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 4));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 0));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 1));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 2));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 3));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 4));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 0).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 3).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 4).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 5).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 6).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 7).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 8).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 9).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 10).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 11).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 12).hasLabel(DataChangeLayer.DIRTY));
    assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertTrue("Row 0 is not dirty", this.dataChangeLayer.isRowDirty(0));
    assertTrue("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(1));
    assertTrue("Row 2 is not dirty", this.dataChangeLayer.isRowDirty(2));
    assertTrue("Row 3 is not dirty", this.dataChangeLayer.isRowDirty(3));
    assertTrue("Row 4 is not dirty", this.dataChangeLayer.isRowDirty(4));
    assertFalse("Row 5 is dirty", this.dataChangeLayer.isRowDirty(5));
    assertFalse("Row 6 is dirty", this.dataChangeLayer.isRowDirty(6));
    assertFalse("Row 7 is dirty", this.dataChangeLayer.isRowDirty(7));
    assertFalse("Row 8 is dirty", this.dataChangeLayer.isRowDirty(8));
    assertFalse("Row 9 is dirty", this.dataChangeLayer.isRowDirty(9));
    assertFalse("Row 10 is dirty", this.dataChangeLayer.isRowDirty(10));
    assertFalse("Row 11 is dirty", this.dataChangeLayer.isRowDirty(11));
    assertFalse("Row 12 is dirty", this.dataChangeLayer.isRowDirty(12));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 0));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 1));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 2));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 3));
    assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 4));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 5));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(0, 2));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(2, 3));
    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) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 2 with RowDeleteEvent

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

the class DataChangeLayerIdIndexTest 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 3 with RowDeleteEvent

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

the class DataChangeLayerIdIndexTest 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 the row that has changes
    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 4 with RowDeleteEvent

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

the class DataChangeLayerTempStorageTest 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("Simpson", this.dataLayer.getDataValue(1, 9));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(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("Simpson", 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 5 with RowDeleteEvent

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

the class CompositeFreezeLayerHideShowTest method testFreezeDeleteRows.

@Test
public void testFreezeDeleteRows() {
    this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 3));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(4, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(3, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(1, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(4, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(80, this.viewportLayer.getMinimumOrigin().getY());
    // fake a multi row delete with no details on which rows are deleted
    // technically the same as collapsing or filtering a GlazedLists
    this.rowCount = 2;
    this.dataLayer.fireLayerEvent(new RowDeleteEvent(this.dataLayer, new ArrayList<Range>()));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(3, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(0, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(-1, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // since the RowHideShowLayer is involved in the current composition
    // the number of rows is cached and we need to update this before reset
    this.rowCount = 5;
    this.dataLayer.fireLayerEvent(new RowInsertEvent(this.dataLayer, new Range(0, 2)));
    reset();
}
Also used : FreezeRowCommand(org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand) RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) 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)

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