Search in sources :

Example 21 with ProjectController

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

the class CopyOrMoveToWorkspace method getSubItems.

@Override
public ContextMenuItemManipulator[] getSubItems() {
    if (nodes != null) {
        int i = 0;
        ArrayList<GraphContextMenuItem> subItems = new ArrayList<>();
        if (canExecute()) {
            //New workspace
            subItems.add(new CopyOrMoveToWorkspaceSubItem(null, true, 0, 0, isCopy()));
            ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
            for (final Workspace w : projectController.getCurrentProject().getLookup().lookup(WorkspaceProvider.class).getWorkspaces()) {
                GraphContextMenuItem item = new CopyOrMoveToWorkspaceSubItem(w, w != projectController.getCurrentWorkspace(), 1, i, isCopy());
                subItems.add(item);
                i++;
            }
            return subItems.toArray(new ContextMenuItemManipulator[0]);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : GraphContextMenuItem(org.gephi.visualization.spi.GraphContextMenuItem) WorkspaceProvider(org.gephi.project.api.WorkspaceProvider) ArrayList(java.util.ArrayList) ProjectController(org.gephi.project.api.ProjectController) Workspace(org.gephi.project.api.Workspace)

Example 22 with ProjectController

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

the class CopyOrMoveToWorkspaceSubItem method copyToWorkspace.

public boolean copyToWorkspace(Workspace workspace) {
    ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
    Workspace currentWorkspace = projectController.getCurrentWorkspace();
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel;
    if (workspace == null) {
        workspace = Lookup.getDefault().lookup(ProjectControllerUI.class).newWorkspace();
        graphModel = graphController.getGraphModel(workspace);
        GraphModel currentGraphModel = graphController.getGraphModel(currentWorkspace);
        graphModel.setConfiguration(currentGraphModel.getConfiguration());
        graphModel.setTimeFormat(currentGraphModel.getTimeFormat());
        graphModel.setTimeZone(currentGraphModel.getTimeZone());
    } else {
        graphModel = graphController.getGraphModel(workspace);
    }
    try {
        graphModel.bridge().copyNodes(nodes);
        return true;
    } catch (Exception e) {
        String error = NbBundle.getMessage(CopyOrMoveToWorkspace.class, "GraphContextMenu_CopyOrMoveToWorkspace_ConfigurationNotCompatible");
        String title = NbBundle.getMessage(CopyOrMoveToWorkspace.class, "GraphContextMenu_CopyOrMoveToWorkspace_ConfigurationNotCompatible_Title");
        JOptionPane.showMessageDialog(null, error, title, JOptionPane.ERROR_MESSAGE);
        return false;
    }
}
Also used : GraphModel(org.gephi.graph.api.GraphModel) ProjectController(org.gephi.project.api.ProjectController) GraphController(org.gephi.graph.api.GraphController) Workspace(org.gephi.project.api.Workspace)

Aggregations

ProjectController (org.gephi.project.api.ProjectController)22 Workspace (org.gephi.project.api.Workspace)11 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)4 ContainerUnloader (org.gephi.io.importer.api.ContainerUnloader)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 JPanel (javax.swing.JPanel)2 GraphController (org.gephi.graph.api.GraphController)2 GraphModel (org.gephi.graph.api.GraphModel)2 WorkspaceInformation (org.gephi.project.api.WorkspaceInformation)2 WorkspaceListener (org.gephi.project.api.WorkspaceListener)2 WorkspaceProvider (org.gephi.project.api.WorkspaceProvider)2 DialogDescriptor (org.openide.DialogDescriptor)2 BorderLayout (java.awt.BorderLayout)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1