Search in sources :

Example 6 with MultiRowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand in project nebula.widgets.nattable by eclipse.

the class TreeLayer method handleRowHideCommand.

/**
 * Checks if the given command tries to hide a row that is a node that is
 * not collapsed and has children. In that case also the child rows need to
 * be hidden.
 *
 * @param command
 *            The {@link RowHideCommand} to process
 * @return <code>true</code> if the command has been handled,
 *         <code>false</code> otherwise
 */
protected boolean handleRowHideCommand(RowHideCommand command) {
    // transform position to index
    if (command.convertToTargetLayer(this)) {
        int rowIndex = getRowIndexByPosition(command.getRowPosition());
        if (this.treeRowModel.hasChildren(rowIndex) && !this.treeRowModel.isCollapsed(rowIndex)) {
            List<Integer> childIndexes = this.treeRowModel.getChildIndexes(rowIndex);
            int[] childPositions = new int[childIndexes.size() + 1];
            childPositions[0] = command.getRowPosition();
            for (int i = 1; i < childIndexes.size() + 1; i++) {
                int childPos = getRowPositionByIndex(childIndexes.get(i - 1));
                childPositions[i] = childPos;
            }
            return super.doCommand(new MultiRowHideCommand(this, childPositions));
        }
    }
    return super.doCommand(command);
}
Also used : MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand)

Example 7 with MultiRowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand in project nebula.widgets.nattable by eclipse.

the class TreeLayer method handleMultiRowHideCommand.

/**
 * Checks if the given command tries to hide rows that are nodes that are
 * not collapsed and have children. In that case also the child rows need to
 * be hidden.
 *
 * @param command
 *            The {@link MultiRowHideCommand} to process
 * @return <code>true</code> if the command has been handled,
 *         <code>false</code> otherwise
 */
protected boolean handleMultiRowHideCommand(MultiRowHideCommand command) {
    // transform position to index
    if (command.convertToTargetLayer(this)) {
        List<Integer> rowPositionsToHide = new ArrayList<Integer>();
        for (Integer rowPos : command.getRowPositions()) {
            rowPositionsToHide.add(rowPos);
            int rowIndex = getRowIndexByPosition(rowPos);
            if (this.treeRowModel.hasChildren(rowIndex) && !this.treeRowModel.isCollapsed(rowIndex)) {
                List<Integer> childIndexes = this.treeRowModel.getChildIndexes(rowIndex);
                for (Integer childIndex : childIndexes) {
                    rowPositionsToHide.add(getRowPositionByIndex(childIndex));
                }
            }
        }
        int[] childPositions = new int[rowPositionsToHide.size()];
        for (int i = 0; i < rowPositionsToHide.size(); i++) {
            childPositions[i] = rowPositionsToHide.get(i);
        }
        return super.doCommand(new MultiRowHideCommand(this, childPositions));
    }
    return super.doCommand(command);
}
Also used : MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) ArrayList(java.util.ArrayList)

Example 8 with MultiRowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand in project nebula.widgets.nattable by eclipse.

the class CompositeFreezeLayerHideShowTest method testFreezeHideShowRowBothRegionsViewportAll.

@Test
public void testFreezeHideShowRowBothRegionsViewportAll() {
    // freeze
    this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 1));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(3, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // hide
    this.compositeFreezeLayer.doCommand(new MultiRowHideCommand(this.compositeFreezeLayer, new int[] { 1, 2, 3, 4 }));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(1, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(0, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(0, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(-1, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(20, this.viewportLayer.getMinimumOrigin().getY());
    // show again
    this.compositeFreezeLayer.doCommand(new ShowAllRowsCommand());
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(1, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(0, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(4, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(-1, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(20, this.viewportLayer.getMinimumOrigin().getY());
    reset();
}
Also used : FreezeRowCommand(org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand) MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) ShowAllRowsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllRowsCommand) Test(org.junit.Test)

Example 9 with MultiRowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand in project nebula.widgets.nattable by eclipse.

the class CompositeFreezeLayerHideShowTest method testFreezeHideShowRowBothRegions.

@Test
public void testFreezeHideShowRowBothRegions() {
    // freeze
    this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 1));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(3, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // hide
    this.compositeFreezeLayer.doCommand(new MultiRowHideCommand(this.compositeFreezeLayer, new int[] { 0, 3 }));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(1, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(0, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(2, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(1, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(20, this.viewportLayer.getMinimumOrigin().getY());
    // show again
    this.compositeFreezeLayer.doCommand(new ShowAllRowsCommand());
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(3, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    reset();
}
Also used : FreezeRowCommand(org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand) MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) ShowAllRowsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllRowsCommand) Test(org.junit.Test)

Example 10 with MultiRowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand in project nebula.widgets.nattable by eclipse.

the class CompositeFreezeLayerHideShowTest method testFreezeHideShowRowFrozenRegionMiddle.

@Test
public void testFreezeHideShowRowFrozenRegionMiddle() {
    // freeze
    this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 3));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(4, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(3, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(1, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(4, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(80, this.viewportLayer.getMinimumOrigin().getY());
    // hide
    this.compositeFreezeLayer.doCommand(new MultiRowHideCommand(this.compositeFreezeLayer, new int[] { 1, 2 }));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(1, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // show again
    this.compositeFreezeLayer.doCommand(new ShowAllRowsCommand());
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(4, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(3, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(1, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(4, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(80, this.viewportLayer.getMinimumOrigin().getY());
    reset();
}
Also used : FreezeRowCommand(org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand) MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) ShowAllRowsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllRowsCommand) Test(org.junit.Test)

Aggregations

MultiRowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand)14 Test (org.junit.Test)12 FreezeRowCommand (org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand)8 ShowAllRowsCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllRowsCommand)8 ArrayList (java.util.ArrayList)1 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)1 RowInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent)1 RowReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand)1