| /******************************************************************************* |
| * Copyright (c) 2000, 2005 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.debug.internal.ui.views.breakpoints; |
| |
| import org.eclipse.jface.util.Assert; |
| import org.eclipse.jface.util.TransferDragSourceListener; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.ISelectionProvider; |
| import org.eclipse.swt.dnd.DND; |
| import org.eclipse.swt.dnd.DragSourceAdapter; |
| import org.eclipse.swt.dnd.DragSourceEvent; |
| import org.eclipse.swt.dnd.Transfer; |
| import org.eclipse.ui.views.navigator.LocalSelectionTransfer; |
| |
| public class BreakpointsDragAdapter extends DragSourceAdapter implements TransferDragSourceListener { |
| |
| private ISelectionProvider fProvider; |
| private BreakpointsView fView; |
| private BreakpointContainer[] fContainers; |
| |
| public BreakpointsDragAdapter(BreakpointsView view, ISelectionProvider provider) { |
| Assert.isNotNull(provider); |
| fProvider= provider; |
| fView = view; |
| } |
| |
| /** |
| * @see TransferDragSourceListener#getTransfer |
| */ |
| public Transfer getTransfer() { |
| return LocalSelectionTransfer.getInstance(); |
| } |
| |
| /* non Java-doc |
| * @see org.eclipse.swt.dnd.DragSourceListener#dragStart |
| */ |
| public void dragStart(DragSourceEvent event) { |
| ISelection selection= fProvider.getSelection(); |
| LocalSelectionTransfer.getInstance().setSelection(selection); |
| LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time & 0xFFFFFFFFL); |
| event.doit= isDragable(selection); |
| } |
| |
| /** |
| * Checks if the elements contained in the given selection can |
| * be dragged. |
| * <p> |
| * Subclasses may override. |
| * |
| * @param selection containing the elements to be dragged |
| */ |
| protected boolean isDragable(ISelection selection) { |
| if (fView.canMove(selection)) { |
| fContainers = fView.getMovedFromContainers(selection); |
| return true; |
| } |
| return false; |
| } |
| |
| |
| /* non Java-doc |
| * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData |
| */ |
| public void dragSetData(DragSourceEvent event) { |
| // For consistency set the data to the selection even though |
| // the selection is provided by the LocalSelectionTransfer |
| // to the drop target adapter. |
| event.data= LocalSelectionTransfer.getInstance().getSelection(); |
| } |
| |
| |
| /* non Java-doc |
| * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished |
| */ |
| public void dragFinished(DragSourceEvent event) { |
| if (event.detail == DND.DROP_MOVE) { |
| // remove from source on move operation |
| fView.performRemove(fContainers, LocalSelectionTransfer.getInstance().getSelection()); |
| } |
| LocalSelectionTransfer.getInstance().setSelection(null); |
| LocalSelectionTransfer.getInstance().setSelectionSetTime(0); |
| } |
| } |