Sachin Giri
Sachin Giri

Reputation: 199

Tree Does not expand in NatTable

I am trying examples from here

I commented rowHeaderLayer, ColumnHeaderLayer, CornerLayer, GridLayer and directly set viewPortLayer to nattable. Tree shows up but I am not able to expand and collapse the tree though I have rowHideShowLayer.

Here is code snippet :

    EventList<Datum> eventList = GlazedLists.eventList(datums.values());
    SortedList<Datum> sortedList = new SortedList<Datum>(eventList, null);

    String[] propertyNames = new String[] { "self", "bar" };
    IColumnPropertyAccessor<Datum> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<Datum>(propertyNames);

    // Column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);

    ISortModel sortModel = new GlazedListsSortModel<Datum>(
            sortedList,
            columnPropertyAccessor,
            configRegistry, 
            columnHeaderDataLayer);

    final TreeList <Datum> treeList = new TreeList<Datum>(sortedList, new DatumTreeFormat(sortModel), new DatumExpansionModel());
    GlazedListTreeData <Datum> treeData = new DatumTreeData(treeList);

    GlazedListsDataProvider<Datum> bodyDataProvider = new GlazedListsDataProvider<Datum>(treeList, columnPropertyAccessor);
    final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);

    // Body layer
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);

    RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(selectionLayer);

    final TreeLayer treeLayer = new TreeLayer(rowHideShowLayer, new GlazedListTreeRowModel<Datum>(treeData));

    ViewportLayer viewportLayer = new ViewportLayer(treeLayer);

    NatTable natTable = new NatTable(parent, viewportLayer, false);`

Upvotes: 0

Views: 457

Answers (1)

Dirk Fauth
Dirk Fauth

Reputation: 4231

Phew, what places our code can be found is really strange ...

I wouldn't look into googlesource, instead we host our sources in the Eclipse infrastructure, and IIRC the sources are replicated at GitHub. So the better example would be

https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_600_GlazedLists/_604_Tree/_6041_TreeGridExample.java

Regarding your question, you don't need the RowHideShowLayer, and I suggest to remove it. As you don't use a grid composition you need to set the necessary region label to the ViewportLayer to enable the configured UI bindings. So you need to add the following line of code after the creation of the ViewportLayer

viewportLayer.setRegionName(GridRegion.BODY);

Upvotes: 0

Related Questions