1 19 package org.openharmonise.him.dnd; 20 21 import java.awt.Point ; 22 import java.awt.dnd.DropTarget ; 23 import java.awt.dnd.DropTargetDragEvent ; 24 import java.awt.dnd.DropTargetDropEvent ; 25 import java.awt.dnd.DropTargetEvent ; 26 import java.awt.dnd.DropTargetListener ; 27 28 import javax.swing.JPopupMenu ; 29 import javax.swing.JTree ; 30 import javax.swing.tree.TreePath ; 31 32 import org.openharmonise.him.swing.resourcetree.*; 33 import org.openharmonise.him.window.menus.*; 34 import org.openharmonise.vfs.*; 35 import org.openharmonise.webdav.client.*; 36 37 38 45 public class TreeDropTarget implements DropTargetListener { 46 47 DropTarget target; 48 JTree targetTree; 49 50 55 public TreeDropTarget(ResourceTree tree) { 56 targetTree = tree.getTree(); 57 target = new DropTarget (targetTree, this); 58 } 59 60 63 public void dragEnter(DropTargetDragEvent arg0) { 64 } 65 66 69 public void dragOver(DropTargetDragEvent dtde) { 70 Point pt = dtde.getLocation(); 71 TreePath path = targetTree.getPathForLocation(pt.x, pt.y); 72 targetTree.setSelectionPath(path); 73 targetTree.expandPath(path); 74 } 75 76 79 public void dropActionChanged(DropTargetDragEvent arg0) { 80 } 81 82 90 private JPopupMenu getPopup(VirtualFile src, VirtualFile dst) { 91 return new MoveMenu(src, dst); 92 } 93 94 97 public void drop(DropTargetDropEvent dtde) { 98 Point pt = dtde.getLocation(); 99 TreePath path = targetTree.getClosestPathForLocation(pt.x,pt.y); 100 TreeNode node = (TreeNode)path.getLastPathComponent(); 101 while(node.isLeaf()) { 102 node = (TreeNode) node.getParent(); 103 } 104 105 VirtualFile src = null; 106 107 try { 108 src = (VirtualFile)dtde.getTransferable().getTransferData( VirtualFileTransferable.DAV_FLAVOR ); 109 } catch (Exception e) { 110 e.printStackTrace(System.out); 111 } 112 113 String sDestinationPath = node.getFilePath(); 114 115 WebDAVFileSystem webVFS = (WebDAVFileSystem) node.getVFS(); 116 117 VirtualFile dst = webVFS.getVirtualFile( sDestinationPath + "/" ).getResource(); 118 119 JPopupMenu popper = this.getPopup(src, dst); 120 121 popper.show(this.targetTree, pt.x, pt.y); 122 } 123 124 127 public void dragExit(DropTargetEvent arg0) { 128 } 129 130 } | Popular Tags |