Search in sources :

Example 11 with Workspace

use of org.gephi.project.api.Workspace 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 12 with Workspace

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

the class GraphControllerImpl method getGraphModel.

@Override
public synchronized GraphModel getGraphModel() {
    Workspace currentWorkspace = Lookup.getDefault().lookup(ProjectController.class).getCurrentWorkspace();
    if (currentWorkspace == null) {
        return null;
    }
    GraphModel model = currentWorkspace.getLookup().lookup(GraphModel.class);
    if (model == null) {
        model = newGraphModel(currentWorkspace);
    }
    return model;
}
Also used : GraphModel(org.gephi.graph.api.GraphModel) ProjectController(org.gephi.project.api.ProjectController) Workspace(org.gephi.project.api.Workspace)

Example 13 with Workspace

use of org.gephi.project.api.Workspace 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)

Example 14 with Workspace

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

the class SaveTask method run.

@Override
public void run() {
    Progress.start(progressTicket);
    Progress.setDisplayName(progressTicket, NbBundle.getMessage(SaveTask.class, "SaveTask.name"));
    File writeFile = null;
    try {
        String tempFileName = file.getName() + "_temp" + System.currentTimeMillis();
        writeFile = new File(file.getParent(), tempFileName);
        FileOutputStream outputStream = null;
        ZipOutputStream zipOut = null;
        BufferedOutputStream bos = null;
        DataOutputStream dos = null;
        try {
            //Stream
            int zipLevel = NbPreferences.forModule(SaveTask.class).getInt(ZIP_LEVEL_PREFERENCE, 9);
            outputStream = new FileOutputStream(writeFile);
            zipOut = new ZipOutputStream(outputStream);
            zipOut.setLevel(zipLevel);
            bos = new BufferedOutputStream(zipOut);
            dos = new DataOutputStream(bos);
            //Providers and workspace
            Collection<WorkspacePersistenceProvider> providers = PersistenceProviderUtils.getPersistenceProviders();
            Workspace[] workspaces = project.getLookup().lookup(WorkspaceProviderImpl.class).getWorkspaces();
            //Setup progress
            Progress.switchToDeterminate(progressTicket, 1 + (1 + providers.size()) * workspaces.length);
            //Write Project
            writeProject(dos, zipOut);
            Progress.progress(progressTicket);
            //Write Workspace files
            for (Workspace ws : workspaces) {
                writeWorkspace(ws, dos, zipOut);
                Progress.progress(progressTicket);
                for (WorkspacePersistenceProvider provider : providers) {
                    if (provider instanceof WorkspaceXMLPersistenceProvider) {
                        writeWorkspaceChildrenXML(ws, (WorkspaceXMLPersistenceProvider) provider, dos, zipOut);
                    } else if (provider instanceof WorkspaceBytesPersistenceProvider) {
                        writeWorkspaceChildrenBytes(ws, (WorkspaceBytesPersistenceProvider) provider, dos, zipOut);
                    }
                    Progress.progress(progressTicket);
                    if (cancel) {
                        break;
                    }
                }
                if (cancel) {
                    break;
                }
            }
            Progress.switchToIndeterminate(progressTicket);
            zipOut.finish();
        } finally {
            if (dos != null) {
                try {
                    dos.close();
                } catch (IOException ex1) {
                }
            }
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException ex1) {
                }
            }
            if (zipOut != null) {
                try {
                    zipOut.close();
                } catch (IOException ex1) {
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException ex1) {
                }
            }
        }
        Progress.finish(progressTicket);
        //Rename file
        if (!cancel && writeFile.exists()) {
            //Delete original file
            if (file.exists()) {
                file.delete();
            }
            FileObject tempFileObject = FileUtil.toFileObject(writeFile);
            FileLock lock = tempFileObject.lock();
            tempFileObject.rename(lock, getFileNameWithoutExt(file), getFileExtension(file));
            lock.releaseLock();
        }
    } catch (Exception ex) {
        if (ex instanceof GephiFormatException) {
            throw (GephiFormatException) ex;
        }
        throw new GephiFormatException(SaveTask.class, ex);
    } finally {
        if (writeFile != null && writeFile.exists()) {
            FileObject tempFileObject = FileUtil.toFileObject(writeFile);
            try {
                tempFileObject.delete();
            } catch (IOException ex) {
            }
        }
    }
    Progress.finish(progressTicket);
}
Also used : WorkspaceProviderImpl(org.gephi.project.impl.WorkspaceProviderImpl) DataOutputStream(java.io.DataOutputStream) WorkspacePersistenceProvider(org.gephi.project.spi.WorkspacePersistenceProvider) IOException(java.io.IOException) IOException(java.io.IOException) WorkspaceXMLPersistenceProvider(org.gephi.project.spi.WorkspaceXMLPersistenceProvider) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) WorkspaceBytesPersistenceProvider(org.gephi.project.spi.WorkspaceBytesPersistenceProvider) FileLock(org.openide.filesystems.FileLock) FileObject(org.openide.filesystems.FileObject) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Workspace(org.gephi.project.api.Workspace)

Example 15 with Workspace

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

the class ProjectControllerImpl method closeCurrentProject.

@Override
public void closeCurrentProject() {
    if (projects.hasCurrentProject()) {
        ProjectImpl currentProject = projects.getCurrentProject();
        //Event
        if (currentProject.getLookup().lookup(WorkspaceProvider.class).hasCurrentWorkspace()) {
            fireWorkspaceEvent(EventType.UNSELECT, currentProject.getLookup().lookup(WorkspaceProvider.class).getCurrentWorkspace());
        }
        for (Workspace ws : currentProject.getLookup().lookup(WorkspaceProviderImpl.class).getWorkspaces()) {
            fireWorkspaceEvent(EventType.CLOSE, ws);
        }
        //Close
        currentProject.getLookup().lookup(ProjectInformationImpl.class).close();
        projects.closeCurrentProject();
        fireWorkspaceEvent(EventType.DISABLE, null);
        //Remove
        projects.removeProject(currentProject);
    }
}
Also used : WorkspaceProvider(org.gephi.project.api.WorkspaceProvider) Workspace(org.gephi.project.api.Workspace)

Aggregations

Workspace (org.gephi.project.api.Workspace)21 ProjectController (org.gephi.project.api.ProjectController)12 IOException (java.io.IOException)4 GraphModel (org.gephi.graph.api.GraphModel)3 WorkspaceListener (org.gephi.project.api.WorkspaceListener)3 WorkspaceProvider (org.gephi.project.api.WorkspaceProvider)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 JPanel (javax.swing.JPanel)2 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)2 GraphController (org.gephi.graph.api.GraphController)2 WorkspaceInformation (org.gephi.project.api.WorkspaceInformation)2 WorkspaceProviderImpl (org.gephi.project.impl.WorkspaceProviderImpl)2 WorkspaceBytesPersistenceProvider (org.gephi.project.spi.WorkspaceBytesPersistenceProvider)2 WorkspacePersistenceProvider (org.gephi.project.spi.WorkspacePersistenceProvider)2 WorkspaceXMLPersistenceProvider (org.gephi.project.spi.WorkspaceXMLPersistenceProvider)2 DialogDescriptor (org.openide.DialogDescriptor)2 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1