Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 580670

Summary: Tree collapse doesn't work with big spanning
Product: [Technology] NatTable Reporter: Vincent Sennedot <vincent.sennedot>
Component: CoreAssignee: Dirk Fauth <dirk.fauth>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: dirk.fauth
Version: 2.0.3   
Target Milestone: 2.0.4   
Hardware: PC   
OS: Windows 11   
See Also: https://git.eclipse.org/r/c/nattable/org.eclipse.nebula.widgets.nattable/+/195557
https://git.eclipse.org/c/nattable/org.eclipse.nebula.widgets.nattable.git/commit/?id=bafe75cd93b8e9addd27d689d75db0ee59ef285c
Whiteboard:

Description Vincent Sennedot CLA 2022-09-02 12:32:05 EDT
If rows are spanned and the origin row is out of the visible NatTable, the origin row position is negative. And in TreeExpandCollapseAction, rowIndex is -1 and the execution of the command results in the following exception:

java.lang.IndexOutOfBoundsException: Cannot get at -1 on list of size 11
	at ca.odell.glazedlists.TransformedList.get(TransformedList.java:106)
	at org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.expandOrCollapse(HierarchicalTreeLayer.java:1074)
	at org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.expandOrCollapse(HierarchicalTreeLayer.java:1003)
	at org.eclipse.nebula.widgets.nattable.hierarchical.command.HierarchicalTreeExpandCollapseCommandHandler.doCommand(HierarchicalTreeExpandCollapseCommandHandler.java:59)
	at org.eclipse.nebula.widgets.nattable.hierarchical.command.HierarchicalTreeExpandCollapseCommandHandler.doCommand(HierarchicalTreeExpandCollapseCommandHandler.java:1)
	at org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler.doCommand(AbstractLayerCommandHandler.java:22)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayer.doCommand(AbstractLayer.java:186)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform.doCommand(AbstractLayerTransform.java:104)
	at org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.doCommand(HierarchicalTreeLayer.java:489)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractIndexLayerTransform.doCommand(AbstractIndexLayerTransform.java:112)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommandOnChildLayers(CompositeLayer.java:159)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommand(CompositeLayer.java:151)
	at org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer.doCommand(CompositeFreezeLayer.java:144)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform.doCommand(AbstractLayerTransform.java:109)
	at org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer.doCommandOnChildLayer(GridLayer.java:120)
	at org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer.doCommandOnChildLayers(GridLayer.java:107)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommand(CompositeLayer.java:151)
	at org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer.doCommand(GridLayer.java:194)
	at org.eclipse.nebula.widgets.nattable.NatTable.doCommand(NatTable.java:827)
	at org.eclipse.nebula.widgets.nattable.tree.action.TreeExpandCollapseAction.run(TreeExpandCollapseAction.java:40)


You can reproduce it with the example _6044_HierarchicalTreeLayerGridExample if you set a middle vertical alignment in the DefaultHierarchicalTreeLayerConfiguration, size up the rows and scroll down.
Comment 1 Eclipse Genie CLA 2022-09-05 03:52:03 EDT
New Gerrit change created: https://git.eclipse.org/r/c/nattable/org.eclipse.nebula.widgets.nattable/+/195557
Comment 3 Dirk Fauth CLA 2022-09-05 05:28:13 EDT
I have added a handling that should cover that special case.

For a better error description if anyone comes across this in the future:

The issue happens only if 
- the tree cell has a row spanning
- the tree handle is not in the top
- the origin row is outside the visible area

The TreeExpandCollapseAction is a IMouseAction so it only knows the NatTable and the clicked position. So it is impossible for the action to retrieve the row index of the origin row if it is not visible. By default the tree handle is on top of a row spanned cell, so if the top row is not visible, the handle is not visible and therefore the issue can not occur.

To fix the issue the clicked row index is passed as a negative value. With this indication the command handler should be able to know that not the origin row was clicked, but some other row of the spanning, and that now the origin row index needs to be determined.

Probably passing the row position instead of the index would be a cleaner approach, but that would mean to change the API from index handling to position handling, which would have a bigger impact overall.

Could you please verify with the latest SNAPSHOT build if everything now works as expected?
Comment 4 Vincent Sennedot CLA 2022-09-07 05:20:41 EDT
Thank you for the correction, it seems to work!
But while testing, I found another bug with the expand/collapse for a parent with only one child.
In the same example, the McLaren row has not the button to expand/collapse, but if you click at the position where the button could be, it appears and if you click again, an exception is thrown.
Comment 5 Dirk Fauth CLA 2022-09-07 07:43:32 EDT
Thanks for testing.

I have created https://bugs.eclipse.org/bugs/show_bug.cgi?id=580698 to track the new found error.
Comment 6 Dirk Fauth CLA 2022-12-14 14:58:50 EST
Released with 2.0.4