Search in sources :

Example 1 with Project

use of org.gephi.project.api.Project in project gephi by gephi.

the class ProjectControllerImpl method deleteWorkspace.

@Override
public void deleteWorkspace(Workspace workspace) {
    Project project = workspace.getProject();
    WorkspaceProviderImpl workspaceProvider = project.getLookup().lookup(WorkspaceProviderImpl.class);
    Workspace toSelectWorkspace = null;
    if (getCurrentWorkspace() == workspace) {
        toSelectWorkspace = workspaceProvider.getPrecedingWorkspace(workspace);
    }
    workspaceProvider.removeWorkspace(workspace);
    //Event
    fireWorkspaceEvent(EventType.CLOSE, workspace);
    if (getCurrentWorkspace() == workspace) {
        //Select the one before, or after
        if (toSelectWorkspace == null) {
            closeCurrentProject();
        } else {
            openWorkspace(toSelectWorkspace);
        }
    }
}
Also used : Project(org.gephi.project.api.Project) Workspace(org.gephi.project.api.Workspace)

Example 2 with Project

use of org.gephi.project.api.Project in project gephi by gephi.

the class ProjectControllerUIImpl method saveAsProject.

@Override
public void saveAsProject() {
    final String LAST_PATH = "SaveAsProject_Last_Path";
    final String LAST_PATH_DEFAULT = "SaveAsProject_Last_Path_Default";
    DialogFileFilter filter = new DialogFileFilter(NbBundle.getMessage(ProjectControllerUIImpl.class, "SaveAsProject_filechooser_filter"));
    filter.addExtension(".gephi");
    //Get last directory
    String lastPathDefault = NbPreferences.forModule(ProjectControllerUIImpl.class).get(LAST_PATH_DEFAULT, null);
    String lastPath = NbPreferences.forModule(ProjectControllerUIImpl.class).get(LAST_PATH, lastPathDefault);
    //File chooser
    final JFileChooser chooser = new JFileChooser(lastPath);
    chooser.addChoosableFileFilter(filter);
    int returnFile = chooser.showSaveDialog(null);
    if (returnFile == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        //Save last path
        NbPreferences.forModule(ProjectControllerUIImpl.class).put(LAST_PATH, file.getAbsolutePath());
        //File management
        try {
            if (!file.getPath().endsWith(".gephi")) {
                file = new File(file.getPath() + ".gephi");
            }
            if (!file.exists()) {
                if (!file.createNewFile()) {
                    String failMsg = NbBundle.getMessage(ProjectControllerUIImpl.class, "SaveAsProject_SaveFailed", new Object[] { file.getPath() });
                    JOptionPane.showMessageDialog(null, failMsg);
                    return;
                }
            } else {
                String overwriteMsg = NbBundle.getMessage(ProjectControllerUIImpl.class, "SaveAsProject_Overwrite", new Object[] { file.getPath() });
                if (JOptionPane.showConfirmDialog(null, overwriteMsg) != JOptionPane.OK_OPTION) {
                    return;
                }
            }
            file = FileUtil.normalizeFile(file);
            final String SaveAsFileName = file.getName();
            //File exist now, Save project
            Project project = controller.getCurrentProject();
            saveProject(project, file);
            //Modifying Title bar
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
                    String title = frame.getTitle();
                    title = title.substring(0, title.indexOf(" - ")) + " - " + SaveAsFileName;
                    frame.setTitle(title);
                }
            });
        } catch (Exception e) {
            Logger.getLogger("").log(Level.WARNING, "", e);
        }
    }
}
Also used : Project(org.gephi.project.api.Project) JFileChooser(javax.swing.JFileChooser) JFrame(javax.swing.JFrame) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) File(java.io.File)

Example 3 with Project

use of org.gephi.project.api.Project in project gephi by gephi.

the class ProjectControllerUIImpl method newProject.

@Override
public Project newProject() {
    if (closeCurrentProject()) {
        controller.newProject();
        final Project project = controller.getCurrentProject();
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
                String title = frame.getTitle() + " - " + project.getLookup().lookup(ProjectInformation.class).getName();
                frame.setTitle(title);
            }
        });
        unlockProjectActions();
        return project;
    }
    return null;
}
Also used : Project(org.gephi.project.api.Project) JFrame(javax.swing.JFrame) ProjectInformation(org.gephi.project.api.ProjectInformation)

Example 4 with Project

use of org.gephi.project.api.Project in project gephi by gephi.

the class ProjectControllerUIImpl method projectProperties.

@Override
public void projectProperties() {
    Project project = controller.getCurrentProject();
    ProjectPropertiesUI ui = Lookup.getDefault().lookup(ProjectPropertiesUI.class);
    if (ui != null) {
        JPanel panel = ui.getPanel();
        ui.setup(project);
        DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(ProjectControllerUIImpl.class, "ProjectProperties_dialog_title"));
        Object result = DialogDisplayer.getDefault().notify(dd);
        if (result == NotifyDescriptor.OK_OPTION) {
            ui.unsetup(project);
        }
    }
}
Also used : Project(org.gephi.project.api.Project) ProjectPropertiesUI(org.gephi.project.spi.ProjectPropertiesUI) JPanel(javax.swing.JPanel) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject)

Example 5 with Project

use of org.gephi.project.api.Project in project gephi by gephi.

the class ProjectControllerUIImpl method saveProject.

@Override
public void saveProject() {
    Project project = controller.getCurrentProject();
    if (project.getLookup().lookup(ProjectInformation.class).hasFile()) {
        File file = project.getLookup().lookup(ProjectInformation.class).getFile();
        saveProject(project, file);
    } else {
        saveAsProject();
    }
}
Also used : Project(org.gephi.project.api.Project) ProjectInformation(org.gephi.project.api.ProjectInformation) File(java.io.File)

Aggregations

Project (org.gephi.project.api.Project)5 File (java.io.File)2 JFrame (javax.swing.JFrame)2 ProjectInformation (org.gephi.project.api.ProjectInformation)2 JFileChooser (javax.swing.JFileChooser)1 JPanel (javax.swing.JPanel)1 Workspace (org.gephi.project.api.Workspace)1 ProjectPropertiesUI (org.gephi.project.spi.ProjectPropertiesUI)1 DialogFileFilter (org.gephi.ui.utils.DialogFileFilter)1 DialogDescriptor (org.openide.DialogDescriptor)1 FileObject (org.openide.filesystems.FileObject)1