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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.dnd;
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;
23 public class BasicSelectionTransferDragAdapter extends DragSourceAdapter
24 implements TransferDragSourceListener {
26 private ISelectionProvider fProvider;
28 public BasicSelectionTransferDragAdapter(ISelectionProvider provider) {
29 Assert.isNotNull(provider);
34 * @see TransferDragSourceListener#getTransfer
36 public Transfer getTransfer() {
37 return LocalSelectionTransfer.getInstance();
43 * @see org.eclipse.swt.dnd.DragSourceListener#dragStart
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);
53 * Checks if the elements contained in the given selection can be dragged.
55 * Subclasses may override.
58 * containing the elements to be dragged
60 protected boolean isDragable(ISelection selection) {
67 * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData
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();
79 * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished
81 public void dragFinished(DragSourceEvent event) {
82 // We assume that the drop target listener has done all
84 Assert.isTrue(event.detail == DND.DROP_NONE);
85 LocalSelectionTransfer.getInstance().setSelection(null);
86 LocalSelectionTransfer.getInstance().setSelectionSetTime(0);