在 NatTable 中,我在過濾表中添加一行。洗掉過濾器后,新添加的行移動到表中的最后一個位置。
但我希望它保持在相同的位置,即在過濾表時添加的行旁邊。
我目前正在使用RowInsertCommand. 我不想通過用于填充表格的模型或串列添加行。我只想通過 NatTable 命令實作。是否可以?
uj5u.com熱心網友回復:
如果沒有示例代碼,總是很難理解解釋和問題。但我假設您只是從 NatTable 示例中復制了代碼,因此我將在此基礎上解釋您的問題。
首先,RowInsertCommand有幾個建構式。如果您使用沒有rowIndexorrowPosition引數的構造函式,則新物件將始終添加到串列的末尾。
當 NatTable 中的過濾器功能與 GlazedLists 一起使用時,包裹在正文中的串列DataLayer是FilterList. 如果您正在操作FilterList以計算rowIndex應添加新物件的位置并且在 中具有FilterListas 基串列,RowInsertCommandHandler則添加新物件的位置在FilterList和基之間轉換EventList,這可能不是所需的結果。
要解決此問題,您需要RowInsertCommandHandler使用 base創建EventList。
EventList<T> eventList = GlazedLists.eventList(values);
TransformedList<T, T> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
SortedList<T> sortedList = new SortedList<>(rowObjectsGlazedList, null);
this.filterList = new FilterList<>(sortedList);
this.baseList = eventList;
bodyDataLayer.registerCommandHandler(new RowInsertCommandHandler<>(this.baseList));
執行添加操作的操作當然需要基于 base 計算索引EventList。以下代碼是部分SelectionAdapter的IMenuItemProvider:
int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
int rowIndex = natTable.getRowIndexByPosition(rowPosition);
Object relative = bodyLayerStack.filterList.get(rowIndex);
int baseIndex = bodyLayerStack.baseList.indexOf(relative);
Object newObject = new ...;
natTable.doCommand(new RowInsertCommand<>(baseIndex 1, newObject));
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/379832.html
標籤:蚀 eclipse插件 eclipse-rcp 可浏览的
下一篇:ModuleNotFoundError:嘗試在Eclipse上使用scons構建專案時沒有名為“SCons”的模塊
