//
// This file is part of the Prose Development Tools for Eclipse package.
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// The Original Code is Prose Development Tools for Eclipse.
//
// The Initial Developer of the Original Code is Angela Nicoara. Portions
// created by Angela Nicoara are Copyright (C) 2006 Angela Nicoara.
// All Rights Reserved.
//
// Contributor(s):
// $Id: RunNodeDragAdapter.java,v 1.1 2008/11/18 12:27:11 anicoara Exp $
// ==============================================================================
//
package ch.ethz.prose.eclipse.internal.run.dnd;
import org.eclipse.jdt.internal.ui.util.SelectionUtil;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
import ch.ethz.prose.eclipse.internal.core.ProsePlugin;
import ch.ethz.prose.eclipse.internal.run.AspectNode;
import ch.ethz.prose.eclipse.internal.run.UnreachableException;
/**
* Drag listener for <code>IRunNode</code>s.
*
* @author Angela Nicoara
* @author Johann Gyger
* @version $Id: RunNodeDragAdapter.java,v 1.1 2008/11/18 12:27:11 anicoara Exp $
*/
public class RunNodeDragAdapter extends DragSourceAdapter {
protected TreeViewer viewer;
/**
* Create a new drag listener.
*
* @param viewer Tree viewer to which this listener is bound
*/
public RunNodeDragAdapter(TreeViewer viewer) {
this.viewer = viewer;
}
/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
*/
public void dragStart(DragSourceEvent event) {
ISelection selection = viewer.getSelection();
Object node = SelectionUtil.getSingleElement(viewer.getSelection());
if (!(node instanceof AspectNode))
event.doit = false;
else
LocalSelectionTransfer.getInstance().setSelection(selection);
}
/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
*/
public void dragSetData(DragSourceEvent event) {
event.data = LocalSelectionTransfer.getInstance().getSelection();
}
/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
*/
public void dragFinished(DragSourceEvent event) {
Object node = SelectionUtil.getSingleElement(viewer.getSelection());
if (node instanceof AspectNode && event.detail == DND.DROP_MOVE) {
AspectNode aspect = (AspectNode) node;
if (event.detail == DND.DROP_MOVE) {
try {
aspect.withdraw();
} catch (UnreachableException e) {
ProsePlugin.log(e);
ProsePlugin.openErrorDialog("Aspect withdrawal failed",
"Could not withdraw aspect because the Prose application is not reachable.");
}
}
}
LocalSelectionTransfer.getInstance().setSelection(null);
}
}