Search in sources :

Example 1 with WorkspaceModelException

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

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

Component (java.awt.Component)2 IOException (java.io.IOException)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 AWorkspaceProject (org.freeplane.plugin.workspace.model.project.AWorkspaceProject)2 File (java.io.File)1 ImportProjectDialogPanel (org.freeplane.plugin.workspace.components.dialog.ImportProjectDialogPanel)1 NewProjectDialogPanel (org.freeplane.plugin.workspace.components.dialog.NewProjectDialogPanel)1