Search in sources :

Example 11 with ProjectController

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

the class MultiProcessor method process.

@Override
public void process() {
    if (containers.length <= 1) {
        throw new RuntimeException("This processor can only handle multiple containers");
    }
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    for (ContainerUnloader container : containers) {
        if (workspace != null) {
            pc.openWorkspace(workspace);
        } else {
            workspace = pc.newWorkspace(pc.getCurrentProject());
        }
        processConfiguration(container, workspace);
        process(container, workspace);
        workspace = null;
    }
    //Clean
    workspace = null;
    graphModel = null;
    containers = null;
    progressTicket = null;
}
Also used : ContainerUnloader(org.gephi.io.importer.api.ContainerUnloader) ProjectController(org.gephi.project.api.ProjectController)

Example 12 with ProjectController

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

the class DefaultProcessor method process.

@Override
public void process() {
    if (containers.length > 1) {
        throw new RuntimeException("This processor can only handle single containers");
    }
    ContainerUnloader container = containers[0];
    //Workspace
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    if (workspace == null) {
        workspace = pc.newWorkspace(pc.getCurrentProject());
        pc.openWorkspace(workspace);
    }
    processConfiguration(container, workspace);
    if (container.getSource() != null) {
        pc.setSource(workspace, container.getSource());
    }
    process(container, workspace);
    //Clean
    workspace = null;
    graphModel = null;
    containers = null;
    progressTicket = null;
}
Also used : ContainerUnloader(org.gephi.io.importer.api.ContainerUnloader) ProjectController(org.gephi.project.api.ProjectController)

Example 13 with ProjectController

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

the class StandardTest method setUp.

@BeforeMethod
public void setUp() {
    ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
    projectController.newProject();
    workspace = projectController.getCurrentWorkspace();
    graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
}
Also used : ProjectController(org.gephi.project.api.ProjectController) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 14 with ProjectController

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

the class FilterControllerImpl method exportToNewWorkspace.

@Override
public void exportToNewWorkspace(Query query) {
    Graph result;
    if (model.getCurrentQuery() == query) {
        GraphView view = model.getCurrentResult();
        if (view == null) {
            return;
        }
        result = model.getGraphModel().getGraph(view);
    } else {
        FilterProcessor processor = new FilterProcessor();
        GraphModel graphModel = model.getGraphModel();
        result = (Graph) processor.process((AbstractQueryImpl) query, graphModel);
    }
    final Graph graphView = result;
    new Thread(new Runnable() {

        @Override
        public void run() {
            ProgressTicketProvider progressProvider = Lookup.getDefault().lookup(ProgressTicketProvider.class);
            ProgressTicket ticket = null;
            if (progressProvider != null) {
                String msg = NbBundle.getMessage(FilterControllerImpl.class, "FilterController.exportToNewWorkspace.task");
                ticket = progressProvider.createTicket(msg, null);
            }
            Progress.start(ticket);
            ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
            Workspace newWorkspace = pc.newWorkspace(pc.getCurrentProject());
            GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(newWorkspace);
            graphModel.bridge().copyNodes(graphView.getNodes().toArray());
            Progress.finish(ticket);
            String workspaceName = newWorkspace.getLookup().lookup(WorkspaceInformation.class).getName();
        //StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(FilterControllerImpl.class, "FilterController.exportToNewWorkspace.status", workspaceName));
        }
    }, "Export filter to workspace").start();
}
Also used : GraphView(org.gephi.graph.api.GraphView) ProjectController(org.gephi.project.api.ProjectController) WorkspaceInformation(org.gephi.project.api.WorkspaceInformation) ProgressTicketProvider(org.gephi.utils.progress.ProgressTicketProvider) Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) ProgressTicket(org.gephi.utils.progress.ProgressTicket) GraphController(org.gephi.graph.api.GraphController) Workspace(org.gephi.project.api.Workspace)

Example 15 with ProjectController

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

the class ExportControllerImpl method exportFile.

@Override
public void exportFile(File file, Exporter fileExporter) throws IOException {
    if (fileExporter.getWorkspace() == null) {
        ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
        Workspace workspace = projectController.getCurrentWorkspace();
        fileExporter.setWorkspace(workspace);
    }
    if (fileExporter instanceof ByteExporter) {
        OutputStream stream = new BufferedOutputStream(new FileOutputStream(file));
        ((ByteExporter) fileExporter).setOutputStream(stream);
        try {
            fileExporter.execute();
        } catch (Exception ex) {
            try {
                stream.flush();
                stream.close();
            } catch (IOException exe) {
            }
            if (ex instanceof RuntimeException) {
                throw (RuntimeException) ex;
            }
            throw new RuntimeException(ex);
        }
        try {
            stream.flush();
            stream.close();
        } catch (IOException ex) {
        }
    } else if (fileExporter instanceof CharacterExporter) {
        Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
        ((CharacterExporter) fileExporter).setWriter(writer);
        try {
            fileExporter.execute();
        } catch (Exception ex) {
            try {
                writer.flush();
                writer.close();
            } catch (IOException exe) {
            }
            if (ex instanceof RuntimeException) {
                throw (RuntimeException) ex;
            }
            throw new RuntimeException(ex);
        }
        try {
            writer.flush();
            writer.close();
        } catch (IOException ex) {
        }
    }
}
Also used : ByteExporter(org.gephi.io.exporter.spi.ByteExporter) CharacterExporter(org.gephi.io.exporter.spi.CharacterExporter) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ProjectController(org.gephi.project.api.ProjectController) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) 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