Sample code for allowing drag-and-drop of Notes/Domino documents (including email) to a table in a plugin

Posted: - Modified: | geek, lotus

Because I had to piece this together from examples on the Internet, and probably other people do too:

Transfer[] transferArray = new Transfer[]{
    XMLTransfer.getInstance(),
};
tableViewer.addDropSupport(DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK,
    transferArray, new DropTargetAdapter() {
        public void drop(DropTargetEvent event) {
            TableItem item = (TableItem) event.item;
            // You can access the object with item.getData()
            try {
                NotesThread.sinitThread();
                Session session = NotesFactory.createSessionWithFullAccess();
                if (event.data instanceof URIDescriptor[]){ 
                    URIDescriptor[] droppedURL = (URIDescriptor[]) event.data;
                    for (int i = 0; i < droppedURL.length; i++) { 
                        URI uri = ((URIDescriptor) droppedURL[i]).uri;
                        Document d = (Document) session.resolve(uri.toString());
                        // Do things with the document
                    }					
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                NotesThread.stermThread();
            }
        }});

Use session.resolve instead of db.getDocumentByURL to retrieve a document from a plugin, as both session.getAgentContext() and session.getCurrentDatabase() will return null.

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.