use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerIdIndexTest method shouldUpdateChangeOnSortAndSaveWithTemp.
@Test
public void shouldUpdateChangeOnSortAndSaveWithTemp() {
// enable temp data storage to test update on save
this.dataChangeLayer = new DataChangeLayer(this.dataLayer, new IdIndexKeyHandler<>(this.dataProvider, new IRowIdAccessor<Person>() {
@Override
public Serializable getRowId(Person rowObject) {
return rowObject.getId();
}
}), true);
assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 2, "Zoolander"));
assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
assertEquals("Zoolander", this.dataChangeLayer.getDataValueByPosition(1, 2));
// sort via firstname
// NOTE: this is because we are storing the data temporary and therefore
// sorting for lastname would not respect the shown data.
this.dataLayer.setDataValueByPosition(0, 2, "Yosefine");
Collections.sort(this.dataModel, new Comparator<Person>() {
@Override
public int compare(Person o1, Person o2) {
return o1.getFirstName().compareTo(o2.getFirstName());
}
});
// 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("Simpson", 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 SaveDataChangesCommand());
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));
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.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.
the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithRowStructuralRefresh.
@Test
public void shouldClearSelectionOnClearingTableWithRowStructuralRefresh() throws Exception {
List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
NatTable nattable = new NatTableFixture(gridLayer, false);
DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
// test SelectionModel updates
assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
// Ford motor at top and selected
assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
// clear the table
listFixture.clear();
// fire event to trigger structural refresh
bodyDataLayer.fireLayerEvent(new RowStructuralRefreshEvent(bodyDataLayer));
// row count of 1 for NatTable because of header
assertEquals(1, nattable.getRowCount());
assertTrue("selection is not empty", selectionLayer.getSelectedCells().isEmpty());
assertTrue("selection model is not empty", selectionLayer.getSelectionModel().getSelections().isEmpty());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithRowStructuralRefresh.
@Test
public void shouldClearSelectionOnClearingTableWithRowStructuralRefresh() throws Exception {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
// Ford motor at top and selected
assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("B Ford Motor", getSelected().getSecurity_description());
// clear the table
this.listFixture.clear();
// fire event to trigger structural refresh
this.bodyDataLayer.fireLayerEvent(new RowStructuralRefreshEvent(this.bodyDataLayer));
// row count of 1 for NatTable because of header
assertEquals(1, this.nattable.getRowCount());
assertEquals(0, this.selectionLayer.getSelectedRowCount());
assertTrue("selection model is not empty", this.selectionLayer.getSelectionModel().getSelections().isEmpty());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.
the class FilterRowDataLayer method doCommand.
@Override
public boolean doCommand(ILayerCommand command) {
boolean handled = false;
if (command instanceof ClearFilterCommand && command.convertToTargetLayer(this)) {
int columnPosition = ((ClearFilterCommand) command).getColumnPosition();
setDataValueByPosition(columnPosition, 0, null);
handled = true;
} else if (command instanceof ClearAllFiltersCommand) {
getFilterRowDataProvider().clearAllFilters();
handled = true;
}
if (handled) {
fireLayerEvent(new RowStructuralRefreshEvent(this));
return true;
} else {
return super.doCommand(command);
}
}
use of org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent in project nebula.widgets.nattable by eclipse.
the class ColumnGroupHeaderLayer method setCalculateHeight.
public void setCalculateHeight(boolean calculateHeight) {
boolean changed = calculateHeight != this.calculateHeight;
this.calculateHeight = calculateHeight;
if (changed) {
if (calculateHeight) {
this.model.registerColumnGroupModelListener(this.modelChangeListener);
} else {
this.model.unregisterColumnGroupModelListener(this.modelChangeListener);
}
this.fireLayerEvent(new RowStructuralRefreshEvent(this));
}
}
Aggregations