Search in sources :

Example 11 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent in project nebula.widgets.nattable by eclipse.

the class RowHideShowLayer method hideRowIndexes.

@Override
public void hideRowIndexes(Collection<Integer> rowIndexes) {
    Set<Integer> rowPositions = new HashSet<Integer>();
    for (Integer rowIndex : rowIndexes) {
        rowPositions.add(getRowPositionByIndex(rowIndex));
    }
    this.hiddenRowIndexes.addAll(rowIndexes);
    invalidateCache();
    fireLayerEvent(new HideRowPositionsEvent(this, rowPositions));
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) HashSet(java.util.HashSet)

Example 12 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent in project nebula.widgets.nattable by eclipse.

the class RowHideShowLayer method hideRowPositions.

@Override
public void hideRowPositions(Collection<Integer> rowPositions) {
    Set<Integer> rowIndexes = new HashSet<Integer>();
    for (Integer rowPosition : rowPositions) {
        rowIndexes.add(getRowIndexByPosition(rowPosition));
    }
    this.hiddenRowIndexes.addAll(rowIndexes);
    invalidateCache();
    fireLayerEvent(new HideRowPositionsEvent(this, rowPositions));
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) HashSet(java.util.HashSet)

Example 13 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayer method expandOrCollapse.

/**
 * Expands or collapses the node at the given index coordinates according to
 * its current state. Expands to the given level, e.g. if toLevel 0 is
 * given, only the first level of a row is expanded, given toLevel is 1 and
 * a node in the first level should be expanded, that node will be expanded
 * as well as all collapsed nodes in the second level for this object.
 *
 * @param columnIndex
 *            The column index of the node to handle.
 * @param rowIndex
 *            The row index of the node to handle.
 * @param toLevel
 *            0 based hierarchy level to expand to. Will be ignored on
 *            collapse or if value is -1.
 *            <p>
 *            <b>Note:</b> This is the level to expand to, not the number of
 *            levels to expand from the expanded level.
 *            </p>
 */
public void expandOrCollapse(int columnIndex, int rowIndex, int toLevel) {
    List<Integer> toProcess = getChildIndexes(columnIndex, rowIndex);
    HierarchicalTreeNode coord = new HierarchicalTreeNode(columnIndex, rowIndex, null);
    if (this.collapsedNodes.contains(coord)) {
        this.collapsedNodes.remove(coord);
        // ensure that deeper level collapsed rows are not shown again
        Range children = new Range(rowIndex, toProcess.get(toProcess.size() - 1));
        int toLevelColumnIndex = (toLevel >= 0) ? this.nodeColumnMapping.get(toLevel) : -1;
        for (Iterator<HierarchicalTreeNode> it = this.collapsedNodes.iterator(); it.hasNext(); ) {
            HierarchicalTreeNode p = it.next();
            // and coord column is bigger than the toLevel
            if (children.contains(p.rowIndex)) {
                if (p.columnIndex > toLevelColumnIndex) {
                    toProcess.removeAll(getChildIndexes(p.columnIndex, p.rowIndex));
                } else {
                    // we also remove the coord in case it will be expanded
                    it.remove();
                }
            }
        }
        this.getHiddenRowIndexes().removeAll(toProcess);
        invalidateCache();
        fireLayerEvent(new ShowRowPositionsEvent(this, toProcess));
    } else {
        coord.rowObject = this.underlyingList.get(coord.rowIndex);
        this.collapsedNodes.add(coord);
        this.getHiddenRowIndexes().addAll(toProcess);
        invalidateCache();
        fireLayerEvent(new HideRowPositionsEvent(this, toProcess));
    }
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)

Example 14 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayer method collapseAll.

/**
 * Collapses all tree nodes.
 */
public void collapseAll() {
    List<Integer> rowsToHide = new ArrayList<Integer>();
    Integer[] nodeColumns = this.nodeColumnMapping.values().toArray(new Integer[0]);
    Arrays.sort(nodeColumns);
    int columnIndex = nodeColumns[0];
    int columnPosition = getColumnPositionByIndex(columnIndex);
    ILayerCell cell = null;
    for (int row = 0; row < getRowCount(); row++) {
        cell = getCellByPosition(columnPosition, row);
        if (cell.getRowSpan() > 1) {
            int rowIndex = getRowIndexByPosition(row);
            this.collapsedNodes.add(new HierarchicalTreeNode(columnIndex, rowIndex, this.underlyingList.get(rowIndex)));
            rowsToHide.addAll(getChildIndexes(columnIndex, rowIndex));
            row += (cell.getRowSpan()) - 1;
        }
    }
    // search for node coords in deeper levels, except the leaf
    for (int col = 1; col < (nodeColumns.length - 1); col++) {
        columnIndex = nodeColumns[col];
        columnPosition = getColumnPositionByIndex(columnIndex);
        for (int row = 0; row < getRowCount(); row++) {
            cell = getCellByPosition(columnPosition, row);
            if (cell.getRowSpan() > 1) {
                // only collect the coordinates, the rows are already hidden
                // by the first level
                int rowIndex = getRowIndexByPosition(row);
                this.collapsedNodes.add(new HierarchicalTreeNode(columnIndex, rowIndex, this.underlyingList.get(rowIndex)));
                row += (cell.getRowSpan()) - 1;
            }
        }
    }
    this.getHiddenRowIndexes().addAll(rowsToHide);
    invalidateCache();
    fireLayerEvent(new HideRowPositionsEvent(this, rowsToHide));
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) ArrayList(java.util.ArrayList) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)14 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)6 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)5 TreeExpandCollapseCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand)3 HashSet (java.util.HashSet)2 RowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand)2 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)2 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 Shell (org.eclipse.swt.widgets.Shell)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 HierarchicalTreeNode (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)1 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)1 SelectionLayerStructuralChangeEventHandler (org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler)1 TreeCollapseAllCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand)1