SWT DnD (Drag and drop) Composite : Drag Drop « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » SWT JFace Eclipse » Drag DropScreenshots 
SWT DnD (Drag and drop) Composite

import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

public class Ch12DnDComposite extends Composite {

  public Ch12DnDComposite(Composite parent) {
    super(parent, SWT.NONE);

    FillLayout layout = new FillLayout();
    setLayout(layout);

    Text leftText = new Text(this, SWT.MULTI);
    Text rightText = new Text(this, SWT.MULTI);

    createDragSource(leftText);
    createDragSource(rightText);

    createDropTarget(leftText);
    createDropTarget(rightText);
  }

  private void createDropTarget(final Text targetText) {
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    DropTarget dropTarget = new DropTarget(targetText, DND.DROP_COPY);
    dropTarget.setTransfer(types);

    dropTarget.addDropListener(new DropTargetListener() {

      public void dragEnter(DropTargetEvent event) {
      }

      public void dragLeave(DropTargetEvent event) {
      }

      public void dragOperationChanged(DropTargetEvent event) {
      }

      public void dragOver(DropTargetEvent event) {
      }

      public void drop(DropTargetEvent event) {
        String data = (Stringevent.data;
        targetText.append(data);
      }

      public void dropAccept(DropTargetEvent event) {
      }
    });
  }

  private void createDragSource(final Text sourceText) {
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    DragSource dragSource = new DragSource(sourceText, DND.DROP_COPY);
    dragSource.setTransfer(types);
    dragSource.addDragListener(new DragSourceListener() {

      public void dragStart(DragSourceEvent event) {
        if (sourceText.getSelectionText().length() 0) {
          event.doit = true;
        }
      }

      public void dragSetData(DragSourceEvent event) {
        event.data = sourceText.getSelection();
      }

      public void dragFinished(DragSourceEvent event) {
        //do nothing
      }
    });
  }
}

           
       
Related examples in the same category
1. SWT DND (Drag and Drop) comprehensive Example SWT DND (Drag and Drop) comprehensive Example
2. Word JumblesWord Jumbles
3. Illustrates draggingIllustrates dragging
4. Simple DND (Drag and Drop) ExampleSimple DND (Drag and Drop) Example
5. Drag and Drop: determine native data types available (motif only)
6. Drag and Drop: determine data types available (win32 only)Drag and Drop: determine data types available (win32 only)
7. Drag and Drop example snippet: define a default operation (in this example, Copy)Drag and Drop example snippet: define a default operation (in this example, Copy)
8. Drag and Drop example snippet: define my own data transfer typeDrag and Drop example snippet: define my own data transfer type
9. Drag and Drop example snippet: drag leaf items in a treeDrag and Drop example snippet: drag leaf items in a tree
10. Drag and Drop example snippet: drag text between two labelsDrag and Drop example snippet: drag text between two labels
w__ww_.__j___a_va_2__s_.__c__o_m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.