Search in sources :

Example 16 with AWorkspaceTreeNode

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

the class FolderLinkNode method getTransferable.

public WorkspaceTransferable getTransferable() {
    WorkspaceTransferable transferable = new WorkspaceTransferable();
    try {
        URI uri = URIUtils.getAbsoluteURI(getPath());
        transferable.addData(WorkspaceTransferable.WORKSPACE_URI_LIST_FLAVOR, uri.toString());
        List<File> fileList = new Vector<File>();
        fileList.add(new File(uri));
        transferable.addData(WorkspaceTransferable.WORKSPACE_FILE_LIST_FLAVOR, fileList);
        if (!this.isSystem()) {
            List<AWorkspaceTreeNode> objectList = new ArrayList<AWorkspaceTreeNode>();
            objectList.add(this);
            transferable.addData(WorkspaceTransferable.WORKSPACE_NODE_FLAVOR, objectList);
        }
        return transferable;
    } catch (Exception e) {
        LogUtils.warn(e);
    }
    return null;
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) ArrayList(java.util.ArrayList) WorkspaceTransferable(org.freeplane.plugin.workspace.dnd.WorkspaceTransferable) URI(java.net.URI) File(java.io.File) Vector(java.util.Vector)

Example 17 with AWorkspaceTreeNode

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

the class InputController method mouseClicked.

/**
 *********************************************************************************
 * REQUIRED METHODS FOR INTERFACES
 *********************************************************************************
 */
public void mouseClicked(MouseEvent e) {
    if (e.isConsumed()) {
        return;
    }
    TreePath path = ((JTree) e.getSource()).getClosestPathForLocation(e.getX(), e.getY());
    ((TreeView) WorkspaceController.getCurrentModeExtension().getView()).addSelectionPath(path);
    if (path != null) {
        AWorkspaceTreeNode node = (AWorkspaceTreeNode) path.getLastPathComponent();
        // encode buttons
        int eventType = 0;
        if (e.getButton() == MouseEvent.BUTTON1) {
            eventType += WorkspaceActionEvent.MOUSE_LEFT;
        }
        if (e.getButton() == MouseEvent.BUTTON3) {
            eventType += WorkspaceActionEvent.MOUSE_RIGHT;
        }
        if (e.getClickCount() % 2 == 0) {
            eventType += WorkspaceActionEvent.MOUSE_DBLCLICK;
        } else {
            eventType += WorkspaceActionEvent.MOUSE_CLICK;
        }
        if (e.isPopupTrigger()) {
            eventType += WorkspaceActionEvent.POPUP_TRIGGER;
        }
        WorkspaceActionEvent event = new WorkspaceActionEvent(node, eventType, e.getX(), e.getY(), e.getComponent());
        List<IWorkspaceNodeActionListener> nodeEventListeners = WorkspaceController.getCurrentModeExtension().getIOController().getNodeActionListeners(node.getClass(), eventType);
        if (nodeEventListeners != null) {
            for (IWorkspaceNodeActionListener listener : nodeEventListeners) {
                if (event.isConsumed()) {
                    break;
                }
                listener.handleAction(event);
            }
        }
        if (!event.isConsumed() && node instanceof IWorkspaceNodeActionListener) {
            ((IWorkspaceNodeActionListener) node).handleAction(event);
        }
    } else {
        if (e.getButton() == MouseEvent.BUTTON3) {
            // WorkspaceController.getController().getPopups().showWorkspacePopup(e.getComponent(), e.getX(), e.getY());
            ((AWorkspaceTreeNode) WorkspaceController.getCurrentModel().getRoot()).showPopup(e.getComponent(), e.getX(), e.getY());
        }
    }
}
Also used : JTree(javax.swing.JTree) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) TreePath(javax.swing.tree.TreePath) IWorkspaceNodeActionListener(org.freeplane.plugin.workspace.event.IWorkspaceNodeActionListener) WorkspaceActionEvent(org.freeplane.plugin.workspace.event.WorkspaceActionEvent) TreeView(org.freeplane.plugin.workspace.components.TreeView)

Example 18 with AWorkspaceTreeNode

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

the class VirtualFolderDropHandler method processUriListDrop.

private void processUriListDrop(AWorkspaceTreeNode targetNode, List<URI> uris, int dropAction) {
    try {
        for (URI uri : uris) {
            File srcFile = new File(uri);
            if (srcFile == null || !srcFile.exists()) {
                continue;
            }
            AWorkspaceTreeNode node = createFSNodeLinks(targetNode, srcFile);
            targetNode.getModel().addNodeTo(node, targetNode);
            node.refresh();
        }
        ;
    // WorkspaceUtils.saveCurrentConfiguration();
    } catch (Exception e) {
        LogUtils.warn(e);
    }
}
Also used : AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) URI(java.net.URI) File(java.io.File)

Example 19 with AWorkspaceTreeNode

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

the class VirtualFolderDropHandler 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.VirtualFolderDropHandler.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.VirtualFolderDropHandler.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)

Example 20 with AWorkspaceTreeNode

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

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