Search in sources :

Example 26 with AWorkspaceTreeNode

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

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

the class ProjectNodeWriter method writeContent.

public void writeContent(ITreeWriter writer, Object element, String tag) throws IOException {
    final AWorkspaceTreeNode node = (AWorkspaceTreeNode) element;
    for (int i = 0; i < node.getChildCount(); i++) {
        AWorkspaceTreeNode child = node.getChildAt(i);
        if (child == null || child.getTagName() == null) {
            continue;
        }
        writer.addElement(child, child.getTagName());
    }
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)

Example 28 with AWorkspaceTreeNode

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

the class FileFolderDropHandler method processDrop.

/**
 *********************************************************************************
 * REQUIRED METHODS FOR INTERFACES
 *********************************************************************************
 */
@SuppressWarnings("unchecked")
public boolean processDrop(AWorkspaceTreeNode targetNode, Transferable transferable, int dropAction) {
    try {
        if (transferable.isDataFlavorSupported(WorkspaceTransferable.WORKSPACE_NODE_FLAVOR)) {
            processWorkspaceNodeDrop(targetNode, (List<AWorkspaceTreeNode>) transferable.getTransferData(WorkspaceTransferable.WORKSPACE_NODE_FLAVOR), dropAction);
        } else if (transferable.isDataFlavorSupported(WorkspaceTransferable.WORKSPACE_FILE_LIST_FLAVOR)) {
            processFileListDrop(targetNode, (List<File>) transferable.getTransferData(WorkspaceTransferable.WORKSPACE_FILE_LIST_FLAVOR), dropAction);
        } else if (transferable.isDataFlavorSupported(WorkspaceTransferable.WORKSPACE_URI_LIST_FLAVOR)) {
            ArrayList<URI> uriList = new ArrayList<URI>();
            String uriString = (String) transferable.getTransferData(WorkspaceTransferable.WORKSPACE_URI_LIST_FLAVOR);
            if (!uriString.startsWith("file://")) {
                return false;
            }
            String[] uriArray = uriString.split("\r\n");
            for (String singleUri : uriArray) {
                try {
                    uriList.add(URIUtils.createURI(singleUri));
                } catch (Exception e) {
                    LogUtils.info("org.freeplane.plugin.workspace.mindmapmode.FolderFileDropHandler.processDrop(targetNode, transferable, dropAction)@1" + e.getMessage());
                }
            }
            processUriListDrop(targetNode, uriList, dropAction);
        }
        targetNode.refresh();
        IWorkspaceView view = WorkspaceController.getCurrentModeExtension().getView();
        if (view != null) {
            view.expandPath(targetNode.getTreePath());
            WorkspaceController.getCurrentModeExtension().getView().refreshView();
        }
    } catch (Exception e) {
        LogUtils.warn("org.freeplane.plugin.workspace.mindmapmode.FolderFileDropHandler.processDrop(targetNode, transferable, dropAction)@2", e);
    }
    return true;
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IWorkspaceView(org.freeplane.plugin.workspace.components.IWorkspaceView) URI(java.net.URI) IOException(java.io.IOException) SkipTaskException(org.freeplane.plugin.workspace.io.SkipTaskException)

Example 29 with AWorkspaceTreeNode

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

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

the class ProjectModel method removeIndexOnlyRecursively.

/**
 * @param node
 */
private void removeIndexOnlyRecursively(AWorkspaceTreeNode node) {
    this.hashStringKeyIndex.remove(node.getKey());
    if (node.getChildCount() > 0) {
        for (int i = 0; i < node.getChildCount(); i++) {
            AWorkspaceTreeNode childNode = node.getChildAt(i);
            removeIndexOnlyRecursively(childNode);
        }
    }
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)

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