KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > callhierarchy > CallHierarchyTransferDropAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10  * (report 36180: Callers/Callees view)
11  *******************************************************************************/

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 JavaDoc 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     /* (non-Javadoc)
48      * @see org.eclipse.jdt.internal.ui.packageview.SelectionTransferDropAdapter#isEnabled(org.eclipse.swt.dnd.DropTargetEvent)
49      */

50     public boolean isEnabled(DropTargetEvent event) {
51         return true;
52     }
53
54     public void drop(Object JavaDoc 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 JavaDoc single= SelectionUtil.getSingleElement(selection);
65         if (single == null)
66             return null;
67         return getCandidate(single);
68     }
69     
70     /**
71      * Converts the input to a possible input candidates
72      */

73     public static IMethod getCandidate(Object JavaDoc input) {
74         if (!(input instanceof IMethod)) {
75             return null;
76         }
77         return (IMethod) input;
78     }
79 }
80
Popular Tags