1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import org.eclipse.swt.dnd.DND; 15 import org.eclipse.swt.dnd.DropTargetEvent; 16 17 import org.eclipse.jface.viewers.ISelection; 18 import org.eclipse.jface.viewers.StructuredViewer; 19 20 import org.eclipse.jdt.core.IMethod; 21 22 import org.eclipse.jdt.internal.ui.packageview.SelectionTransferDropAdapter; 23 import org.eclipse.jdt.internal.ui.util.SelectionUtil; 24 25 class CallHierarchyTransferDropAdapter extends SelectionTransferDropAdapter { 26 27 private static final int OPERATION = DND.DROP_LINK; 28 private CallHierarchyViewPart fCallHierarchyViewPart; 29 30 public CallHierarchyTransferDropAdapter(CallHierarchyViewPart viewPart, StructuredViewer viewer) { 31 super(viewer); 32 setFullWidthMatchesItem(false); 33 fCallHierarchyViewPart= viewPart; 34 } 35 36 public void validateDrop(Object target, DropTargetEvent event, int operation) { 37 event.detail= DND.DROP_NONE; 38 initializeSelection(); 39 if (target != null){ 40 super.validateDrop(target, event, operation); 41 return; 42 } 43 if (getInputElement(getSelection()) != null) 44 event.detail= OPERATION; 45 } 46 47 50 public boolean isEnabled(DropTargetEvent event) { 51 return true; 52 } 53 54 public void drop(Object target, DropTargetEvent event) { 55 if (target != null || event.detail != OPERATION){ 56 super.drop(target, event); 57 return; 58 } 59 IMethod input= getInputElement(getSelection()); 60 fCallHierarchyViewPart.setMethod(input); 61 } 62 63 private static IMethod getInputElement(ISelection selection) { 64 Object single= SelectionUtil.getSingleElement(selection); 65 if (single == null) 66 return null; 67 return getCandidate(single); 68 } 69 70 73 public static IMethod getCandidate(Object input) { 74 if (!(input instanceof IMethod)) { 75 return null; 76 } 77 return (IMethod) input; 78 } 79 } 80 | Popular Tags |