如何在nat表中排序后将选择放在第一行?

时间:2017-08-21 06:30:14

标签: eclipse-plugin eclipse-rcp nattable

如何在nat表中排序后将选择放在第一行,我使用SortHeaderLayer进行排序.....提前感谢

 SortHeaderLayer<Mapping> sortHeaderLayer =new SortHeaderLayer<Mapping>(columnHeaderLayer, new GlazedListsSortModel<Mapping>(sortedList,columnAccessor,configRegistry, columnHeaderDataLayer), false);

由于

1 个答案:

答案 0 :(得分:0)

这可以通过注册ILayerListener来完成。唯一要记住的是SortColumnEvent首先被激活,然后GlazedListsEventLayer触发RowStructuralRefreshEvent以触发重新绘制。这将在不使用RowSelectionModel时删除选择。因此,听众需要以反应的方式进行设计。

    // an ILayerListener that performs a selection after a refresh and 
    // unregisters itself afterwards
    ILayerListener sortListener = new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof RowStructuralRefreshEvent) {
                natTable.doCommand(new SelectRowsCommand(natTable,
                        1, 1, false, false));
                natTable.removeLayerListener(this);
            }
        }
    };

    // register an ILayerListener that registers the above listener
    // on a SortColumnEvent
    natTable.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof SortColumnEvent) {
                natTable.addLayerListener(sortListener);
            }
        }
    });