Search in sources :

Example 1 with AFolderNode

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

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

Aggregations

File (java.io.File)2 URI (java.net.URI)2 AWorkspaceTreeNode (org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)2 AFolderNode (org.freeplane.plugin.workspace.nodes.AFolderNode)2 HashSet (java.util.HashSet)1 JFileChooser (javax.swing.JFileChooser)1 AWorkspaceProject (org.freeplane.plugin.workspace.model.project.AWorkspaceProject)1 ALinkNode (org.freeplane.plugin.workspace.nodes.ALinkNode)1 DefaultFileNode (org.freeplane.plugin.workspace.nodes.DefaultFileNode)1 FolderFileNode (org.freeplane.plugin.workspace.nodes.FolderFileNode)1 LinkTypeFileNode (org.freeplane.plugin.workspace.nodes.LinkTypeFileNode)1