Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

Eclipse Drag and Drop - Tutorial

Lars Vogel

Version 0.2

19.11.2009

Revision History
Revision 0.116.10.2009Lars Vogel
Created Article
Revision 0.219.11.2009Lars Vogel
Working example

Eclipse Drag and Drop

This article demonstrates the usage of Drag and Drop in the Eclipse framework.

The article assumes that you are familiar with Eclipse RCP development. In this article Eclipse 3.5 (Galileo) is used.


Table of Contents

1. Eclipse Drag and Drop
2. Project
3. Model
4. Content and Label Provider
5. Drag Listener and Drop Listener
6. Views
7. Thank you
8. Questions and Discussion
9. Links and Literature
9.1. Source Code
9.2. Eclipse Drag and Drop Resources
9.3. vogella Resources

1. Eclipse Drag and Drop

Eclipse supports Drag and Drop based on transfer types defined as a subclass "org.eclipse.swt.dnd.Transfer". Every UI element can define if it provides a certain transfer type as source and if it accepts a certain transfer type as destination.

Eclipse provides several pre-defined transfer types, to define your own transfer type it is recommended to subclass "org.eclipse.swt.dnd.ByteArrayTransfer".

The following will demonstrate the usage of drag and drop for your own domain object between two JFace viewers (table and tree). The example in this article will just transfer Text. For a comprehensive description of drag and drop please check the articles in the appendix.