1 11 package org.eclipse.jdt.internal.ui.dnd; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.swt.dnd.DND; 16 import org.eclipse.swt.dnd.DragSourceAdapter; 17 import org.eclipse.swt.dnd.DragSourceEvent; 18 import org.eclipse.swt.dnd.Transfer; 19 20 import org.eclipse.jface.util.TransferDragSourceListener; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.jface.viewers.ISelectionProvider; 23 24 import org.eclipse.ui.views.navigator.LocalSelectionTransfer; 25 26 public class BasicSelectionTransferDragAdapter extends DragSourceAdapter implements TransferDragSourceListener { 27 28 private ISelectionProvider fProvider; 29 30 public BasicSelectionTransferDragAdapter(ISelectionProvider provider) { 31 Assert.isNotNull(provider); 32 fProvider= provider; 33 } 34 35 38 public Transfer getTransfer() { 39 return LocalSelectionTransfer.getInstance(); 40 } 41 42 45 public void dragStart(DragSourceEvent event) { 46 ISelection selection= fProvider.getSelection(); 47 LocalSelectionTransfer.getInstance().setSelection(selection); 48 LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time & 0xFFFFFFFFL); 49 event.doit= isDragable(selection); 50 } 51 52 60 protected boolean isDragable(ISelection selection) { 61 return true; 62 } 63 64 65 68 public void dragSetData(DragSourceEvent event) { 69 event.data= LocalSelectionTransfer.getInstance().getSelection(); 73 } 74 75 76 79 public void dragFinished(DragSourceEvent event) { 80 Assert.isTrue(event.detail != DND.DROP_MOVE); 82 LocalSelectionTransfer.getInstance().setSelection(null); 83 LocalSelectionTransfer.getInstance().setSelectionSetTime(0); 84 } 85 } 86 | Popular Tags |