Search in sources :

Example 1 with ITask

use of org.freeplane.plugin.workspace.io.ITask in project freeplane by freeplane.

the class FileFolderDropHandler method getPostOperation.

private ITask getPostOperation(final AWorkspaceTreeNode targetNode, final AWorkspaceTreeNode node, final File srcFile, final File destFile) {
    return new ITask() {

        public void exec(Properties properties) throws IOException {
            if (onSkipList(destFile.getParentFile(), properties)) {
                throw new SkipTaskException();
            }
            AWorkspaceTreeNode parent = node.getParent();
            targetNode.getModel().cutNodeFromParent(node);
            parent.refresh();
            targetNode.getModel().nodeMoved(node, srcFile, destFile);
        }

        private boolean onSkipList(File dest, Properties properties) {
            if (properties == null || dest == null) {
                return false;
            }
            String list = properties.getProperty("skippedDirs", "");
            String entry = dest.getPath() + ";";
            if (list.contains(entry)) {
                return true;
            }
            return false;
        }
    };
}
Also used : ITask(org.freeplane.plugin.workspace.io.ITask) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) SkipTaskException(org.freeplane.plugin.workspace.io.SkipTaskException) Properties(java.util.Properties) File(java.io.File)

Example 2 with ITask

use of org.freeplane.plugin.workspace.io.ITask in project freeplane by freeplane.

the class FileFolderDropHandler method processWorkspaceNodeDrop.

/**
 *********************************************************************************
 * CONSTRUCTORS
 *********************************************************************************
 */
/**
 *********************************************************************************
 * METHODS
 *********************************************************************************
 */
private void processWorkspaceNodeDrop(AWorkspaceTreeNode targetNode, List<AWorkspaceTreeNode> nodes, int dropAction) {
    try {
        File targetDir = ((IFileSystemRepresentation) targetNode).getFile();
        if (targetDir != null && targetDir.isDirectory()) {
            List<ITask> opList = new ArrayList<ITask>();
            for (AWorkspaceTreeNode node : nodes) {
                if (node instanceof DefaultFileNode) {
                    File srcFile = ((DefaultFileNode) node).getFile();
                    if (srcFile.equals(targetDir)) {
                        continue;
                    }
                    File destFile = new File(targetDir, srcFile.getName());
                    if (dropAction == DnDConstants.ACTION_COPY) {
                        FileSystemManager.buildCopyOperationList(srcFile, destFile, opList);
                    } else if (dropAction == DnDConstants.ACTION_MOVE) {
                        FileSystemManager.buildMoveOperationList(srcFile, destFile, opList);
                        opList.add(getPostOperation(targetNode, node, srcFile, destFile));
                    }
                } else if (node instanceof LinkTypeFileNode) {
                    File srcFile = URIUtils.getAbsoluteFile(((LinkTypeFileNode) node).getLinkURI());
                    if (srcFile.equals(targetDir)) {
                        continue;
                    }
                    File destFile = new File(targetDir, srcFile.getName());
                    FileSystemManager.buildCopyOperationList(srcFile, destFile, opList);
                    if (dropAction == DnDConstants.ACTION_MOVE) {
                        opList.add(getPostOperation(targetNode, node, srcFile, destFile));
                    }
                } else if (node instanceof FolderLinkNode) {
                    File srcFile = URIUtils.getAbsoluteFile(((FolderLinkNode) node).getPath());
                    if (srcFile.equals(targetDir)) {
                        continue;
                    }
                    File destFile = new File(targetDir, srcFile.getName());
                    FileSystemManager.buildCopyOperationList(srcFile, destFile, opList);
                    if (dropAction == DnDConstants.ACTION_MOVE) {
                        opList.add(getPostOperation(targetNode, node, srcFile, destFile));
                    }
                }
            }
            FileSystemManager.execOperations(opList);
        }
    } catch (Exception e) {
        LogUtils.warn(e);
    }
}
Also used : IFileSystemRepresentation(org.freeplane.plugin.workspace.io.IFileSystemRepresentation) ITask(org.freeplane.plugin.workspace.io.ITask) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) LinkTypeFileNode(org.freeplane.plugin.workspace.nodes.LinkTypeFileNode) ArrayList(java.util.ArrayList) File(java.io.File) DefaultFileNode(org.freeplane.plugin.workspace.nodes.DefaultFileNode) IOException(java.io.IOException) SkipTaskException(org.freeplane.plugin.workspace.io.SkipTaskException) FolderLinkNode(org.freeplane.plugin.workspace.nodes.FolderLinkNode)

Aggregations

File (java.io.File)2 ITask (org.freeplane.plugin.workspace.io.ITask)2 SkipTaskException (org.freeplane.plugin.workspace.io.SkipTaskException)2 AWorkspaceTreeNode (org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 IFileSystemRepresentation (org.freeplane.plugin.workspace.io.IFileSystemRepresentation)1 DefaultFileNode (org.freeplane.plugin.workspace.nodes.DefaultFileNode)1 FolderLinkNode (org.freeplane.plugin.workspace.nodes.FolderLinkNode)1 LinkTypeFileNode (org.freeplane.plugin.workspace.nodes.LinkTypeFileNode)1