Andy Thomas
Andy Thomas

Reputation: 86459

NatTable 1.6 - TreeLayer - expand/collapse triangles don't follow their rows after collapsing a row above

When I collapse a row in a TreeLayer in NatTable, its children disappear, and other rows move up.

In NatTable 1.5.0, the expand/collapse icons move up with their rows.

In NatTable 1.6.0, the expand/collapse icons stay at their original row index, where their rows used to be.

Do I need to do something extra in 1.6? For example, to cause the tree layer to update from its ITreeRowModel?

EDIT

Here's an illustration of the issue. It occurs when NatTable is upgraded to 1.6, with no other code changes.

illustration of issue

Upvotes: 0

Views: 218

Answers (1)

Dirk Fauth
Dirk Fauth

Reputation: 4231

Unfortunately this is a regression that was not noticed. Mainly because most of the people seem to use TreeLayer with GlazedLists. And the NatTable project did not even have an example for usage without GlazedLists.

I have created a ticket and fixed the issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=552727

You could workaround the issue in the meanwhile by overriding TreeLayer#getConfigLabelsByPosition(int, int) the following way:

public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) {
    LabelStack configLabels = super.getConfigLabelsByPosition(columnPosition, rowPosition);

    if (isTreeColumn(columnPosition)) {
        configLabels.addLabelOnTop(TREE_COLUMN_CELL);

        ILayerCell cell = getCellByPosition(columnPosition, rowPosition);
        if (cell != null) {
            int rowIndex = getRowIndexByPosition(cell.getOriginRowPosition());
            configLabels.addLabelOnTop(
                    DefaultTreeLayerConfiguration.TREE_DEPTH_CONFIG_TYPE + this.treeRowModel.depth(rowIndex));
            if (!this.treeRowModel.hasChildren(rowIndex)) {
                configLabels.addLabelOnTop(DefaultTreeLayerConfiguration.TREE_LEAF_CONFIG_TYPE);
            } else {
                if (this.treeRowModel.isCollapsed(rowIndex)) {
                    configLabels.addLabelOnTop(DefaultTreeLayerConfiguration.TREE_COLLAPSED_CONFIG_TYPE);
                } else {
                    configLabels.addLabelOnTop(DefaultTreeLayerConfiguration.TREE_EXPANDED_CONFIG_TYPE);
                }
            }
        }
    }
    return configLabels;
}

Main issue is the missing transformation of the origin row position to index in the 1.6 implementation.

Upvotes: 1

Related Questions