我尝试用 glazedlists 实现一个简单的过滤器行。过滤器行出现,我可以将过滤器字符串放入文本字段。在那之前一切正常,但按下回车键,什么也没有发生。没有过滤。
我还阅读了以下文章:[2] http://www.eclipse.org/nattable/resources/NatTable_Advanced.pdf
现在到我的实现:
如 [1] 中所述,我在将数据列表传递给 DataProvider 之前将其打包到 filterList 中。之后,我使用 GlazedListsEventLayer 构建了我的 bodyLayerStack。
EventList<T> eventList = GlazedLists.eventList(entries);
TransformedList<T, T> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
SortedList<T> sortedList = new SortedList<T>(rowObjectsGlazedList, null);
filterList = new FilterList<T>(sortedList);
bodyDataProvider = new LogListDataProvider<>(filterList, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(getBodyDataProvider());
GlazedListsEventLayer<T> glazedListsEventLayer = new GlazedListsEventLayer<T>(bodyDataLayer, filterList);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(glazedListsEventLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
selectionLayer = new SelectionLayer(columnHideShowLayer, false);
ViewportLayer viewportLayer = new ViewportLayer(getSelectionLayer());
使用的类“LogListDataProvider”只是 ListDataProvider 的扩展,我只添加了一个 setter 方法“setList(List list)”,因为我在使用其内容创建表后刷新了表。
public class LogListDataProvider<T> extends ListDataProvider<T> {
public LogListDataProvider(List<T> list, IColumnAccessor<T> columnAccessor) {
super(list, columnAccessor);
}
public void setList(List<T> list) {
this.list = list;
}
}
对于 FilterRowHeader,我还按照示例 [1] 构建了一个 FilterRowHeaderComposite。
FilterRowHeaderComposite<LogEntry> filterRowHeaderComposite = new FilterRowHeaderComposite<LogEntry>(
new DefaultGlazedListsFilterStrategy<LogEntry>(bodyLayerStack.getFilterList(),
columnPropertyAccessor, configRegistry),
columnHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
// Columns: 1 ; Rows: 2
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.addConfiguration(new DefaultGridLayerConfiguration(compositeLayer));
// add headerlayer-stack and bodylayer-stack to compositelayer
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, filterRowHeaderComposite, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
对我来说,我似乎正确地遵循了 [1] 和 [2],但尽管它不起作用。