nebula

Copy headers in NatTables in Eclipse


I want to copy also row header every time, when some row(s) is(are) copied into clipboard. I have found this: Handler class for copying selected data within the SelectionLayer to the clipboard. This handler is registered by default with the SelectionLayer, without references to the header regions. You can override the copy data behaviour by registering an instance of this handler to a layer above the SelectionLayer. This way the registered custom instance will consume a CopyDataToClipboardCommand and the registered default handler won't be called.

But I do not understand it well. I am running:

public class CopyDataAction implements IKeyAction {
public void run(NatTable natTable, KeyEvent event) {
   natTable.doCommand(new CopyDataToClipboardCommand("\t", System.getProperty("line.separator"), 
     natTable.getConfigRegistry()));
}

}

It is possible just to change some configuration? Or should I implement my own handler to overwrite default behaviour?


Solution

  • You need to register an instance of the CopyDataCommandHandler that is created with references to the header layer on a layer above the SelectionLayer. Actually it should be also possible to register it on the SelectionLayer as it should override the default registered instance.

    There is no configuration for that. You need to customize with a command handler. But the existing implementation provides the possibility to achieve what you want without the need to create a custom command handler.

    This example shows how to do this: https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_700_AdditionalFunctions/_751_CopyExample.java