summaryrefslogtreecommitdiffstats
path: root/idrop-swing
diff options
context:
space:
mode:
authorMike Conway <mikeconway@dhcp152-54-6-70.wireless.europa.renci.org>2011-06-24 17:50:09 (GMT)
committer Mike Conway <mikeconway@dhcp152-54-6-70.wireless.europa.renci.org>2011-06-24 17:50:09 (GMT)
commitf041319e8413a2cf8abe7345755126027903a661 (patch)
tree5c5186f8feef377a5a81349d685d84050866b96d /idrop-swing
parent8251904c0a8a24f186ffe0b41ade0d6a53537973 (diff)
downloadQCG-Data-f041319e8413a2cf8abe7345755126027903a661.zip
QCG-Data-f041319e8413a2cf8abe7345755126027903a661.tar.gz
QCG-Data-f041319e8413a2cf8abe7345755126027903a661.tar.bz2
[#153] local file dir copy/move
Diffstat (limited to 'idrop-swing')
-rw-r--r--idrop-swing/pom.xml5
-rw-r--r--idrop-swing/release_notes.txt1
-rw-r--r--idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalFileSystemModel.java23
-rw-r--r--idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalTreeTransferHandler.java98
4 files changed, 116 insertions, 11 deletions
diff --git a/idrop-swing/pom.xml b/idrop-swing/pom.xml
index 9602306..afd7435 100644
--- a/idrop-swing/pom.xml
+++ b/idrop-swing/pom.xml
@@ -119,6 +119,11 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>compile</scope>
+</dependency>
+ <dependency>
<groupId>org.irods.jargon</groupId>
<artifactId>jargon-user-tagging</artifactId>
<scope>compile</scope>
diff --git a/idrop-swing/release_notes.txt b/idrop-swing/release_notes.txt
index 715e578..8d2b4ff 100644
--- a/idrop-swing/release_notes.txt
+++ b/idrop-swing/release_notes.txt
@@ -7,3 +7,4 @@ work in progress -- Milestone 0.9.8
*[#308] irods tree does not refresh when deleting a directory
* [#61] delete local file multi-select
*[#254] drag and drop, desktop to irods file should use irods parent as target
+*[#153] local file dir copy/move
diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalFileSystemModel.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalFileSystemModel.java
index be614b0..2902c8c 100644
--- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalFileSystemModel.java
+++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalFileSystemModel.java
@@ -28,6 +28,29 @@ public class LocalFileSystemModel extends DefaultTreeModel {
localFileNode.lazyLoadOfChildrenOfThisNode();
}
+ public void notifyFileShouldBeAdded(final LocalFileTree fileTree, final String newFileAbsolutePath) throws IdropException {
+ TreePath parentNodePath = TreeUtils.buildTreePathForLocalAbsolutePath(fileTree,
+ newFileAbsolutePath);
+ log.debug("tree path for put: {}", parentNodePath);
+ LocalFileNode targetNode = (LocalFileNode) parentNodePath.getLastPathComponent();
+ File entry = (File) targetNode.getUserObject();
+ if (entry.isFile()) {
+ log.info("substitute parent as target, as given node was a leaf");
+ targetNode = (LocalFileNode) targetNode.getParent();
+ }
+ targetNode.forceReloadOfChildrenOfThisNode();
+ targetNode.lazyLoadOfChildrenOfThisNode();
+ this.reload(targetNode);
+ if (entry.isFile()) {
+ parentNodePath = TreeUtils.buildTreePathForLocalAbsolutePath(fileTree, entry.getParent());
+ fileTree.highlightPath(parentNodePath);
+ } else {
+ fileTree.highlightPath(parentNodePath);
+
+ }
+
+ }
+
public void notifyCompletionOfOperation(final LocalFileTree fileTree, final TransferStatus transferStatus)
throws IdropException {
log.info("tree model notified of status:{}", transferStatus);
diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalTreeTransferHandler.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalTreeTransferHandler.java
index c22ef23..57893b2 100644
--- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalTreeTransferHandler.java
+++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/LocalTreeTransferHandler.java
@@ -16,12 +16,17 @@ import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.TransferHandler;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreePath;
+import org.apache.commons.io.FileUtils;
import org.irods.jargon.core.exception.JargonException;
import org.irods.jargon.core.pub.io.IRODSFile;
import org.irods.jargon.idrop.desktop.systraygui.iDrop;
+import org.irods.jargon.idrop.exceptions.IdropException;
import org.irods.jargon.idrop.exceptions.IdropRuntimeException;
+import org.openide.util.Exceptions;
import org.slf4j.LoggerFactory;
/**
@@ -32,7 +37,6 @@ import org.slf4j.LoggerFactory;
public class LocalTreeTransferHandler extends TransferHandler {
public static org.slf4j.Logger log = LoggerFactory.getLogger(LocalTreeTransferHandler.class);
-
public final iDrop idropGui;
@Override
@@ -59,8 +63,7 @@ public class LocalTreeTransferHandler extends TransferHandler {
tree.setDirtyRegion(firstRowRect);
g.setColor(tree.getHighlightColor());
- g.fillRect((int) tree.getDirtyRegion().getX(), (int) tree.getDirtyRegion().getY(), (int) tree
- .getDirtyRegion().getWidth(), (int) tree.getDirtyRegion().getHeight());
+ g.fillRect((int) tree.getDirtyRegion().getX(), (int) tree.getDirtyRegion().getY(), (int) tree.getDirtyRegion().getWidth(), (int) tree.getDirtyRegion().getHeight());
tree.setHighlightedRow(closestRow);
}
}
@@ -122,7 +125,7 @@ public class LocalTreeTransferHandler extends TransferHandler {
} else if (flavor.getMimeType().equals(
"application/x-java-jvm-local-objectref; class=javax.swing.tree.TreeSelectionModel")) {
log.info("process drop as serialized object");
- processDropFromSerializedObjectType(transferable, nodeThatWasDropTargetAsFile);
+ processDropFromSerializedObjectType(transferable, nodeThatWasDropTargetAsFile, flavor, ts.getUserDropAction());
imported = true;
break;
} else {
@@ -190,10 +193,8 @@ public class LocalTreeTransferHandler extends TransferHandler {
if (transferFile instanceof IRODSFile) {
log.info("initiating a transfer of iRODS file:{}", transferFile.getAbsolutePath());
log.info("transfer to local file:{}", tempTargetLocalFileAbsolutePath);
- idropGui.getiDropCore()
- .getTransferManager()
- .enqueueAGet(transferFile.getAbsolutePath(), tempTargetLocalFileAbsolutePath,
- "", idropGui.getIrodsAccount());
+ idropGui.getiDropCore().getTransferManager().enqueueAGet(transferFile.getAbsolutePath(), tempTargetLocalFileAbsolutePath,
+ "", idropGui.getIrodsAccount());
} else {
log.info("process a local to local move with source...not yet implemented : {}",
transferFile.getAbsolutePath());
@@ -211,8 +212,84 @@ public class LocalTreeTransferHandler extends TransferHandler {
}
}
- private void processDropFromSerializedObjectType(Transferable transferable, File parent) {
- log.debug("processing as a drop of a serialized object");
+ /**
+ * Drop from local file tree onto local file tree for copy/move operation
+ * @param transferable
+ * @param parent
+ */
+ private void processDropFromSerializedObjectType(Transferable transferable, File parent, DataFlavor flavor, int userDropAction) {
+
+ log.info("process as drop of file list to target:{}", parent.getAbsolutePath());
+
+ File effectiveTarget;
+ if (parent.isDirectory()) {
+ effectiveTarget = parent;
+ } else {
+ effectiveTarget = parent.getParentFile();
+ }
+ try {
+ Object transferObj = transferable.getTransferData(flavor);
+ log.debug("transfer object:{}", transferObj);
+
+ boolean isTreeModel = transferObj instanceof DefaultTreeSelectionModel;
+ if (!isTreeModel) {
+ log.warn("unknown object type in transferable for local file tree");
+ return;
+ }
+
+ DefaultTreeSelectionModel transferableAsTreeModel = (DefaultTreeSelectionModel) transferObj;
+
+ LocalFileSystemModel fileSystemModel = (LocalFileSystemModel) idropGui.getFileTree().getModel();
+ log.debug("tree model in transferable:{}", transferableAsTreeModel);
+
+ TreePath[] selectionPaths = transferableAsTreeModel.getSelectionPaths();
+
+ File sourceFile;
+ LocalFileNode sourceNode;
+ for (TreePath selectionPath : selectionPaths) {
+ sourceNode = (LocalFileNode) selectionPath.getLastPathComponent();
+ sourceFile = (File) sourceNode.getUserObject();
+ log.info("sourceFile:{}", sourceFile.getAbsolutePath());
+
+ // target normalized to a directory
+ if (sourceFile.isDirectory()) {
+ if (userDropAction == 1) {
+ FileUtils.copyDirectoryToDirectory(sourceFile, effectiveTarget);
+
+ } else {
+ FileUtils.moveDirectory(sourceFile, effectiveTarget);
+ LocalFileNode parentNode = (LocalFileNode) sourceNode.getParent();
+ parentNode.remove(sourceNode);
+ }
+ fileSystemModel.notifyFileShouldBeAdded(idropGui.getFileTree(), effectiveTarget.getAbsolutePath());
+ } else {
+ if (userDropAction == 1) {
+ FileUtils.copyFileToDirectory(sourceFile, effectiveTarget);
+
+ } else {
+ FileUtils.moveToDirectory(sourceFile, effectiveTarget, false);
+ LocalFileNode parentNode = (LocalFileNode) sourceNode.getParent();
+ parentNode.remove(sourceNode);
+ }
+ fileSystemModel.notifyFileShouldBeAdded(idropGui.getFileTree(), effectiveTarget.getAbsolutePath() + "/" + sourceFile.getName());
+
+ }
+
+ }
+
+ } catch (IdropException ex) {
+ log.error("error updating local file tree after add", ex);
+ throw new IdropRuntimeException(ex);
+
+ } catch (UnsupportedFlavorException ex) {
+ log.error("error updating local file tree after add", ex);
+ throw new IdropRuntimeException(ex);
+ } catch (IOException ex) {
+ log.error("error updating local file tree after add", ex);
+ throw new IdropRuntimeException(ex);
+ }
+
+
}
public LocalTreeTransferHandler(final iDrop idropGui) {
@@ -235,5 +312,4 @@ public class LocalTreeTransferHandler extends TransferHandler {
protected void exportDone(JComponent jc, Transferable t, int i) {
super.exportDone(jc, t, i);
}
-
}