Search in sources :

Example 1 with LinkTypeFileNode

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

the class NodeNewLinkAction method actionPerformed.

/**
 *********************************************************************************
 * METHODS
 *********************************************************************************
 */
/**
 *********************************************************************************
 * REQUIRED METHODS FOR INTERFACES
 *********************************************************************************
 */
public void actionPerformed(ActionEvent e) {
    AWorkspaceTreeNode targetNode = null;
    if (e == null || getRootPopupMenu((Component) e.getSource()) == null) {
        targetNode = WorkspaceController.getCurrentProject().getModel().getRoot();
    } else {
        targetNode = getNodeFromActionEvent(e);
    }
    if (targetNode == null) {
        return;
    }
    AWorkspaceProject project = WorkspaceController.getProject(targetNode);
    if (targetNode instanceof AFolderNode) {
        JFileChooser chooser = new JFileChooser(URIUtils.getAbsoluteFile(((AFolderNode) targetNode).getPath() == null ? WorkspaceController.getCurrentProject().getProjectHome() : ((AFolderNode) targetNode).getPath()));
        chooser.setMultiSelectionEnabled(false);
        int response = chooser.showOpenDialog(UITools.getFrame());
        if (response == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            if (file != null) {
                LinkTypeFileNode node = new LinkTypeFileNode();
                node.setName(file.getName());
                URI path = chooser.getSelectedFile().toURI();
                if (path == null) {
                    return;
                }
                URI uri = project.getRelativeURI(path);
                if (uri == null) {
                    node.setLinkURI(path);
                } else {
                    node.setLinkURI(uri);
                }
                targetNode.getModel().addNodeTo(node, targetNode);
                targetNode.refresh();
                targetNode.getModel().requestSave();
            }
        }
    }
}
Also used : AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) LinkTypeFileNode(org.freeplane.plugin.workspace.nodes.LinkTypeFileNode) AFolderNode(org.freeplane.plugin.workspace.nodes.AFolderNode) JFileChooser(javax.swing.JFileChooser) File(java.io.File) URI(java.net.URI)

Example 2 with LinkTypeFileNode

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

the class VirtualFolderDropHandler method createFSNodeLinks.

/**
 * @param file
 * @return
 */
private AWorkspaceTreeNode createFSNodeLinks(AWorkspaceTreeNode targetNode, File file) {
    AWorkspaceTreeNode node = null;
    AWorkspaceProject project = WorkspaceController.getProject(targetNode);
    if (file.isDirectory()) {
        FolderLinkNode pNode = new FolderLinkNode();
        pNode.setPath(project.getRelativeURI(file.toURI()));
        node = pNode;
    } else {
        LinkTypeFileNode lNode = new LinkTypeFileNode();
        lNode.setLinkURI(project.getRelativeURI(file.toURI()));
        node = lNode;
    }
    node.setName(file.getName());
    return node;
}
Also used : AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) LinkTypeFileNode(org.freeplane.plugin.workspace.nodes.LinkTypeFileNode) FolderLinkNode(org.freeplane.plugin.workspace.nodes.FolderLinkNode)

Example 3 with LinkTypeFileNode

use of org.freeplane.plugin.workspace.nodes.LinkTypeFileNode 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 4 with LinkTypeFileNode

use of org.freeplane.plugin.workspace.nodes.LinkTypeFileNode 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 5 with LinkTypeFileNode

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

the class LinkTypeFileCreator method getNode.

@Override
public AWorkspaceTreeNode getNode(XMLElement data) {
    String type = data.getAttribute("type", "file");
    LinkTypeFileNode node = new LinkTypeFileNode(type);
    String path = data.getAttribute("path", null);
    if (path == null || path.length() == 0) {
        return null;
    }
    node.setLinkURI(URIUtils.createURI(path));
    String name = data.getAttribute("name", URIUtils.getAbsoluteFile(node.getLinkURI()).getName());
    node.setName(name);
    return node;
}
Also used : LinkTypeFileNode(org.freeplane.plugin.workspace.nodes.LinkTypeFileNode)

Aggregations

LinkTypeFileNode (org.freeplane.plugin.workspace.nodes.LinkTypeFileNode)5 AWorkspaceTreeNode (org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)4 File (java.io.File)3 AWorkspaceProject (org.freeplane.plugin.workspace.model.project.AWorkspaceProject)2 DefaultFileNode (org.freeplane.plugin.workspace.nodes.DefaultFileNode)2 FolderLinkNode (org.freeplane.plugin.workspace.nodes.FolderLinkNode)2 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 JFileChooser (javax.swing.JFileChooser)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 AFolderNode (org.freeplane.plugin.workspace.nodes.AFolderNode)1