KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > history > GenericHistoryDropAdapter


1 /*******************************************************************************
2  * Copyright (c) 2006 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.team.internal.ui.history;
13
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.swt.dnd.*;
16 import org.eclipse.ui.part.PluginDropAdapter;
17 import org.eclipse.ui.part.ResourceTransfer;
18
19 public class GenericHistoryDropAdapter extends PluginDropAdapter {
20
21     private GenericHistoryView view;
22
23     public GenericHistoryDropAdapter(GenericHistoryView view) {
24         super(null);
25         this.view = view;
26     }
27
28     /*
29      * Override dragOver to slam the detail to DROP_LINK, as we do not
30      * want to really execute a DROP_MOVE, although we want to respond
31      * to it.
32      */

33     public void dragOver(DropTargetEvent event) {
34         if ((event.operations & DND.DROP_LINK) == DND.DROP_LINK) {
35             event.detail = DND.DROP_LINK;
36         }
37         super.dragOver(event);
38     }
39
40     /*
41      * Override drop to slam the detail to DROP_LINK, as we do not
42      * want to really execute a DROP_MOVE, although we want to respond
43      * to it.
44      */

45     public void drop(DropTargetEvent event) {
46         super.drop(event);
47         event.detail = DND.DROP_LINK;
48     }
49
50     public boolean performDrop(Object JavaDoc data) {
51         if (data == null)
52             return false;
53         if (data instanceof IResource[]) {
54             IResource[] sources = (IResource[]) data;
55             if (sources.length == 0)
56                 return false;
57             IResource resource = sources[0];
58             //Allow all resources types through to the view, the individual pages can decide
59
//which ones to handle
60
view.showHistoryPageFor(resource, true, true, null);
61
62             return true;
63         }
64         return false;
65     }
66
67     public boolean validateDrop(Object JavaDoc target, int operation, TransferData transferType) {
68         if (transferType != null && ResourceTransfer.getInstance().isSupportedType(transferType)) {
69             return true;
70         }
71         
72         return super.validateDrop(target, operation, transferType);
73     }
74
75     protected Object JavaDoc getCurrentTarget() {
76         return view;
77     }
78 }
79
Popular Tags