0

我正在尝试这里的例子

我注释了 rowHeaderLayer、ColumnHeaderLayer、CornerLayer、GridLayer 并直接将 viewPortLayer 设置为 nattable。树出现了,但我无法展开和折叠树,尽管我有 rowHideShowLayer。

这是代码片段:

    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);`
4

1 回答 1

0

呸,我们的代码在什么地方能找到真的很奇怪……

我不会查看 googlesource,而是将我们的源代码托管在 Eclipse 基础架构中,IIRC 源代码在 GitHub 上复制。所以更好的例子是

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

关于您的问题,您不需要 RowHideShowLayer,我建议将其删除。由于您不使用网格组合,因此您需要将必要的区域标签设置为 ViewportLayer 以启用配置的 UI 绑定。所以需要在创建好ViewportLayer之后添加下面这行代码

viewportLayer.setRegionName(GridRegion.BODY);
于 2015-10-06T22:05:38.733 回答