use of org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerGlazedListsTest method shouldRetainCollapsedStateOnFilter.
@Test
public void shouldRetainCollapsedStateOnFilter() throws InterruptedException, ExecutionException, TimeoutException {
// collapse first level of first item
this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
assertEquals(7, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.getCollapsedNodes().size());
HierarchicalTreeNode node = this.treeLayer.getCollapsedNodes().iterator().next();
assertEquals(0, node.rowIndex);
assertEquals(0, node.columnIndex);
assertNotNull(node.rowObject);
assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 1));
// filter out BMW which is the first row that is collapsed
this.filterList.setMatcher(new Matcher<HierarchicalWrapper>() {
@Override
public boolean matches(HierarchicalWrapper item) {
return !((Car) item.getObject(0)).getManufacturer().equals("BMW");
}
});
// refresh the layers to ensure the state is current
// sometimes in the tests list change events where missing
this.treeLayer.doCommand(new StructuralRefreshCommand());
assertEquals(6, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.getCollapsedNodes().size());
node = this.treeLayer.getCollapsedNodes().iterator().next();
// row index -1 as we retain but the object is not available anymore
assertEquals(-1, node.rowIndex);
assertEquals(0, node.columnIndex);
assertNotNull(node.rowObject);
// nothing hidden as it is filtered
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 0));
this.filterList.setMatcher(null);
// refresh the layers to ensure the state is current
// sometimes in the tests list change events where missing
this.treeLayer.doCommand(new StructuralRefreshCommand());
// bring it back to is previous state and the collapsed state is
// restored
assertEquals(7, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.getCollapsedNodes().size());
node = this.treeLayer.getCollapsedNodes().iterator().next();
assertEquals(0, node.rowIndex);
assertEquals(0, node.columnIndex);
assertNotNull(node.rowObject);
assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 1));
}
use of org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerGlazedListsTest method shouldClearCollapsedStateOnFilter.
@Test
public void shouldClearCollapsedStateOnFilter() throws InterruptedException, ExecutionException, TimeoutException {
// remove deleted objects from the collection
this.treeLayer.setRetainRemovedRowObjectNodes(false);
// collapse first level of first item
this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
assertEquals(7, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.getCollapsedNodes().size());
HierarchicalTreeNode node = this.treeLayer.getCollapsedNodes().iterator().next();
assertEquals(0, node.rowIndex);
assertEquals(0, node.columnIndex);
assertNotNull(node.rowObject);
assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 1));
// filter out BMW which is the first row that is collapsed
this.filterList.setMatcher(new Matcher<HierarchicalWrapper>() {
@Override
public boolean matches(HierarchicalWrapper item) {
return !((Car) item.getObject(0)).getManufacturer().equals("BMW");
}
});
// refresh the layers to ensure the state is current
// sometimes in the tests list change events where missing
this.treeLayer.doCommand(new StructuralRefreshCommand());
assertEquals(6, this.treeLayer.getRowCount());
// nothing collapsed anymore as collapsed node was removed/filtered
assertEquals(0, this.treeLayer.getCollapsedNodes().size());
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 0));
this.filterList.setMatcher(null);
// refresh the layers to ensure the state is current
// sometimes in the tests list change events where missing
this.treeLayer.doCommand(new StructuralRefreshCommand());
// no restore of collapsed nodes
assertEquals(11, this.treeLayer.getRowCount());
assertEquals(0, this.treeLayer.getCollapsedNodes().size());
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("BMW", this.treeLayer.getDataValueByPosition(1, 1));
}
use of org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerTempStorageTest method shouldClearOnStructuralChange.
@Test
public void shouldClearOnStructuralChange() {
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));
// clear locally stored data changes
this.dataChangeLayer.doCommand(new StructuralRefreshCommand());
assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
assertEquals("Simpson", 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());
}
use of org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand in project nebula.widgets.nattable by eclipse.
the class DataLayer method doCommand.
@Override
public boolean doCommand(ILayerCommand command) {
if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
boolean refresh = false;
if (isColumnPercentageSizing()) {
this.columnWidthConfig.calculatePercentages(this.columnWidthConfig.downScale(clientAreaResizeCommand.getCalcArea().width), getColumnCount());
refresh = true;
}
if (isRowPercentageSizing()) {
this.rowHeightConfig.calculatePercentages(this.rowHeightConfig.downScale(clientAreaResizeCommand.getCalcArea().height), getRowCount());
refresh = true;
}
if (refresh) {
fireLayerEvent(new ResizeStructuralRefreshEvent(this));
}
return refresh;
} else if (command instanceof StructuralRefreshCommand) {
// that the percentage values are re-calculated
if (isColumnPercentageSizing()) {
this.columnWidthConfig.updatePercentageValues(getColumnCount());
}
if (isRowPercentageSizing()) {
this.rowHeightConfig.updatePercentageValues(getRowCount());
}
}
return super.doCommand(command);
}
Aggregations