Nattable: Need help to paste data from extenal source to Nattable

200 views Asked by At

I am able to implement Copy Paste function for nattable and it is working perfectly inside the nattable and also for other internal nattable.But not able to paste Data for External system.I have tried to extend Copyhandler and Paste handler.But i am not able to get Data from System clipboard.Please help me.

1

There are 1 answers

2
Dirk Fauth On BEST ANSWER

To get data from the system clipboard when previously copied data from Excel, you can try to use the following code:

    final Clipboard cb = new Clipboard(Display.getCurrent());

    Button paste = new Button(buttonPanel, SWT.PUSH);
    paste.setText("Paste");
    paste.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            TextTransfer transfer = TextTransfer.getInstance();
            String data = (String) cb.getContents(transfer);
            if (data != null) {
                System.out.println(data);
            }
        }
    });

You only need to get the data from the system clipboard and interprete it to match your NatTable structure. And you need to be aware that Excel adds new line characters and tabs as delimiter, so you are able to parse the data correctly.