package com.opcoach.training.rental.ui.views;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent;

import com.opcoach.training.rental.Customer;

final class AgencyTreeDragSourceListener extends DragSourceAdapter
{
	private ISelectionProvider selProvider = null;

	public AgencyTreeDragSourceListener(ISelectionProvider selProvider)
	{
		super();
		this.selProvider = selProvider;
	}

	@Override
	public void dragSetData(DragSourceEvent event)
	{
		// Recupere la source
		ISelection sel = selProvider.getSelection();
		if (sel instanceof IStructuredSelection)
		{
			IStructuredSelection ss = (IStructuredSelection) sel;
			Object selectedObject = ss.getFirstElement();
			if (selectedObject instanceof Customer)
			{
				Customer c = (Customer) selectedObject;
				event.data = "Customer : " + c.getDisplayName();
			} else
				event.data = selectedObject.toString();
		}

	}
}
@@ -282,16 +282,57 @@
 ceEvent;
+%0Aimport org.eclipse.swt.dnd.TextTransfer;
 %0A%0Aimport
@@ -672,16 +672,87 @@
 ent)%0A%09%7B%0A
+%09%09if (TextTransfer.getInstance().isSupportedType(event.dataType))%0A%09%09%7B%0A%09
 %09%09// Rec
@@ -767,16 +767,17 @@
  source%0A
+%09
 %09%09ISelec
@@ -817,16 +817,17 @@
 on();%0A%09%09
+%09
 if (sel 
@@ -861,18 +861,20 @@
 tion)%0A%09%09
+%09
 %7B%0A
+%09
 %09%09%09IStru
@@ -925,16 +925,17 @@
 sel;%0A%09%09%09
+%09
 Object s
@@ -968,24 +968,25 @@
 tElement();%0A
+%09
 %09%09%09if (selec
@@ -1015,26 +1015,28 @@
 ustomer)%0A%09%09%09
+%09
 %7B%0A
+%09
 %09%09%09%09Customer
@@ -1067,16 +1067,17 @@
 Object;%0A
+%09
 %09%09%09%09even
@@ -1128,15 +1128,17 @@
 %0A%09%09%09
+%09
 %7D else%0A
+%09
 %09%09%09%09
@@ -1177,16 +1177,21 @@
 ring();%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%0A%09%7D%0A

Gère le textTransfert uniquement