KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > HistoryDropAdapter


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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui;
12
13  
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.jface.viewers.StructuredViewer;
17 import org.eclipse.jface.viewers.ViewerDropAdapter;
18 import org.eclipse.swt.dnd.DND;
19 import org.eclipse.swt.dnd.DropTargetEvent;
20 import org.eclipse.swt.dnd.TransferData;
21 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
22 import org.eclipse.ui.part.ResourceTransfer;
23
24 public class HistoryDropAdapter extends ViewerDropAdapter {
25     HistoryView view;
26     
27     public HistoryDropAdapter(StructuredViewer viewer, HistoryView view) {
28         super(viewer);
29         this.view = view;
30     }
31     /*
32      * Override dragOver to slam the detail to DROP_LINK, as we do not
33      * want to really execute a DROP_MOVE, although we want to respond
34      * to it.
35      */

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

47     public void drop(DropTargetEvent event) {
48         super.drop(event);
49         event.detail = DND.DROP_LINK;
50     }
51     public boolean performDrop(Object JavaDoc data) {
52         if (data == null) return false;
53         if(data instanceof IResource[]) {
54             IResource[] sources = (IResource[])data;
55             if (sources.length == 0) return false;
56             IResource resource = sources[0];
57             if (!(resource instanceof IFile)) return false;
58             view.showHistory(resource, true /* fetch */);
59             return true;
60         } else if( data instanceof ICVSRemoteFile) {
61             view.showHistory((ICVSRemoteFile) data, true /* fetch */);
62             return true;
63         }
64         return false;
65     }
66     public boolean validateDrop(Object JavaDoc target, int operation, TransferData transferType) {
67         if (transferType != null &&
68             (ResourceTransfer.getInstance().isSupportedType(transferType) ||
69              CVSResourceTransfer.getInstance().isSupportedType(transferType))) {
70             return true;
71         }
72         return false;
73     }
74 }
75
76
Popular Tags