diff options
4 files changed, 107 insertions, 71 deletions
diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/MoveOrCopyiRODSDialog.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/MoveOrCopyiRODSDialog.java index 4f8f5bd..d691805 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/MoveOrCopyiRODSDialog.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/MoveOrCopyiRODSDialog.java @@ -38,13 +38,21 @@ import org.slf4j.LoggerFactory; public class MoveOrCopyiRODSDialog extends javax.swing.JDialog { private final iDrop idrop; + private final IRODSTree stagingViewTree; + private final IRODSOutlineModel irodsFileSystemModel; + private final IRODSNode targetNode; + private final String targetAbsolutePath; + private final IRODSFile sourceFile; + private final List<IRODSFile> sourceFiles; + public static org.slf4j.Logger log = LoggerFactory.getLogger(MoveOrCopyiRODSDialog.class); + private final boolean isCopy; public MoveOrCopyiRODSDialog(final iDrop parent, final boolean modal, final IRODSNode targetNode, @@ -314,7 +322,8 @@ public class MoveOrCopyiRODSDialog extends javax.swing.JDialog { DataTransferOperations dataTransferOperations; try { - dataTransferOperations = idrop.getiDropCore().getIRODSAccessObjectFactory().getDataTransferOperations(idrop.getIrodsAccount()); + dataTransferOperations = idrop.getiDropCore().getIRODSAccessObjectFactory() + .getDataTransferOperations(idrop.getIrodsAccount()); } catch (Exception e) { idrop.getiDropCore().closeIRODSConnection(idrop.getIrodsAccount()); thisDialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); @@ -399,7 +408,8 @@ public class MoveOrCopyiRODSDialog extends javax.swing.JDialog { log.debug("source file is a file, do a move"); dataTransferOperations.move(sourceFile.getAbsolutePath(), targetAbsolutePath); - IRODSFile targetFile = idrop.getiDropCore().getIRODSFileFactoryForLoggedInAccount().instanceIRODSFile(targetAbsolutePath); + IRODSFile targetFile = idrop.getiDropCore().getIRODSFileFactoryForLoggedInAccount() + .instanceIRODSFile(targetAbsolutePath); String targetPathForNotify = null; if (targetFile.isDirectory()) { targetPathForNotify = targetFile.getAbsolutePath() + "/" + sourceFile.getName(); @@ -411,8 +421,9 @@ public class MoveOrCopyiRODSDialog extends javax.swing.JDialog { } else { log.debug("source file is a collection, reparent it"); - dataTransferOperations.moveTheSourceCollectionUnderneathTheTargetCollectionUsingSourceParentCollectionName( - sourceFile.getAbsolutePath(), targetAbsolutePath); + dataTransferOperations + .moveTheSourceCollectionUnderneathTheTargetCollectionUsingSourceParentCollectionName( + sourceFile.getAbsolutePath(), targetAbsolutePath); irodsFileSystemModel.notifyFileShouldBeAdded(stagingViewTree, targetAbsolutePath); } } catch (JargonFileOrCollAlreadyExistsException fcae) { @@ -434,8 +445,10 @@ public class MoveOrCopyiRODSDialog extends javax.swing.JDialog { private void processACopyOfAnIndividualFile(DataTransferOperations dataTransferOperations, IRODSFile sourceFile, String targetAbsolutePath) throws IdropException { try { - idrop.getiDropCore().getTransferManager().enqueueACopy(sourceFile.getAbsolutePath(), sourceFile.getResource(), targetAbsolutePath, - idrop.getiDropCore().getIrodsAccount()); + idrop.getiDropCore() + .getTransferManager() + .enqueueACopy(sourceFile.getAbsolutePath(), sourceFile.getResource(), targetAbsolutePath, + idrop.getiDropCore().getIrodsAccount()); } catch (JargonException ex) { Logger.getLogger(MoveOrCopyiRODSDialog.class.getName()).log(Level.SEVERE, null, ex); diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/RenameIRODSDirectoryDialog.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/RenameIRODSDirectoryDialog.java index 40c7bf7..e4bacb3 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/RenameIRODSDirectoryDialog.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/RenameIRODSDirectoryDialog.java @@ -21,14 +21,19 @@ import javax.swing.Action; import javax.swing.JComponent; import javax.swing.KeyStroke; import javax.swing.tree.TreePath; +import org.irods.jargon.core.exception.JargonException; +import org.irods.jargon.core.pub.io.IRODSFile; +import org.irods.jargon.core.query.CollectionAndDataObjectListingEntry; import org.irods.jargon.idrop.desktop.systraygui.services.IRODSFileService; import org.irods.jargon.idrop.desktop.systraygui.utils.TreeUtils; import org.irods.jargon.idrop.desktop.systraygui.viscomponents.IRODSFileSystemModel; import org.irods.jargon.idrop.desktop.systraygui.viscomponents.IRODSNode; +import org.irods.jargon.idrop.desktop.systraygui.viscomponents.IRODSOutlineModel; import org.irods.jargon.idrop.desktop.systraygui.viscomponents.IRODSTree; import org.irods.jargon.idrop.exceptions.IdropException; import org.irods.jargon.idrop.exceptions.IdropRuntimeException; +import org.openide.util.Exceptions; import org.slf4j.LoggerFactory; /** @@ -37,15 +42,11 @@ import org.slf4j.LoggerFactory; * @author mikeconway */ public class RenameIRODSDirectoryDialog extends javax.swing.JDialog { - + private final iDrop idrop; - private final String currentAbsolutePath; - private final IRODSTree stagingViewTree; - private final IRODSNode currentNode; - public static org.slf4j.Logger log = LoggerFactory.getLogger(RenameIRODSDirectoryDialog.class); /** Creates new form NewIRODSDirectoryDialog */ @@ -64,13 +65,13 @@ public class RenameIRODSDirectoryDialog extends javax.swing.JDialog { idrop.showIdropException(new IdropException(msg)); return; } - + String parentAbsPath = currentAbsolutePath.substring(0, lastPathPartIdx); String currentCollectionOrFileName = currentAbsolutePath.substring(lastPathPartIdx + 1); - + log.debug("computed parent abs path as:{}", parentAbsPath); log.debug("computed current file or collection name as:{}", currentCollectionOrFileName); - + txtCurrentFolder.setText(currentCollectionOrFileName); registerKeystrokeListener(); } @@ -267,7 +268,6 @@ public class RenameIRODSDirectoryDialog extends javax.swing.JDialog { private javax.swing.JTextField txtNewFolder; // End of variables declaration//GEN-END:variables - private void doRename() { // add the new folder to irods, add to the tree, and scroll the tree into view @@ -276,29 +276,29 @@ public class RenameIRODSDirectoryDialog extends javax.swing.JDialog { idrop.showMessageFromOperation("please enter a new file or collection name"); return; } - + final RenameIRODSDirectoryDialog thisDialog = this; - + java.awt.EventQueue.invokeLater(new Runnable() { - + @Override public void run() { log.info("renaming a file named:{}", txtCurrentFolder.getText()); thisDialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { - - IRODSFileService irodsFileService = new IRODSFileService(idrop.getIrodsAccount(), idrop - .getiDropCore().getIrodsFileSystem()); + + IRODSFileService irodsFileService = new IRODSFileService(idrop.getIrodsAccount(), idrop.getiDropCore().getIrodsFileSystem()); String newPath = irodsFileService.renameIRODSFileOrDirectory(currentAbsolutePath, txtNewFolder.getText()); + log.debug("New path:{}", newPath); - IRODSFileSystemModel irodsFileSystemModel = (IRODSFileSystemModel) stagingViewTree.getModel(); + IRODSOutlineModel irodsOutlineModel = (IRODSOutlineModel) stagingViewTree.getModel(); // get the parent of the new directory, and force a reload of that parent String[] dirs = newPath.split("/"); if (dirs.length == 0) { throw new IdropRuntimeException("unable to find dir components"); } - + StringBuilder sb = new StringBuilder(); for (int i = 0; i < dirs.length - 1; i++) { if (i > 0) { @@ -306,26 +306,50 @@ public class RenameIRODSDirectoryDialog extends javax.swing.JDialog { } sb.append(dirs[i]); } - + String parentOfNewDir = sb.toString(); log.info("parent of new dir:{}", parentOfNewDir); - - TreePath pathForNew = TreeUtils.buildTreePathForIrodsAbsolutePath(stagingViewTree, parentOfNewDir); - log.debug("computed new path:{}", pathForNew); - IRODSNode targetParentNode = (IRODSNode) pathForNew.getParentPath().getLastPathComponent(); + + TreePath pathForOld = TreeUtils.buildTreePathForIrodsAbsolutePath(stagingViewTree, currentAbsolutePath); + + if (pathForOld == null) { + log.warn("could not find old path for node:{}, ignoring", currentAbsolutePath); + } else { + IRODSFileSystemModel irodsFileSystemModel = irodsOutlineModel.getTreeModel(); + IRODSNode oldNode = (IRODSNode) pathForOld.getLastPathComponent(); + CollectionAndDataObjectListingEntry nodesEntry = (CollectionAndDataObjectListingEntry) oldNode.getUserObject(); + IRODSFile newEntryAsFile = idrop.getiDropCore().getIRODSFileFactoryForLoggedInAccount().instanceIRODSFile(newPath); + if (newEntryAsFile.isDirectory()) { + nodesEntry.setParentPath(newEntryAsFile.getParent()); + nodesEntry.setPathOrName(newEntryAsFile.getAbsolutePath()); + } else { + nodesEntry.setParentPath(newEntryAsFile.getParent()); + nodesEntry.setPathOrName(newEntryAsFile.getName()); + } + + oldNode.setUserObject(nodesEntry); + irodsFileSystemModel.nodeChanged(oldNode); + + } + + // TreePath pathForNew = TreeUtils.buildTreePathForIrodsAbsolutePath(stagingViewTree, parentOfNewDir); + // log.debug("computed new path:{}", pathForNew); + /*IRODSNode targetParentNode = (IRODSNode) pathForNew.getParentPath().getLastPathComponent(); targetParentNode.forceReloadOfChildrenOfThisNode(); - irodsFileSystemModel.reload(targetParentNode); + irodsOutlineModel.reload(targetParentNode); stagingViewTree.expandPath(pathForNew); + * */ - // idrop.showMessageFromOperation("The rename was successful"); - } catch (IdropException ex) { + idrop.showMessageFromOperation("The rename was successful"); + + } catch (Exception ex) { Logger.getLogger(RenameIRODSDirectoryDialog.class.getName()).log(Level.SEVERE, null, ex); idrop.showIdropException(ex); } finally { thisDialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } - + thisDialog.dispose(); } }); @@ -335,16 +359,16 @@ public class RenameIRODSDirectoryDialog extends javax.swing.JDialog { * Register a listener for the enter event, so login can occur. */ private void registerKeystrokeListener() { - + KeyStroke enter = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0); Action enterAction = new AbstractAction() { - + @Override public void actionPerformed(ActionEvent e) { doRename(); } }; btnOK.registerKeyboardAction(enterAction, enter, JComponent.WHEN_IN_FOCUSED_WINDOW); - + } } diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/IRODSOutlineModel.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/IRODSOutlineModel.java index ca9e899..ffe087e 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/IRODSOutlineModel.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/IRODSOutlineModel.java @@ -34,8 +34,11 @@ public class IRODSOutlineModel extends DefaultOutlineModel { public static final org.slf4j.Logger log = LoggerFactory.getLogger(IRODSOutlineModel.class); private final IRODSFileSystemModel treeModel; + public IRODSFileSystemModel getTreeModel() { + return treeModel; + } private iDrop idrop; - + public IRODSOutlineModel(iDrop idrop, TreeModel tm, TableModel tm1, boolean bln, String string) { super(tm, tm1, bln, string); this.treeModel = (IRODSFileSystemModel) tm; @@ -44,54 +47,45 @@ public class IRODSOutlineModel extends DefaultOutlineModel { public IRODSOutlineModel(iDrop idrop, TreeModel tm, RowModel rm, boolean bln, String string) { super(tm, rm, bln, string); - this.treeModel = (IRODSFileSystemModel) tm; + this.treeModel = (IRODSFileSystemModel) tm; this.idrop = idrop; } public void notifyFileShouldBeRemoved(final IRODSNode deletedNode) throws IdropException { + if (deletedNode == null) { return; } log.info("deleting node from parent:{}", deletedNode); final IRODSNode parent = (IRODSNode) deletedNode.getParent(); - + if (parent == null) { return; } - + final IRODSOutlineModel thisModel = this; java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { - CollectionAndDataObjectListingEntry entry = (CollectionAndDataObjectListingEntry) ((IRODSNode) parent) - .getUserObject(); - IRODSTree stagingViewTree = idrop.getIrodsTree(); - TreePath path; + CollectionAndDataObjectListingEntry deletedEntry = (CollectionAndDataObjectListingEntry) deletedNode.getUserObject(); + CollectionAndDataObjectListingEntry entry = (CollectionAndDataObjectListingEntry) ((IRODSNode) parent).getUserObject(); + IRODSTree stagingViewTree = idrop.getIrodsTree(); + TreePath path; + try { path = TreeUtils.buildTreePathForIrodsAbsolutePath(stagingViewTree, - entry.getFormattedAbsolutePath()); + entry.getFormattedAbsolutePath()); + } catch (IdropException ex) { - Logger.getLogger(IRODSOutlineModel.class.getName()).log(Level.SEVERE, null, ex); - throw new IdropRuntimeException(ex); + Logger.getLogger(IRODSOutlineModel.class.getName()).log(Level.SEVERE, null, ex); + throw new IdropRuntimeException(ex); } - - // thisModel.getTreePathSupport().removePath(path); - parent.remove(deletedNode); - - - //parent.forceReloadOfChildrenOfThisNode(); - treeModel.nodeChanged(deletedNode); - treeModel.nodeChanged(parent); - - //treeModel.nodeChanged(parent); - - //stagingViewTree.highlightPath(path); - - - + + thisModel.treeModel.removeNodeFromParent(deletedNode); + } }); } @@ -109,7 +103,7 @@ public class IRODSOutlineModel extends DefaultOutlineModel { || transferStatus.getTransferType() == TransferStatus.TransferType.COPY) { log.info("successful put transfer, find the parent tree node, and clear the children"); notifyFileShouldBeAdded(irodsTree, transferStatus.getTargetFileAbsolutePath()); - + } } @@ -125,25 +119,27 @@ public class IRODSOutlineModel extends DefaultOutlineModel { try { try { // if the node already exists (e.g. an overwrite, don' add it - - TreePath currentPath = TreeUtils.buildTreePathForIrodsAbsolutePath(irodsTree, irodsFileAbsolutePath); + + TreePath currentPath = TreeUtils.buildTreePathForIrodsAbsolutePath(irodsTree, + irodsFileAbsolutePath); // build treePath will return parent if child not found if (currentPath == null) { - log.warn("null tree path found for:{} logged and ignored as a warning", irodsFileAbsolutePath); + log.warn("null tree path found for:{} logged and ignored as a warning", + irodsFileAbsolutePath); return; } IRODSNode irodsNode = (IRODSNode) currentPath.getLastPathComponent(); - CollectionAndDataObjectListingEntry lastPathNodeEntry = (CollectionAndDataObjectListingEntry) irodsNode.getUserObject(); + CollectionAndDataObjectListingEntry lastPathNodeEntry = (CollectionAndDataObjectListingEntry) irodsNode.getUserObject(); if (irodsFileAbsolutePath.equals(lastPathNodeEntry.getFormattedAbsolutePath())) { log.info("path already exists, do not double-add"); return; } - + } catch (IdropException ex) { Logger.getLogger(IRODSOutlineModel.class.getName()).log(Level.SEVERE, null, ex); throw new IdropRuntimeException(ex); } - + IRODSFile addedFile = irodsFileFactory.instanceIRODSFile(irodsFileAbsolutePath); if (!addedFile.exists()) { log.info("looking for file that was added, I don't find it, so just move on: {}", @@ -178,8 +174,7 @@ public class IRODSOutlineModel extends DefaultOutlineModel { newEntry.setPathOrName(addedFile.getName()); } - IRODSNode newNode = new IRODSNode(newEntry, idrop.getiDropCore().getIrodsAccount(), idrop - .getiDropCore().getIrodsFileSystem(), irodsTree); + IRODSNode newNode = new IRODSNode(newEntry, idrop.getiDropCore().getIrodsAccount(), idrop.getiDropCore().getIrodsFileSystem(), irodsTree); ((IRODSNode) parentPath.getLastPathComponent()).add(newNode); irodsTree.highlightPath(parentPath); } catch (JargonException ex) { diff --git a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/IrodsSelectionListenerForBuildingInfoPanel.java b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/IrodsSelectionListenerForBuildingInfoPanel.java index d929715..19292a7 100644 --- a/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/IrodsSelectionListenerForBuildingInfoPanel.java +++ b/idrop-swing/src/main/java/org/irods/jargon/idrop/desktop/systraygui/viscomponents/IrodsSelectionListenerForBuildingInfoPanel.java @@ -5,6 +5,7 @@ package org.irods.jargon.idrop.desktop.systraygui.viscomponents; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -154,9 +155,11 @@ public class IrodsSelectionListenerForBuildingInfoPanel implements ListSelection if (irodsFileSystemModel == null) { irodsFileSystemModel = (IRODSOutlineModel) idrop.getIrodsTree().getModel(); } + + ListSelectionModel selectionModel = idrop.getIrodsTree().getSelectionModel(); + int idx = selectionModel.getLeadSelectionIndex(); // use first selection for info - int idx = lse.getLastIndex(); IRODSNode selectedNode = (IRODSNode) irodsFileSystemModel.getValueAt(idx, 0); log.info("selected node to initialize info panel:{}", selectedNode); try { @@ -165,5 +168,6 @@ public class IrodsSelectionListenerForBuildingInfoPanel implements ListSelection Logger.getLogger(IrodsSelectionListenerForBuildingInfoPanel.class.getName()).log(Level.SEVERE, null, ex); throw new IdropRuntimeException("error initializing info panel for selected irods node"); } + } } |