Search in sources :

Example 6 with StructuralRefreshCommand

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));
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) Test(org.junit.Test)

Example 7 with StructuralRefreshCommand

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));
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) Test(org.junit.Test)

Example 8 with StructuralRefreshCommand

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

Example 9 with StructuralRefreshCommand

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);
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) ResizeStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.ResizeStructuralRefreshEvent)

Aggregations

StructuralRefreshCommand (org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand)9 Test (org.junit.Test)8 HierarchicalTreeNode (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode)5 TreeExpandCollapseCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand)5 HierarchicalWrapper (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper)4 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)3 ClientAreaResizeCommand (org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand)1 ResizeStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.ResizeStructuralRefreshEvent)1