Search in sources :

Example 1 with AWorkspaceProject

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

the class ImportProjectDialogPanel method readVersions.

private void readVersions(File home) {
    for (File folder : home.listFiles(new FileFilter() {

        public boolean accept(File pathname) {
            if (pathname.isDirectory()) {
                return true;
            }
            return false;
        }
    })) {
        File settings = new File(folder, "settings.xml");
        if (settings.exists()) {
            AWorkspaceProject project = AWorkspaceProject.create(folder.getName(), home.getParentFile().toURI());
            String item = new TempProjectLoader().getMetaInfo(project);
            if (item == null) {
                continue;
            }
            getComboBoxModel().addItem(new VersionItem(project, item, new Date(settings.lastModified())));
        }
    }
}
Also used : AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) FileFilter(java.io.FileFilter) File(java.io.File) Date(java.util.Date)

Example 2 with AWorkspaceProject

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

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

the class ProjectURLHandler method openConnection.

public URLConnection openConnection(URL url) throws IOException {
    // WORKSPACE - todo: extend with meaningful exception messages
    AWorkspaceProject project = WorkspaceController.getCurrentModel().getProject(url.getAuthority());
    URL absolutePath = resolve(project, url);
    return absolutePath.openConnection();
}
Also used : AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) URL(java.net.URL)

Example 4 with AWorkspaceProject

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

the class MModeWorkspaceController method saveSettings.

private void saveSettings(String settingsPath) {
    final File userPropertiesFolder = new File(settingsPath);
    final File settingsFile = new File(userPropertiesFolder, USER_SETTINGS_FILENAME);
    // clear old settings
    String[] projectsIds = settings.getProperty(WORKSPACE_MODEL_PROJECTS, "").split(WORKSPACE_MODEL_PROJECTS_SEPARATOR);
    for (String projectID : projectsIds) {
        settings.remove(projectID);
    }
    // build new project stack
    List<String> projectIDs = new ArrayList<String>();
    synchronized (getModel().getProjects()) {
        for (AWorkspaceProject project : getModel().getProjects()) {
            saveProject(project);
            if (projectIDs.contains(project.getProjectID())) {
                continue;
            }
            projectIDs.add(project.getProjectID());
            settings.setProperty(project.getProjectID(), project.getProjectHome().toString());
        }
    }
    StringBuilder sb = new StringBuilder();
    for (String prjId : projectIDs) {
        if (sb.length() > 0) {
            sb.append(WORKSPACE_MODEL_PROJECTS_SEPARATOR);
        }
        sb.append(prjId);
    }
    settings.setProperty(WORKSPACE_MODEL_PROJECTS, sb.toString());
    OutputStream os = null;
    try {
        if (!settingsFile.exists()) {
            settingsFile.getParentFile().mkdirs();
            settingsFile.createNewFile();
        }
        os = new FileOutputStream(settingsFile);
        settings.store(os, "user settings for the workspace");
    } catch (final Exception ex) {
        LogUtils.severe("could not store workspace settings.", ex);
    } finally {
        FileUtils.silentlyClose(os);
    }
}
Also used : AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException)

Example 5 with AWorkspaceProject

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

the class MModeWorkspaceController method setupModel.

private void setupModel(ModeController modeController) {
    String[] projectsIds = settings.getProperty(WORKSPACE_MODEL_PROJECTS, "").split(WORKSPACE_MODEL_PROJECTS_SEPARATOR);
    for (String projectID : projectsIds) {
        String projectHome = settings.getProperty(projectID);
        if (projectHome == null) {
            continue;
        }
        AWorkspaceProject project = null;
        try {
            project = AWorkspaceProject.create(projectID, URIUtils.createURI(projectHome));
            getModel().addProject(project);
            getProjectLoader().loadProject(project);
        } catch (Exception e) {
            LogUtils.severe(e);
            if (project != null) {
                getModel().removeProject(project);
            }
        }
    }
}
Also used : AWorkspaceProject(org.freeplane.plugin.workspace.model.project.AWorkspaceProject) IOException(java.io.IOException)

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