use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerIdIndexTest method shouldRemoveChangeOnColumnDelete.
@Test
public void shouldRemoveChangeOnColumnDelete() {
assertEquals("Homer", this.dataLayer.getDataValue(0, 2));
this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 0, 2, "Nelson"));
assertEquals("Nelson", this.dataLayer.getDataValue(0, 2));
// simulate column deletion
this.dataLayer.fireLayerEvent(new ColumnDeleteEvent(this.dataLayer, 0));
assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
assertFalse("Row 2 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());
}
use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerIdIndexTest method shouldUpdateChangeOnSortAndDiscard.
@Test
public void shouldUpdateChangeOnSortAndDiscard() {
assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 2, "Zoolander"));
assertEquals("Zoolander", this.dataLayer.getDataValue(1, 2));
// sort
Collections.sort(this.dataModel, new Comparator<Person>() {
@Override
public int compare(Person o1, Person o2) {
return o1.getLastName().compareTo(o2.getLastName());
}
});
// fire event to trigger update of cached row indexes
this.dataLayer.fireLayerEvent(new RowStructuralRefreshEvent(this.dataLayer));
// now the dirty state should be on the last row
assertEquals("Zoolander", this.dataLayer.getDataValue(1, 17));
assertEquals("Zoolander", this.dataChangeLayer.getDataValueByPosition(1, 17));
assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 17).hasLabel(DataChangeLayer.DIRTY));
assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
assertFalse("Row 2 is dirty", this.dataChangeLayer.isRowDirty(2));
assertTrue("Row 17 is not dirty", this.dataChangeLayer.isRowDirty(17));
assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 17));
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());
// check if discard is applied correctly
this.dataChangeLayer.doCommand(new DiscardDataChangesCommand());
assertEquals("Simpson", this.dataLayer.getDataValue(1, 17));
assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 17));
assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 17).hasLabel(DataChangeLayer.DIRTY));
assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
assertFalse("Row 2 is dirty", this.dataChangeLayer.isRowDirty(2));
assertFalse("Row 17 is dirty", this.dataChangeLayer.isRowDirty(17));
assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 17));
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());
}
use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerIdIndexTest method shouldDiscardChanges.
@Test
public void shouldDiscardChanges() {
assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, "Lovejoy"));
assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
this.dataChangeLayer.doCommand(new DiscardDataChangesCommand());
assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 1));
assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
assertFalse("Row 1 is dirty", this.dataChangeLayer.isRowDirty(1));
assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 1));
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());
}
use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerIdIndexTest method shouldSaveChanges.
@Test
public void shouldSaveChanges() {
assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, "Lovejoy"));
assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
this.dataChangeLayer.doCommand(new SaveDataChangesCommand());
assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 1));
assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
assertFalse("Row 1 is dirty", this.dataChangeLayer.isRowDirty(1));
assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 1));
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());
}
use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerIdIndexTest method shouldUpdateChangeOnRowInsert.
@Test
public void shouldUpdateChangeOnRowInsert() {
this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 2, "Lovejoy"));
assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 2));
// input a new row
this.dataModel.add(2, new Person(40, "Nelson", "Muntz", Gender.MALE, false, new Date(), 100d));
this.dataLayer.fireLayerEvent(new RowInsertEvent(this.dataLayer, 2));
assertEquals("Muntz", this.dataLayer.getDataValue(1, 2));
assertEquals("Muntz", this.dataChangeLayer.getDataValueByPosition(1, 2));
assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 3));
assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 3));
assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
assertFalse("Row 1 is dirty", this.dataChangeLayer.isRowDirty(2));
assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 2));
assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 3).hasLabel(DataChangeLayer.DIRTY));
assertTrue("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
assertTrue("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(3));
assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 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());
}
Aggregations