001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.dnd;
020:
021: import java.awt.Point;
022: import java.awt.dnd.DropTarget;
023: import java.awt.dnd.DropTargetDragEvent;
024: import java.awt.dnd.DropTargetDropEvent;
025: import java.awt.dnd.DropTargetEvent;
026: import java.awt.dnd.DropTargetListener;
027:
028: import javax.swing.JPopupMenu;
029: import javax.swing.JTree;
030: import javax.swing.tree.TreePath;
031:
032: import org.openharmonise.him.swing.resourcetree.*;
033: import org.openharmonise.him.window.menus.*;
034: import org.openharmonise.vfs.*;
035: import org.openharmonise.webdav.client.*;
036:
037: /**
038: * Drop target for the resource tree. Used for copying/moving resources.
039: *
040: * @author Matthew Large
041: * @version $Revision: 1.1 $
042: *
043: */
044: public class TreeDropTarget implements DropTargetListener {
045:
046: DropTarget target;
047: JTree targetTree;
048:
049: /**
050: * Constructs a new tree drop target.
051: *
052: * @param tree Resource tree
053: */
054: public TreeDropTarget(ResourceTree tree) {
055: targetTree = tree.getTree();
056: target = new DropTarget(targetTree, this );
057: }
058:
059: /* (non-Javadoc)
060: * @see java.awt.dnd.DropTargetListener#dragEnter(java.awt.dnd.DropTargetDragEvent)
061: */
062: public void dragEnter(DropTargetDragEvent arg0) {
063: }
064:
065: /* (non-Javadoc)
066: * @see java.awt.dnd.DropTargetListener#dragOver(java.awt.dnd.DropTargetDragEvent)
067: */
068: public void dragOver(DropTargetDragEvent dtde) {
069: Point pt = dtde.getLocation();
070: TreePath path = targetTree.getPathForLocation(pt.x, pt.y);
071: targetTree.setSelectionPath(path);
072: targetTree.expandPath(path);
073: }
074:
075: /* (non-Javadoc)
076: * @see java.awt.dnd.DropTargetListener#dropActionChanged(java.awt.dnd.DropTargetDragEvent)
077: */
078: public void dropActionChanged(DropTargetDragEvent arg0) {
079: }
080:
081: /**
082: * Returns the popup menu which appears at the end of a drag and
083: * drop from a table view to the resource tree.
084: *
085: * @param src Source virtual file
086: * @param dst Destination virtual file
087: * @return Popup menu
088: */
089: private JPopupMenu getPopup(VirtualFile src, VirtualFile dst) {
090: return new MoveMenu(src, dst);
091: }
092:
093: /* (non-Javadoc)
094: * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
095: */
096: public void drop(DropTargetDropEvent dtde) {
097: Point pt = dtde.getLocation();
098: TreePath path = targetTree
099: .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(
109: VirtualFileTransferable.DAV_FLAVOR); /*ex.getSelectedTableFile();*/
110: } catch (Exception e) {
111: e.printStackTrace(System.out);
112: }
113:
114: String sDestinationPath = node.getFilePath();
115:
116: WebDAVFileSystem webVFS = (WebDAVFileSystem) node.getVFS();
117:
118: VirtualFile dst = webVFS.getVirtualFile(sDestinationPath + "/")
119: .getResource();
120:
121: JPopupMenu popper = this .getPopup(src, dst);
122:
123: popper.show(this .targetTree, pt.x, pt.y);
124: }
125:
126: /* (non-Javadoc)
127: * @see java.awt.dnd.DropTargetListener#dragExit(java.awt.dnd.DropTargetEvent)
128: */
129: public void dragExit(DropTargetEvent arg0) {
130: }
131:
132: }
|