Search in sources :

Example 1 with DefaultFileNode

use of org.freeplane.plugin.workspace.nodes.DefaultFileNode in project freeplane by freeplane.

the class FileNodeDeleteAction method deleteFile.

private void deleteFile(final AWorkspaceTreeNode node) {
    if (node instanceof DefaultFileNode) {
        ((DefaultFileNode) node).delete();
    } else if (node instanceof LinkTypeFileNode) {
        File file = URIUtils.getAbsoluteFile(((LinkTypeFileNode) node).getLinkURI());
        if (file != null) {
            if (!file.delete()) {
            // show message?
            }
        }
    }
    AWorkspaceTreeNode parent = node.getParent();
    node.getModel().removeNodeFromParent(node);
    parent.refresh();
    parent.getModel().requestSave();
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) LinkTypeFileNode(org.freeplane.plugin.workspace.nodes.LinkTypeFileNode) File(java.io.File) DefaultFileNode(org.freeplane.plugin.workspace.nodes.DefaultFileNode)

Example 2 with DefaultFileNode

use of org.freeplane.plugin.workspace.nodes.DefaultFileNode in project freeplane by freeplane.

the class NodeRemoveAction method actionPerformed.

/**
 *********************************************************************************
 * REQUIRED METHODS FOR INTERFACES
 *********************************************************************************
 */
public void actionPerformed(ActionEvent e) {
    AWorkspaceTreeNode[] targetNodes = getSelectedNodes(e);
    if (targetNodes.length <= 0) {
        return;
    }
    String question = "the selected nodes";
    if (targetNodes.length == 1) {
        question = targetNodes[0].getName();
    }
    int option = JOptionPane.showConfirmDialog(UITools.getFrame(), TextUtils.format("workspace.action.node.remove.confirm.text", question), TextUtils.getRawText("workspace.action.node.remove.confirm.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (option == JOptionPane.YES_OPTION) {
        for (AWorkspaceTreeNode targetNode : targetNodes) {
            AWorkspaceTreeNode parent = targetNode.getParent();
            if (targetNode instanceof DefaultFileNode) {
                // WORKSPACE - info: used in case of key events
                ((DefaultFileNode) targetNode).delete();
            } else {
                targetNode.getModel().removeNodeFromParent(targetNode);
            }
            if (parent != null) {
                parent.refresh();
            }
        }
    }
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) DefaultFileNode(org.freeplane.plugin.workspace.nodes.DefaultFileNode)

Example 3 with DefaultFileNode

use of org.freeplane.plugin.workspace.nodes.DefaultFileNode 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)

Example 4 with DefaultFileNode

use of org.freeplane.plugin.workspace.nodes.DefaultFileNode in project freeplane by freeplane.

the class ProjectModel method getAllNodesFiltered.

public List<URI> getAllNodesFiltered(String filter) {
    HashSet<URI> set = new HashSet<URI>();
    Collection<AWorkspaceTreeNode> values = hashStringKeyIndex.values();
    for (AWorkspaceTreeNode node : values) {
        if (node instanceof AFolderNode || node instanceof FolderFileNode) {
            continue;
        }
        if (node instanceof DefaultFileNode) {
            File file = ((DefaultFileNode) node).getFile();
            if (file.getName().endsWith(filter)) {
                set.add(file.toURI());
            }
        } else if (node instanceof ALinkNode) {
            URI uri = ((ALinkNode) node).getLinkURI();
            if (uri.getPath().endsWith(filter)) {
                URI absUri = URIUtils.getAbsoluteURI(uri);
                if (absUri == null) {
                    continue;
                }
                set.add(absUri);
            }
        }
    }
    return Arrays.asList(set.toArray(new URI[] {}));
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) FolderFileNode(org.freeplane.plugin.workspace.nodes.FolderFileNode) AFolderNode(org.freeplane.plugin.workspace.nodes.AFolderNode) ALinkNode(org.freeplane.plugin.workspace.nodes.ALinkNode) URI(java.net.URI) File(java.io.File) DefaultFileNode(org.freeplane.plugin.workspace.nodes.DefaultFileNode) HashSet(java.util.HashSet)

Example 5 with DefaultFileNode

use of org.freeplane.plugin.workspace.nodes.DefaultFileNode in project freeplane by freeplane.

the class VirtualFolderDropHandler method processWorkspaceNodeDrop.

/**
 *********************************************************************************
 * CONSTRUCTORS
 *********************************************************************************
 */
/**
 *********************************************************************************
 * METHODS
 *********************************************************************************
 */
private void processWorkspaceNodeDrop(AWorkspaceTreeNode targetNode, List<AWorkspaceTreeNode> nodes, int dropAction) {
    try {
        for (AWorkspaceTreeNode node : nodes) {
            AWorkspaceTreeNode newNode = null;
            if (node instanceof DefaultFileNode) {
                newNode = createFSNodeLinks(targetNode, ((DefaultFileNode) node).getFile());
            } else {
                if (dropAction == DnDConstants.ACTION_COPY) {
                    newNode = node.clone();
                } else if (dropAction == DnDConstants.ACTION_MOVE) {
                    AWorkspaceTreeNode parent = node.getParent();
                    targetNode.getModel().cutNodeFromParent(node);
                    parent.refresh();
                    newNode = node;
                }
            }
            if (newNode == null) {
                continue;
            }
            targetNode.getModel().addNodeTo(newNode, targetNode);
        // WorkspaceController.getController().getExpansionStateHandler().addPathKey(this.getKey());
        }
    // WorkspaceUtils.saveCurrentConfiguration();
    } catch (Exception e) {
        LogUtils.warn(e);
    }
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) DefaultFileNode(org.freeplane.plugin.workspace.nodes.DefaultFileNode)

Aggregations

AWorkspaceTreeNode (org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)6 DefaultFileNode (org.freeplane.plugin.workspace.nodes.DefaultFileNode)6 File (java.io.File)3 LinkTypeFileNode (org.freeplane.plugin.workspace.nodes.LinkTypeFileNode)2 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NodeRenameDialogPanel (org.freeplane.plugin.workspace.components.dialog.NodeRenameDialogPanel)1 IFileSystemRepresentation (org.freeplane.plugin.workspace.io.IFileSystemRepresentation)1 ITask (org.freeplane.plugin.workspace.io.ITask)1 SkipTaskException (org.freeplane.plugin.workspace.io.SkipTaskException)1 IMutableLinkNode (org.freeplane.plugin.workspace.model.IMutableLinkNode)1 AFolderNode (org.freeplane.plugin.workspace.nodes.AFolderNode)1 ALinkNode (org.freeplane.plugin.workspace.nodes.ALinkNode)1 FolderFileNode (org.freeplane.plugin.workspace.nodes.FolderFileNode)1 FolderLinkNode (org.freeplane.plugin.workspace.nodes.FolderLinkNode)1