Get index of currently selected column from within custom selection binding [message #1751255] |
Fri, 06 January 2017 07:02  |
Eclipse User |
|
|
|
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!
|
|
|
Re: Get index of currently selected column from within custom selection binding [message #1751269 is a reply to message #1751255] |
Fri, 06 January 2017 12:22  |
Eclipse User |
|
|
|
No this is not possible. The NatTable is not aware of selection, as a NatTable might not contain a SelectionLayer in the layer composition.
Either create an action that knows the SelectionLayer, or use a command with a command handler on the SelectionLayer like we do with the DeleteSelectionAction or do a workaround like we do in the SearchAction or somewhere on the way and search for the SelectionLayer in the layer stack.
The question is what you are trying to achieve? Typically the command approach is best matching to perform actions in a NatTable
|
|
|
Powered by
FUDForum. Page generated in 0.04013 seconds