Search in sources :

Example 6 with SaveDataChangesCommand

use of org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand in project nebula.widgets.nattable by eclipse.

the class DataChangeLayerTest 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());
}
Also used : SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 7 with SaveDataChangesCommand

use of org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand 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());
}
Also used : SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 8 with SaveDataChangesCommand

use of org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand in project nebula.widgets.nattable by eclipse.

the class DataChangeLayerTempStorageTest 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("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 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 9 with SaveDataChangesCommand

use of org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand in project nebula.widgets.nattable by eclipse.

the class DataChangeLayerTempStorageTest method shouldSaveChanges.

@Test
public void shouldSaveChanges() {
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, "Lovejoy"));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 1));
    this.dataChangeLayer.doCommand(new SaveDataChangesCommand());
    assertEquals("Lovejoy", this.dataLayer.getDataValue(1, 1));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 1));
    assertFalse("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(1));
    assertFalse("Cell is not 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());
    assertEquals(1, this.listener.getReceivedEvents().size());
    assertTrue(this.listener.getReceivedEvents().get(0) instanceof DataUpdateEvent);
}
Also used : SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) DataUpdateEvent(org.eclipse.nebula.widgets.nattable.edit.event.DataUpdateEvent) Test(org.junit.Test)

Example 10 with SaveDataChangesCommand

use of org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand in project nebula.widgets.nattable by eclipse.

the class DefaultDataChangeConfiguration method configureUiBindings.

@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
    uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.MOD1, 's'), new IKeyAction() {

        @Override
        public void run(NatTable natTable, KeyEvent event) {
            natTable.doCommand(new SaveDataChangesCommand());
        }
    });
    uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.MOD1, 'd'), new IKeyAction() {

        @Override
        public void run(NatTable natTable, KeyEvent event) {
            natTable.doCommand(new DiscardDataChangesCommand());
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) DiscardDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand) KeyEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.KeyEventMatcher) IKeyAction(org.eclipse.nebula.widgets.nattable.ui.action.IKeyAction) SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) NatTable(org.eclipse.nebula.widgets.nattable.NatTable)

Aggregations

SaveDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand)10 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)6 Test (org.junit.Test)6 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DiscardDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand)4 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)4 HashMap (java.util.HashMap)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)3 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)3 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)3 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)3 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)3 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)3 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)3 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)3 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)3 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)3 IMenuItemProvider (org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider)3 PopupMenuBuilder (org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)3