Search in sources :

Example 1 with Workspace

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

the class LoadTask method run.

@Override
public void run() {
    Progress.start(progressTicket);
    Progress.setDisplayName(progressTicket, NbBundle.getMessage(LoadTask.class, "LoadTask.name"));
    try {
        ZipFile zip = null;
        try {
            zip = new ZipFile(file);
            ProjectImpl project = readProject(zip);
            if (project != null) {
                // Enumerate workspaces
                List<String> workspaceEntries = new ArrayList<>();
                for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
                    ZipEntry entry = e.nextElement();
                    if (entry.getName().matches("Workspace_[0-9]*_xml")) {
                        workspaceEntries.add(entry.getName());
                    }
                }
                // Get providers
                Collection<WorkspacePersistenceProvider> providers = PersistenceProviderUtils.getPersistenceProviders();
                //Setup progress
                Progress.switchToDeterminate(progressTicket, (1 + providers.size()) * workspaceEntries.size());
                // Read workspaces
                for (String workspaceEntry : workspaceEntries) {
                    WorkspaceImpl workspace = readWorkspace(project, workspaceEntry, zip);
                    Progress.progress(progressTicket);
                    if (workspace != null) {
                        for (WorkspacePersistenceProvider provider : providers) {
                            if (provider instanceof WorkspaceXMLPersistenceProvider) {
                                readWorkspaceChildrenXML((WorkspaceXMLPersistenceProvider) provider, workspace, zip);
                            } else if (provider instanceof WorkspaceBytesPersistenceProvider) {
                                readWorkspaceChildrenBytes((WorkspaceBytesPersistenceProvider) provider, workspace, zip);
                            }
                            Progress.progress(progressTicket);
                            if (cancel) {
                                break;
                            }
                        }
                    }
                    if (cancel) {
                        break;
                    }
                }
            }
            Progress.switchToIndeterminate(progressTicket);
            //Add project
            ProjectControllerImpl projectController = Lookup.getDefault().lookup(ProjectControllerImpl.class);
            if (project != null && !cancel) {
                if (!cancel) {
                    //Set current workspace
                    WorkspaceProviderImpl workspaces = project.getLookup().lookup(WorkspaceProviderImpl.class);
                    for (Workspace workspace : workspaces.getWorkspaces()) {
                        WorkspaceInformationImpl info = workspace.getLookup().lookup(WorkspaceInformationImpl.class);
                        if (info.isOpen()) {
                            workspaces.setCurrentWorkspace(workspace);
                            break;
                        }
                    }
                    // Open project
                    projectController.openProject(project);
                }
            }
        } finally {
            if (zip != null) {
                zip.close();
            }
        }
    } catch (Exception ex) {
        if (ex instanceof GephiFormatException) {
            throw (GephiFormatException) ex;
        }
        throw new GephiFormatException(GephiReader.class, ex);
    }
    Progress.finish(progressTicket);
}
Also used : ProjectControllerImpl(org.gephi.project.impl.ProjectControllerImpl) WorkspaceImpl(org.gephi.workspace.impl.WorkspaceImpl) WorkspaceProviderImpl(org.gephi.project.impl.WorkspaceProviderImpl) ProjectImpl(org.gephi.project.impl.ProjectImpl) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) WorkspacePersistenceProvider(org.gephi.project.spi.WorkspacePersistenceProvider) WorkspaceInformationImpl(org.gephi.workspace.impl.WorkspaceInformationImpl) XMLStreamException(javax.xml.stream.XMLStreamException) WorkspaceXMLPersistenceProvider(org.gephi.project.spi.WorkspaceXMLPersistenceProvider) ZipFile(java.util.zip.ZipFile) WorkspaceBytesPersistenceProvider(org.gephi.project.spi.WorkspaceBytesPersistenceProvider) Workspace(org.gephi.project.api.Workspace)

Example 2 with Workspace

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

the class ProjectControllerImpl method newWorkspace.

@Override
public Workspace newWorkspace(Project project) {
    Workspace workspace = project.getLookup().lookup(WorkspaceProviderImpl.class).newWorkspace();
    //Event
    fireWorkspaceEvent(EventType.INITIALIZE, workspace);
    return workspace;
}
Also used : Workspace(org.gephi.project.api.Workspace)

Example 3 with Workspace

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

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

the class DesktopImportControllerUI method finishImport.

private void finishImport(Container[] containers) {
    Report finalReport = new Report();
    for (Container container : containers) {
        if (container.verify()) {
            Report report = container.getReport();
            report.close();
            finalReport.append(report);
        } else {
        //TODO
        }
    }
    finalReport.close();
    //Report panel
    ReportPanel reportPanel = new ReportPanel();
    reportPanel.setData(finalReport, containers);
    DialogDescriptor dd = new DialogDescriptor(reportPanel, NbBundle.getMessage(DesktopImportControllerUI.class, "ReportPanel.title"));
    Object response = DialogDisplayer.getDefault().notify(dd);
    reportPanel.destroy();
    finalReport.clean();
    for (Container c : containers) {
        c.getReport().clean();
    }
    if (!response.equals(NotifyDescriptor.OK_OPTION)) {
        return;
    }
    final Processor processor = reportPanel.getProcessor();
    //Project
    Workspace workspace = null;
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    ProjectControllerUI pcui = Lookup.getDefault().lookup(ProjectControllerUI.class);
    if (pc.getCurrentProject() == null) {
        pcui.newProject();
        workspace = pc.getCurrentWorkspace();
    }
    //Process
    final ProcessorUI pui = getProcessorUI(processor);
    final ValidResult validResult = new ValidResult();
    if (pui != null) {
        try {
            final JPanel panel = pui.getPanel();
            if (panel != null) {
                SwingUtilities.invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.processor.ui.dialog.title");
                        pui.setup(processor);
                        final DialogDescriptor dd2 = new DialogDescriptor(panel, title);
                        if (panel instanceof ValidationPanel) {
                            ValidationPanel vp = (ValidationPanel) panel;
                            vp.addChangeListener(new ChangeListener() {

                                @Override
                                public void stateChanged(ChangeEvent e) {
                                    dd2.setValid(!((ValidationPanel) e.getSource()).isProblem());
                                }
                            });
                            dd2.setValid(!vp.isProblem());
                        }
                        Object result = DialogDisplayer.getDefault().notify(dd2);
                        if (result.equals(NotifyDescriptor.CANCEL_OPTION) || result.equals(NotifyDescriptor.CLOSED_OPTION)) {
                            validResult.setResult(false);
                        } else {
                            //true
                            pui.unsetup();
                            validResult.setResult(true);
                        }
                    }
                });
            }
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        } catch (InvocationTargetException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    if (validResult.isResult()) {
        controller.process(containers, processor, workspace);
        //StatusLine notify
        StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.status.multiImportSuccess", containers.length));
    }
}
Also used : JPanel(javax.swing.JPanel) Processor(org.gephi.io.processor.spi.Processor) Report(org.gephi.io.importer.api.Report) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) ProjectController(org.gephi.project.api.ProjectController) ProcessorUI(org.gephi.io.processor.spi.ProcessorUI) InvocationTargetException(java.lang.reflect.InvocationTargetException) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject) ChangeListener(javax.swing.event.ChangeListener) Workspace(org.gephi.project.api.Workspace) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 5 with Workspace

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

the class DesktopGeneratorController method finishGenerate.

private void finishGenerate(Container container) {
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    ProjectControllerUI pcui = Lookup.getDefault().lookup(ProjectControllerUI.class);
    Workspace workspace;
    if (pc.getCurrentProject() == null) {
        pcui.newProject();
        workspace = pc.getCurrentWorkspace();
    } else {
        workspace = pc.newWorkspace(pc.getCurrentProject());
        pc.openWorkspace(workspace);
    }
    if (container.getSource() != null) {
        pc.setSource(workspace, container.getSource());
    }
    container.closeLoader();
    DefaultProcessor defaultProcessor = new DefaultProcessor();
    defaultProcessor.setContainers(new ContainerUnloader[] { container.getUnloader() });
    defaultProcessor.setWorkspace(workspace);
    defaultProcessor.process();
}
Also used : DefaultProcessor(org.gephi.io.processor.plugin.DefaultProcessor) ProjectController(org.gephi.project.api.ProjectController) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI) 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