mPlugin = null;
}
public void drop(DropTargetDropEvent e) {
e.acceptDrop(e.getDropAction());
final Transferable tr = e.getTransferable();
final Object src = e.getSource();
final Point loc = e.getLocation();
final PluginTree tree = this;
e.dropComplete(true);
mDropThread = new Thread("Plugin view drop") {
public void run() {
tree.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
DataFlavor[] flavors = null;
try {
flavors = tr.getTransferDataFlavors();
} catch (Exception e) {
// there seems to be a bug in Java, causing a NPE internally
e.printStackTrace();
}
if (flavors != null && flavors.length == 1) {
try {
TreePath targetPath = ((PluginTree) ((DropTarget) src)
.getComponent()).getPathForLocation(loc.x, loc.y);
Node target = (Node) targetPath.getLastPathComponent();
if(target.getProgramReceiveTarget() == null && targetPath.getPathCount() <= 2) {
target = (Node) targetPath.getPathComponent(1);
}
if (flavors[0].getHumanPresentableName().equals("NodeExport")) {
TreePath sourcePath = ((PluginTree) ((DropTarget) src)
.getComponent()).getSelectionPath();
Node plugin = (Node) sourcePath.getPathComponent(1);
Node source = (Node) sourcePath.getLastPathComponent();
if (target.equals(plugin) || targetPath.isDescendant(sourcePath) || sourcePath.isDescendant(targetPath)) {
return;
} else {
Vector<Program> vec;
if (source.isLeaf()) {
vec = new Vector<Program>();
if (source.getUserObject() instanceof ProgramItem) {
vec.addElement(((ProgramItem) source.getUserObject())
.getProgram());
}
} else {
vec = getLeafElements(source, new Vector<Program>());
}
Program[] p = vec.toArray(new Program[vec.size()]);
if(p.length > 0) {
if (target.equals(ReminderPlugin.getRootNode()
.getMutableTreeNode())) {
ReminderPlugin.getInstance().addPrograms(p);
} else if(target.getProgramReceiveTarget() == null) {
PluginProxy[] pa = PluginProxyManager.getInstance().getActivatedPlugins();
for (PluginProxy pluginAccess : pa) {
if (pluginAccess.getRootNode() != null) {
if (pluginAccess.getRootNode().getMutableTreeNode().equals(target)) {
if (pluginAccess.canReceiveProgramsWithTarget()
&& pluginAccess.getProgramReceiveTargets() != null
&& pluginAccess.getProgramReceiveTargets().length > 0) {
pluginAccess.receivePrograms(p,pluginAccess.getProgramReceiveTargets()[0]);
} else {
break;
}
}
}
}
}
else {
ProgramReceiveTarget receiveTarget = target.getProgramReceiveTarget();
receiveTarget.getReceifeIfForIdOfTarget().receivePrograms(p,receiveTarget);
}
}
}
} else if (flavors[0].getHumanPresentableName().equals("Program")) {
PluginProxy[] pa = PluginProxyManager.getInstance().getActivatedPlugins();
boolean found = false;
Program program = (Program) tr.getTransferData(flavors[0]);
for (PluginProxy pluginAccess : pa) {
if (pluginAccess.getRootNode().getMutableTreeNode().equals(target)) {
Action action = getAction(pluginAccess
.getContextMenuActions(program));