use of org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayer method expandAll.
/**
* Expands all tree nodes.
*/
public void expandAll() {
List<Integer> rowsToShow = new ArrayList<Integer>(this.hiddenRowIndexes);
this.hiddenRowIndexes.clear();
this.collapsedNodes.clear();
invalidateCache();
fireLayerEvent(new ShowRowPositionsEvent(this, rowsToShow));
}
use of org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayer method handleLayerEvent.
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof IStructuralChangeEvent) {
IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
if (structuralChangeEvent.isVerticalStructureChanged()) {
// recalculate node row indexes
// build a new collection of nodes to avoid duplication clashes
// as nodes are equal per column and row index
int negativeIndex = -1;
Set<HierarchicalTreeNode> updatedCollapsedNodes = new HashSet<HierarchicalTreeNode>();
for (HierarchicalTreeNode node : this.collapsedNodes) {
int newRowIndex = findTopRowIndex(node.columnIndex, node.rowObject);
// the underlying collection
if (newRowIndex >= 0) {
updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, newRowIndex, this.underlyingList.get(newRowIndex)));
} else if (this.retainRemovedRowObjectNodes) {
updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, negativeIndex, node.rowObject));
negativeIndex--;
}
}
this.collapsedNodes.clear();
this.collapsedNodes.addAll(updatedCollapsedNodes);
// recalculate hidden rows based on updated collapsed nodes
Set<Integer> updatedHiddenRows = new HashSet<Integer>();
for (HierarchicalTreeNode node : this.collapsedNodes) {
updatedHiddenRows.addAll(getChildIndexes(node.columnIndex, node.rowIndex));
}
getHiddenRowIndexes().clear();
getHiddenRowIndexes().addAll(updatedHiddenRows);
}
} else if (event instanceof SearchEvent) {
PositionCoordinate coord = ((SearchEvent) event).getCellCoordinate();
if (coord != null) {
Integer foundIndex = coord.getLayer().getRowIndexByPosition(coord.rowPosition);
if (getHiddenRowIndexes().contains(foundIndex)) {
if (this.expandOnSearch) {
// not collapsible
for (int level = this.nodeColumnMapping.size() - 2; level >= 0; level--) {
ILayerCell nodeCell = coord.getLayer().getCellByPosition(this.nodeColumnMapping.get(level), coord.rowPosition);
int colIdx = coord.getLayer().getColumnIndexByPosition(nodeCell.getOriginColumnPosition());
int rowIdx = coord.getLayer().getRowIndexByPosition(nodeCell.getOriginRowPosition());
if (this.collapsedNodes.contains(new HierarchicalTreeNode(colIdx, rowIdx, null))) {
expandOrCollapse(colIdx, rowIdx);
}
}
} else {
// only make the single row visible again
getHiddenRowIndexes().remove(foundIndex);
}
}
invalidateCache();
fireLayerEvent(new ShowRowPositionsEvent(this, Arrays.asList(foundIndex)));
}
}
super.handleLayerEvent(event);
}
use of org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayer method expandAllToLevel.
/**
* Expands all tree nodes starting from the first level to the specified
* level.
*
* @param toLevel
* 0 based hierarchy level to expand to. A negative value will be
* defaulted to 0 to at least expand the first level.
*/
public void expandAllToLevel(int toLevel) {
// at least the first level will always be expanded
int toLevelColumnIndex = (toLevel >= 0) ? this.nodeColumnMapping.get(toLevel) : 0;
// first remove all node coords that should be expanded
for (Iterator<HierarchicalTreeNode> it = this.collapsedNodes.iterator(); it.hasNext(); ) {
HierarchicalTreeNode coord = it.next();
// coords in the first level aswell as level matching
if (coord.columnIndex <= toLevelColumnIndex) {
it.remove();
}
}
// collect all rows of coords that are still collapsed
Set<Integer> remain = new HashSet<Integer>();
for (HierarchicalTreeNode coord : this.collapsedNodes) {
remain.addAll(getChildIndexes(coord.columnIndex, coord.rowIndex));
}
// calculate the indexes that get visible afterwards
List<Integer> toProcess = new ArrayList<Integer>(this.hiddenRowIndexes);
toProcess.removeAll(remain);
// set still collapsed as hidden row indexes
this.hiddenRowIndexes.clear();
this.hiddenRowIndexes.addAll(remain);
// invalidate cache and fire event for rows that got visible
invalidateCache();
fireLayerEvent(new ShowRowPositionsEvent(this, toProcess));
}
use of org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent in project nebula.widgets.nattable by eclipse.
the class TreeLayer method expandTreeRowToLevel.
/**
* Expands the tree node for the given row index in the tree to a certain
* level.
*
* @param parentIndex
* The index of the row that shows the node that should be
* expanded
* @param level
* The level to which the tree node should be expanded.
*/
public void expandTreeRowToLevel(int parentIndex, int level) {
List<Integer> rowIndexes = this.treeRowModel.expandToLevel(parentIndex, level);
// removeAll()
for (final Integer expandedChildRowIndex : rowIndexes) {
this.hiddenRowIndexes.remove(expandedChildRowIndex);
}
invalidateCache();
fireLayerEvent(new ShowRowPositionsEvent(this, rowIndexes));
}
use of org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerTest method testCollapseMultipleExpandSingleToLevel.
// collapse second - collapse first - expand first to level 1 - second also
// expanded
@Test
public void testCollapseMultipleExpandSingleToLevel() {
// collapse first node in second level
this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 2));
// collapse first node in first level
this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
assertEquals(7, this.treeLayer.getRowCount());
assertEquals(2, this.treeLayer.collapsedNodes.size());
assertTrue(this.treeLayer.collapsedNodes.contains(new HierarchicalTreeNode(2, 0, null)));
assertTrue(this.treeLayer.collapsedNodes.contains(new HierarchicalTreeNode(0, 0, null)));
assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
// expand first node in first level to level 1
this.treeLayer.doCommand(new TreeExpandToLevelCommand(0, 1));
assertEquals(11, this.treeLayer.getRowCount());
assertTrue(this.treeLayer.collapsedNodes.isEmpty());
assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
assertEquals(3, this.layerListener.getEventsCount());
assertTrue(this.layerListener.containsInstanceOf(ShowRowPositionsEvent.class));
ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
Collection<Range> rowPositionRanges = showEvent.getRowPositionRanges();
assertEquals(1, rowPositionRanges.size());
assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
}
Aggregations