KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > breakpoints > BreakpointsDragAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.debug.internal.ui.views.breakpoints;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.jface.util.TransferDragSourceListener;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.swt.dnd.DND;
17 import org.eclipse.swt.dnd.DragSourceAdapter;
18 import org.eclipse.swt.dnd.DragSourceEvent;
19 import org.eclipse.swt.dnd.Transfer;
20 import org.eclipse.swt.widgets.Item;
21 import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
22
23 /**
24  * A drag adapter for the breakpoints viewer
25  */

26 public class BreakpointsDragAdapter extends DragSourceAdapter implements TransferDragSourceListener {
27     
28     /**
29      * the associated viewer for the adapter
30      */

31     private BreakpointsViewer fViewer;
32     private Item[] fItems = null;
33     
34     /**
35      * Constructor
36      * @param view the associiated view, which acts as the selection provider and therefore <b>must</b> implement <code>ISelectionProvider</code>
37      */

38     public BreakpointsDragAdapter(BreakpointsViewer viewer) {
39         Assert.isNotNull(viewer);
40         fViewer = viewer;
41     }
42
43     /**
44      * @see TransferDragSourceListener#getTransfer
45      */

46     public Transfer getTransfer() {
47         return LocalSelectionTransfer.getInstance();
48     }
49     
50     /* non Java-doc
51      * @see org.eclipse.swt.dnd.DragSourceListener#dragStart
52      */

53     public void dragStart(DragSourceEvent event) {
54         ISelection selection = fViewer.getSelection();
55         LocalSelectionTransfer.getInstance().setSelection(selection);
56         LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time & 0xFFFFFFFFL);
57         event.doit = fViewer.canDrag(fViewer.getSelectedItems());
58         fItems = fViewer.getSelectedItems();
59     }
60    
61     /* non Java-doc
62      * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData
63      */

64     public void dragSetData(DragSourceEvent event) {
65         // For consistency set the data to the selection even though
66
// the selection is provided by the LocalSelectionTransfer
67
// to the drop target adapter.
68
event.data = LocalSelectionTransfer.getInstance().getSelection();
69     }
70
71     /* non Java-doc
72      * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished
73      */

74     public void dragFinished(DragSourceEvent event) {
75         if (event.detail == DND.DROP_MOVE) {
76             // remove from source on move operation
77
fViewer.performDrag(fItems);
78         }
79         fItems = null;
80         LocalSelectionTransfer.getInstance().setSelection(null);
81         LocalSelectionTransfer.getInstance().setSelectionSetTime(0);
82     }
83 }
84
Popular Tags