use of org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand 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());
}
use of org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerTest 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.datachange.command.DiscardDataChangesCommand 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());
}
use of org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand in project nebula.widgets.nattable by eclipse.
the class _5016_DataChangeLayerExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
final List<Person> data = PersonService.getPersons(10);
// create the body layer stack
IDataProvider bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
// add a DataChangeLayer that tracks data changes but directly updates
// the underlying data model
DataChangeLayer dataChangeLayer = new DataChangeLayer(bodyDataLayer, new PointKeyHandler(), false);
// we register a special command handler to perform custom changes on
// save
dataChangeLayer.registerCommandHandler(new SaveDataChangesCommandHandler(dataChangeLayer) {
@Override
public boolean doCommand(ILayer targetLayer, SaveDataChangesCommand command) {
if (MessageDialog.openQuestion(parent.getShell(), "Save data", "Do you really want to save to database?")) {
// you would implement the storage to database here
System.out.println("We save the data to the database");
return super.doCommand(targetLayer, command);
}
return true;
}
});
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(dataChangeLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 40, 20), viewportLayer, selectionLayer);
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new EditorConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
export.setText("Discard changes");
export.setEnabled(true);
export.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new DiscardDataChangesCommand());
}
});
}
}).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
export.setText("Save changes");
export.setEnabled(true);
export.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new SaveDataChangesCommand());
}
});
}
});
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand in project nebula.widgets.nattable by eclipse.
the class _5017_DataChangeLayerTempStorageExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
final List<Person> data = PersonService.getPersons(10);
// create the body layer stack
IDataProvider bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
// add a DataChangeLayer that tracks data changes but directly updates
// the underlying data model
DataChangeLayer dataChangeLayer = new DataChangeLayer(bodyDataLayer, new PointKeyHandler(), true);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(dataChangeLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 40, 20), viewportLayer, selectionLayer);
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new EditorConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
export.setText("Discard changes");
export.setEnabled(true);
export.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new DiscardDataChangesCommand());
}
});
}
}).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
export.setText("Save changes");
export.setEnabled(true);
export.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new SaveDataChangesCommand());
}
});
}
});
}
});
natTable.configure();
return natTable;
}
Aggregations