Search in sources :

Example 6 with AWorkspaceProject

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

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

the class MModeWorkspaceController method setupView.

private void setupView(ModeController modeController) {
    FileSystemManager.setDirectoryConflictHandler(new DirectoryMergeConflictDialog());
    FileSystemManager.setFileConflictHandler(new FileExistsConflictDialog());
    boolean expanded = true;
    try {
        expanded = !Boolean.parseBoolean(settings.getProperty(WORKSPACE_VIEW_COLLAPSED, "false"));
    } catch (Exception e) {
    // ignore -> default is true
    }
    OneTouchCollapseResizer otcr = new OneTouchCollapseResizer(Direction.LEFT);
    otcr.addCollapseListener(getWorkspaceView());
    ResizerEventAdapter adapter = new ResizerEventAdapter() {

        public void componentResized(ResizeEvent event) {
            if (event.getSource().equals(getView())) {
                settings.setProperty(WORKSPACE_VIEW_WIDTH, String.valueOf(((JComponent) event.getSource()).getPreferredSize().width));
            }
        }

        public void componentCollapsed(ResizeEvent event) {
            if (event.getSource().equals(getView())) {
                settings.setProperty(WORKSPACE_VIEW_COLLAPSED, "true");
            }
        }

        public void componentExpanded(ResizeEvent event) {
            if (event.getSource().equals(getView())) {
                settings.setProperty(WORKSPACE_VIEW_COLLAPSED, "false");
            }
        }
    };
    otcr.addResizerListener(adapter);
    otcr.addCollapseListener(adapter);
    Box resizableTools = Box.createHorizontalBox();
    try {
        int width = Integer.parseInt(settings.getProperty(WORKSPACE_VIEW_WIDTH, "250"));
        getWorkspaceView().setPreferredSize(new Dimension(width, 40));
    } catch (Exception e) {
    // blindly accept
    }
    resizableTools.add(getWorkspaceView());
    resizableTools.add(otcr);
    otcr.setExpanded(expanded);
    modeController.getUserInputListenerFactory().addToolBar("workspace", ViewController.LEFT, resizableTools);
    getWorkspaceView().setModel(getModel());
    getView().expandPath(getModel().getRoot().getTreePath());
    for (AWorkspaceProject project : getModel().getProjects()) {
        getView().expandPath(project.getModel().getRoot().getTreePath());
    }
    getView().getNodeTypeIconManager().addNodeTypeIconHandler(LinkTypeFileNode.class, new LinkTypeFileIconHandler());
    getView().getNodeTypeIconManager().addNodeTypeIconHandler(DefaultFileNode.class, new DefaultFileNodeIconHandler());
    getView().refreshView();
}
Also used : AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) FileExistsConflictDialog(org.freeplane.plugin.workspace.handler.FileExistsConflictDialog) Box(javax.swing.Box) Dimension(java.awt.Dimension) LinkTypeFileIconHandler(org.freeplane.plugin.workspace.handler.LinkTypeFileIconHandler) IOException(java.io.IOException) ResizeEvent(org.freeplane.core.ui.components.ResizeEvent) DirectoryMergeConflictDialog(org.freeplane.plugin.workspace.handler.DirectoryMergeConflictDialog) DefaultFileNodeIconHandler(org.freeplane.plugin.workspace.handler.DefaultFileNodeIconHandler) OneTouchCollapseResizer(org.freeplane.core.ui.components.OneTouchCollapseResizer)

Example 8 with AWorkspaceProject

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

the class WorkspaceNewProjectAction method actionPerformed.

public void actionPerformed(ActionEvent event) {
    final NewProjectDialogPanel dialog = new NewProjectDialogPanel();
    dialog.setConfirmButton(new Component() {

        private static final long serialVersionUID = 1L;

        private Component confirmButton;

        @Override
        public void setEnabled(boolean b) {
            if (confirmButton == null) {
                findButton(dialog);
            }
            if (confirmButton != null) {
                confirmButton.setEnabled(b);
            }
        }

        private void findButton(Component dialog) {
            Component parent = dialog.getParent();
            while (parent != null) {
                if (parent instanceof JOptionPane) {
                    // WORKSPACE - test: os other than windows7
                    for (Component comp : ((JOptionPane) parent).getComponents()) {
                        if (comp instanceof JPanel && ((JPanel) comp).getComponentCount() > 0 && ((JPanel) comp).getComponent(0) instanceof JButton) {
                            confirmButton = ((JPanel) comp).getComponent(0);
                        }
                    }
                }
                parent = parent.getParent();
            }
        }
    });
    int response = JOptionPane.showConfirmDialog(UITools.getFrame(), dialog, TextUtils.getText("workspace.action.node.new.project.dialog.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (response == JOptionPane.OK_OPTION) {
        File path = URIUtils.getFile(dialog.getProjectPath());
        // WORKSPACE - todo: ask for permission to create the directory or check for always_create setting
        if (!path.exists()) {
            if (path.mkdirs()) {
                LogUtils.info("new project directory created");
            } else {
                LogUtils.info("Error: could not create new project directory");
            }
        }
        AWorkspaceProject project = AWorkspaceProject.create(null, path.toURI());
        WorkspaceController.getCurrentModel().addProject(project);
        try {
            LOAD_RETURN_TYPE return_type = WorkspaceController.getCurrentModeExtension().getProjectLoader().loadProject(project);
            if (return_type == LOAD_RETURN_TYPE.NEW_PROJECT && dialog.getProjectName() != null && dialog.getProjectName().length() > 0) {
                project.getModel().changeNodeName(project.getModel().getRoot(), dialog.getProjectName());
            }
        } catch (IOException e) {
            LogUtils.severe(e);
        } catch (WorkspaceModelException e) {
            LogUtils.severe(e);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) JButton(javax.swing.JButton) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) WorkspaceModelException(org.freeplane.plugin.workspace.model.WorkspaceModelException) NewProjectDialogPanel(org.freeplane.plugin.workspace.components.dialog.NewProjectDialogPanel) Component(java.awt.Component) File(java.io.File) LOAD_RETURN_TYPE(org.freeplane.plugin.workspace.io.IProjectSettingsIOHandler.LOAD_RETURN_TYPE)

Example 9 with AWorkspaceProject

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

the class NodeNewFolderAction 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);
    int mode = WorkspaceNewFolderPanel.MODE_VIRTUAL_PHYSICAL;
    if (targetNode instanceof IFileSystemRepresentation) {
        mode = WorkspaceNewFolderPanel.MODE_VIRTUAL_ONLY;
    }
    WorkspaceNewFolderPanel dialog = new WorkspaceNewFolderPanel(mode, targetNode);
    int response = JOptionPane.showConfirmDialog(UITools.getFrame(), dialog, TextUtils.getText("workspace.action.node.new.folder.dialog.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (response == JOptionPane.OK_OPTION) {
        String value = dialog.getFolderName();
        if (value == null || value.trim().length() <= 0) {
            // WORKSPACE - ToDo: prepare message, or call this method (with error message) again?
            return;
        }
        if (dialog.isLinkedFolder()) {
            File path = new File(dialog.getLinkPath());
            if (path != null) {
                FolderLinkNode node = new FolderLinkNode();
                node.setName(value);
                URI uri = project.getRelativeURI(path.toURI());
                if (uri == null) {
                    node.setPath(path.toURI());
                } else {
                    node.setPath(uri);
                }
                targetNode.getModel().addNodeTo(node, targetNode);
                node.refresh();
            }
        } else {
            if (targetNode instanceof IFileSystemRepresentation) {
                try {
                    WorkspaceController.getFileSystemMgr().createDirectory(value, ((IFileSystemRepresentation) targetNode).getFile());
                } catch (IOException e1) {
                    JOptionPane.showMessageDialog(UITools.getFrame(), e1.getMessage());
                }
            } else {
                FolderVirtualNode node = new FolderVirtualNode();
                node.setName(value);
                targetNode.getModel().addNodeTo(node, targetNode);
            }
        }
        targetNode.refresh();
        targetNode.getModel().requestSave();
    }
}
Also used : AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) IFileSystemRepresentation(org.freeplane.plugin.workspace.io.IFileSystemRepresentation) FolderVirtualNode(org.freeplane.plugin.workspace.nodes.FolderVirtualNode) AWorkspaceTreeNode(org.freeplane.plugin.workspace.model.AWorkspaceTreeNode) WorkspaceNewFolderPanel(org.freeplane.plugin.workspace.components.dialog.WorkspaceNewFolderPanel) IOException(java.io.IOException) File(java.io.File) URI(java.net.URI) FolderLinkNode(org.freeplane.plugin.workspace.nodes.FolderLinkNode)

Example 10 with AWorkspaceProject

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

the class WorkspaceImportProjectAction method actionPerformed.

public void actionPerformed(ActionEvent event) {
    final ImportProjectDialogPanel dialog = new ImportProjectDialogPanel();
    dialog.setConfirmButton(new Component() {

        private static final long serialVersionUID = 1L;

        private Component confirmButton;

        @Override
        public void setEnabled(boolean b) {
            if (confirmButton == null) {
                findButton(dialog);
            }
            if (confirmButton != null) {
                confirmButton.setEnabled(b);
            }
        }

        private void findButton(Component dialog) {
            Component parent = dialog.getParent();
            while (parent != null) {
                if (parent instanceof JOptionPane) {
                    // WORKSPACE - test: os other than windows7
                    for (Component comp : ((JOptionPane) parent).getComponents()) {
                        if (comp instanceof JPanel && ((JPanel) comp).getComponentCount() > 0 && ((JPanel) comp).getComponent(0) instanceof JButton) {
                            confirmButton = ((JPanel) comp).getComponent(0);
                        }
                    }
                }
                parent = parent.getParent();
            }
        }
    });
    int response = JOptionPane.showConfirmDialog(UITools.getFrame(), dialog, TextUtils.getText("workspace.action.node.import.project.dialog.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (response == JOptionPane.OK_OPTION) {
        AWorkspaceProject project = dialog.getProject();
        if (project == null) {
            return;
        }
        WorkspaceController.getCurrentModel().addProject(project);
        try {
            LOAD_RETURN_TYPE return_type = WorkspaceController.getCurrentModeExtension().getProjectLoader().loadProject(project);
            if (return_type == LOAD_RETURN_TYPE.NEW_PROJECT && dialog.getProjectName() != null && dialog.getProjectName().length() > 0) {
                project.getModel().changeNodeName(project.getModel().getRoot(), dialog.getProjectName());
            }
        } catch (IOException e) {
            LogUtils.severe(e);
        } catch (WorkspaceModelException e) {
            LogUtils.severe(e);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) JButton(javax.swing.JButton) ImportProjectDialogPanel(org.freeplane.plugin.workspace.components.dialog.ImportProjectDialogPanel) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) WorkspaceModelException(org.freeplane.plugin.workspace.model.WorkspaceModelException) Component(java.awt.Component) LOAD_RETURN_TYPE(org.freeplane.plugin.workspace.io.IProjectSettingsIOHandler.LOAD_RETURN_TYPE)

Aggregations

AWorkspaceProject (org.freeplane.plugin.workspace.model.project.AWorkspaceProject)15 IOException (java.io.IOException)6 File (java.io.File)5 AWorkspaceTreeNode (org.freeplane.plugin.workspace.model.AWorkspaceTreeNode)3 Component (java.awt.Component)2 URI (java.net.URI)2 JButton (javax.swing.JButton)2 JOptionPane (javax.swing.JOptionPane)2 JPanel (javax.swing.JPanel)2 LOAD_RETURN_TYPE (org.freeplane.plugin.workspace.io.IProjectSettingsIOHandler.LOAD_RETURN_TYPE)2 WorkspaceModelException (org.freeplane.plugin.workspace.model.WorkspaceModelException)2 FolderLinkNode (org.freeplane.plugin.workspace.nodes.FolderLinkNode)2 LinkTypeFileNode (org.freeplane.plugin.workspace.nodes.LinkTypeFileNode)2 Dimension (java.awt.Dimension)1 FileFilter (java.io.FileFilter)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1