Search in sources :

Example 1 with AWorkspaceTreeNode

use of org.freeplane.plugin.workspace.model.AWorkspaceTreeNode in project freeplane by freeplane.

the class AWorkspaceAction method getSelectedNodes.

protected AWorkspaceTreeNode[] getSelectedNodes(ActionEvent e) {
    JTree tree = null;
    if (e.getSource() instanceof JTree) {
        tree = (JTree) e.getSource();
    } else {
        WorkspacePopupMenu pop = getRootPopupMenu((Component) e.getSource());
        if (pop == null) {
            return null;
        }
        tree = (JTree) pop.getInvoker();
    }
    AWorkspaceTreeNode[] nodes = new AWorkspaceTreeNode[tree.getSelectionPaths().length];
    int i = 0;
    for (TreePath path : tree.getSelectionPaths()) {
        nodes[i++] = (AWorkspaceTreeNode) path.getLastPathComponent();
    }
    return nodes;
}
Also used : JTree(javax.swing.JTree) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) TreePath(javax.swing.tree.TreePath) WorkspacePopupMenu(org.freeplane.plugin.workspace.components.menu.WorkspacePopupMenu)

Example 2 with AWorkspaceTreeNode

use of org.freeplane.plugin.workspace.model.AWorkspaceTreeNode in project freeplane by freeplane.

the class AWorkspaceAction method getNodeFromActionEvent.

protected AWorkspaceTreeNode getNodeFromActionEvent(ActionEvent e) {
    JTree tree = null;
    TreePath path = null;
    if (e.getSource() instanceof JTree) {
        tree = (JTree) e.getSource();
        path = tree.getSelectionPath();
    } else {
        WorkspacePopupMenu pop = getRootPopupMenu((Component) e.getSource());
        if (pop == null) {
            return null;
        }
        tree = (JTree) pop.getInvoker();
        int x = pop.getInvokerLocation().x;
        int y = pop.getInvokerLocation().y;
        path = tree.getClosestPathForLocation(x, y);
    }
    if (path == null) {
        return null;
    }
    return (AWorkspaceTreeNode) path.getLastPathComponent();
}
Also used : JTree(javax.swing.JTree) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) TreePath(javax.swing.tree.TreePath) WorkspacePopupMenu(org.freeplane.plugin.workspace.components.menu.WorkspacePopupMenu)

Example 3 with AWorkspaceTreeNode

use of org.freeplane.plugin.workspace.model.AWorkspaceTreeNode in project freeplane by freeplane.

the class FileNodeNewMindmapAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    Controller.getCurrentController().selectMode(MModeController.MODENAME);
    AWorkspaceTreeNode targetNode = this.getNodeFromActionEvent(e);
    if (targetNode instanceof IFileSystemRepresentation) {
        String fileName = JOptionPane.showInputDialog(Controller.getCurrentController().getViewController().getContentPane(), TextUtils.getText("add_new_mindmap"), TextUtils.getText("add_new_mindmap_title"), JOptionPane.OK_CANCEL_OPTION);
        if (fileName != null && fileName.length() > 0) {
            if (!fileName.endsWith(".mm")) {
                fileName += ".mm";
            }
            File file = new File(((IFileSystemRepresentation) targetNode).getFile(), fileName);
            try {
                file = WorkspaceController.getFileSystemMgr().createFile(fileName, ((IFileSystemRepresentation) targetNode).getFile());
                if (createNewMindmap(file)) {
                    targetNode.refresh();
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(UITools.getFrame(), ex.getMessage(), "Error ... ", JOptionPane.ERROR_MESSAGE);
                ex.printStackTrace();
            }
        }
    }
}
Also used : IFileSystemRepresentation(org.freeplane.plugin.workspace.io.IFileSystemRepresentation) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) File(java.io.File) XMLParseException(org.freeplane.n3.nanoxml.XMLParseException) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with AWorkspaceTreeNode

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

use of org.freeplane.plugin.workspace.model.AWorkspaceTreeNode in project freeplane by freeplane.

the class NodePasteAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    AWorkspaceTreeNode targetNode = getNodeFromActionEvent(e);
    if (DnDController.isDropAllowed(targetNode)) {
        Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable transf = clip.getContents(null);
        if (transf == null) {
            return;
        }
        int dndAction = DnDConstants.ACTION_COPY;
        if (transf.isDataFlavorSupported(WorkspaceTransferable.WORKSPACE_MOVE_NODE_FLAVOR)) {
            dndAction = DnDConstants.ACTION_MOVE;
        }
        if (WorkspaceController.getCurrentModeExtension().getView() != null) {
            try {
                WorkspaceController.getCurrentModeExtension().getView().getTransferHandler().handleDrop(targetNode, transf, dndAction);
                if (dndAction == DnDConstants.ACTION_MOVE) {
                    clip.setContents(null, null);
                }
            } catch (NoDropHandlerFoundExeption ex) {
                LogUtils.info("Exception in org.freeplane.plugin.workspace.actions.NodePasteAction.actionPerformed(ActionEvent): " + ex.getMessage());
            }
        }
    }
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) NoDropHandlerFoundExeption(org.freeplane.plugin.workspace.dnd.NoDropHandlerFoundExeption) Transferable(java.awt.datatransfer.Transferable) WorkspaceTransferable(org.freeplane.plugin.workspace.dnd.WorkspaceTransferable) Clipboard(java.awt.datatransfer.Clipboard)

Aggregations

AWorkspaceTreeNode (org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)51 File (java.io.File)13 URI (java.net.URI)9 ArrayList (java.util.ArrayList)8 WorkspaceTransferable (org.freeplane.plugin.workspace.dnd.WorkspaceTransferable)7 TreePath (javax.swing.tree.TreePath)6 DefaultFileNode (org.freeplane.plugin.workspace.nodes.DefaultFileNode)6 JTree (javax.swing.JTree)5 IOException (java.io.IOException)4 IWorkspaceView (org.freeplane.plugin.workspace.components.IWorkspaceView)4 IFileSystemRepresentation (org.freeplane.plugin.workspace.io.IFileSystemRepresentation)4 LinkTypeFileNode (org.freeplane.plugin.workspace.nodes.LinkTypeFileNode)4 Vector (java.util.Vector)3 IWorkspaceNodeActionListener (org.freeplane.plugin.workspace.event.IWorkspaceNodeActionListener)3 WorkspaceActionEvent (org.freeplane.plugin.workspace.event.WorkspaceActionEvent)3 SkipTaskException (org.freeplane.plugin.workspace.io.SkipTaskException)3 AWorkspaceProject (org.freeplane.plugin.workspace.model.project.AWorkspaceProject)3 FolderLinkNode (org.freeplane.plugin.workspace.nodes.FolderLinkNode)3 List (java.util.List)2 WorkspacePopupMenu (org.freeplane.plugin.workspace.components.menu.WorkspacePopupMenu)2