/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DropTargetListener#drop(org.eclipse.swt.dnd.DropTargetEvent)
*/
public void drop(DropTargetEvent event) {
IType type = null;
AspectManagerNode targetManager = (AspectManagerNode) getTarget(event);
Object source = SelectionUtil.getSingleElement(LocalSelectionTransfer.getInstance().getSelection());
if (source instanceof AspectNode) {
AspectNode aspect = (AspectNode) source;
// Since there is no classpath information in an AspectSurrogate, we
// have to seek the aspect class.
IJavaProject[] projects = getJavaProjects();
for (int i = 0; i < projects.length; i++) {
try {
type = projects[i].findType(aspect.getAspect().getAspectClassName());
if (type != null)
break;
} catch (JavaModelException e) {
ProsePlugin.log(e.getStatus());
break;
}
}
if (type == null) {
ProsePlugin.openErrorDialog("No aspect found", "No project contains an aspect named "
+ aspect.getAspect().getAspectClassName() + '.');
event.detail = DND.DROP_NONE;
return;
}
} else if (source instanceof ICompilationUnit){
type = ((ICompilationUnit) source).findPrimaryType();
if (type == null) {
ProsePlugin.openErrorDialog("No type found", "Compilation unit does not contain a type: " + source + '.');
event.detail = DND.DROP_NONE;
return;
}
}
try {
targetManager.insertAspect(type);
} catch (UnreachableException e) {
ProsePlugin.openErrorDialog("Aspect insertion failed",
"Could not insert aspect because Prose application is not reachable.");
event.detail = DND.DROP_NONE;
}