Fix hover functionality.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / dnd / BasicSelectionTransferDragAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.dnd;
12
13 //incastrix
14 //import org.eclipse.jface.text.Assert;
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.jface.viewers.ISelectionProvider;
18 import org.eclipse.swt.dnd.DND;
19 import org.eclipse.swt.dnd.DragSourceAdapter;
20 import org.eclipse.swt.dnd.DragSourceEvent;
21 import org.eclipse.swt.dnd.Transfer;
22
23 public class BasicSelectionTransferDragAdapter extends DragSourceAdapter
24                 implements TransferDragSourceListener {
25
26         private ISelectionProvider fProvider;
27
28         public BasicSelectionTransferDragAdapter(ISelectionProvider provider) {
29                 Assert.isNotNull(provider);
30                 fProvider = provider;
31         }
32
33         /**
34          * @see TransferDragSourceListener#getTransfer
35          */
36         public Transfer getTransfer() {
37                 return LocalSelectionTransfer.getInstance();
38         }
39
40         /*
41          * non Java-doc
42          * 
43          * @see org.eclipse.swt.dnd.DragSourceListener#dragStart
44          */
45         public void dragStart(DragSourceEvent event) {
46                 ISelection selection = fProvider.getSelection();
47                 LocalSelectionTransfer.getInstance().setSelection(selection);
48                 LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time);
49                 event.doit = isDragable(selection);
50         }
51
52         /**
53          * Checks if the elements contained in the given selection can be dragged.
54          * <p>
55          * Subclasses may override.
56          * 
57          * @param selection
58          *            containing the elements to be dragged
59          */
60         protected boolean isDragable(ISelection selection) {
61                 return true;
62         }
63
64         /*
65          * non Java-doc
66          * 
67          * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData
68          */
69         public void dragSetData(DragSourceEvent event) {
70                 // For consistency set the data to the selection even though
71                 // the selection is provided by the LocalSelectionTransfer
72                 // to the drop target adapter.
73                 event.data = LocalSelectionTransfer.getInstance().getSelection();
74         }
75
76         /*
77          * non Java-doc
78          * 
79          * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished
80          */
81         public void dragFinished(DragSourceEvent event) {
82                 // We assume that the drop target listener has done all
83                 // the work.
84                 Assert.isTrue(event.detail == DND.DROP_NONE);
85                 LocalSelectionTransfer.getInstance().setSelection(null);
86                 LocalSelectionTransfer.getInstance().setSelectionSetTime(0);
87         }
88 }