Tree 在 NatTable 中不展开
Tree Does not expand in NatTable
我正在尝试 here
中的示例
我注释了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);`
咦,我们代码能找到的地方真奇怪...
我不会研究 googlesource,而是将我们的源代码托管在 Eclipse 基础架构中,IIRC 将源代码复制到 GitHub。所以更好的例子是
关于你的问题,你不需要RowHideShowLayer,建议去掉。由于您不使用网格组合,因此您需要将必要的区域标签设置为 ViewportLayer 以启用配置的 UI 绑定。所以需要在ViewportLayer
的创建之后添加下面这行代码
viewportLayer.setRegionName(GridRegion.BODY);
我正在尝试 here
中的示例我注释了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);`
咦,我们代码能找到的地方真奇怪...
我不会研究 googlesource,而是将我们的源代码托管在 Eclipse 基础架构中,IIRC 将源代码复制到 GitHub。所以更好的例子是
关于你的问题,你不需要RowHideShowLayer,建议去掉。由于您不使用网格组合,因此您需要将必要的区域标签设置为 ViewportLayer 以启用配置的 UI 绑定。所以需要在ViewportLayer
的创建之后添加下面这行代码viewportLayer.setRegionName(GridRegion.BODY);