Get index of currently selected column from within custom selection binding [message #1751255] |
Fri, 06 January 2017 12:02 |
|
I've added a custom selection configuration to my NatTable's selectionLayer.
In this custom selection configuration I override addSelectionUIBindings() to add a new custom selection binding via addConfiguration(binding).
This custom binding extends DefaultSelectionBindings#configureUIBindings(UIBindingRegistry uiBindingRegistry) by adding a new key binding as follows.
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
super.configureUiBindings(uiBindingRegistry);
uiBindingRegistry.registerKeyBinding(new IKeyEventMatcher() {
@Override
public boolean matches(KeyEvent event) {
if (event.keyCode == 'n') {
return true;
}
return false;
}
}, new IKeyAction() {
@Override
public void run(NatTable natTable, KeyEvent event) {
System.out.println("N gives us the item " + natTable.getData("selectedItem"));
}
});
}
I've also added an ILayerListener to my NatTable, which listens to selection changes, and sets the selected object accordingly:
natTable.setData("selectedItem", item)
In the listener the actual Item is got via the absolute column index (using LayerUtil.convertColumnPosition(natTable, colPos, bodyDataLayer)), and getting an object from a list (my data provider extends ListDataProvider) at the specified column index. (FYI: My list objects aren't beans and don't have the properties I want to present so I have to hack my way around presenting them (e.g., by getting properties of connected nodes in the main graph object, while the Items are nodes themselves, but whatever).)
This all works fine, but I'd like to avoid calling NatTable.setData("selectedItem", item) every time the selection changes as I assume this isn't very performant. Hence I'd like to work via the selection itself if possible at all.
As I have a NatTable object in my KeyAction's run() method, it'd be great to get the actual absolute column index of the current selection via this.
I have tried via separate methods (e.g., setting the selectionLayer as data to the NatTable so I can retrieve it later, same hack as above, and doesn't work) but couldn't get it to work. The examples show nothing similar, so I'd like to inquire if there is something like a "global" option for getting the current selection with only a NatTable object in hand.
Thanks!
|
|
|
|
Powered by
FUDForum. Page generated in 0.03607 seconds