Search in sources :

Example 1 with WorkspaceInformationImpl

use of org.gephi.workspace.impl.WorkspaceInformationImpl in project gephi by gephi.

the class GephiReader method readWorkspace.

public static WorkspaceImpl readWorkspace(XMLStreamReader reader, ProjectImpl project) throws Exception {
    WorkspaceImpl workspace = null;
    boolean end = false;
    while (reader.hasNext() && !end) {
        Integer eventType = reader.next();
        if (eventType.equals(XMLEvent.START_ELEMENT)) {
            String name = reader.getLocalName();
            if ("workspace".equalsIgnoreCase(name)) {
                //Id
                Integer workspaceId;
                if (reader.getAttributeValue(null, "id") == null) {
                    workspaceId = project.nextWorkspaceId();
                } else {
                    workspaceId = Integer.parseInt(reader.getAttributeValue(null, "id"));
                }
                workspace = project.getLookup().lookup(WorkspaceProviderImpl.class).newWorkspace(workspaceId);
                WorkspaceInformationImpl info = workspace.getLookup().lookup(WorkspaceInformationImpl.class);
                //Name
                info.setName(reader.getAttributeValue(null, "name"));
                //Status
                String workspaceStatus = reader.getAttributeValue(null, "status");
                if (workspaceStatus.equals("open")) {
                    info.open();
                } else if (workspaceStatus.equals("closed")) {
                    info.close();
                } else {
                    info.invalid();
                }
            }
        } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
            if ("workspace".equalsIgnoreCase(reader.getLocalName())) {
                end = true;
            }
        }
    }
    return workspace;
}
Also used : WorkspaceImpl(org.gephi.workspace.impl.WorkspaceImpl) WorkspaceInformationImpl(org.gephi.workspace.impl.WorkspaceInformationImpl)

Example 2 with WorkspaceInformationImpl

use of org.gephi.workspace.impl.WorkspaceInformationImpl 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 3 with WorkspaceInformationImpl

use of org.gephi.workspace.impl.WorkspaceInformationImpl in project gephi by gephi.

the class GephiReader method readWorkspaceLegacy.

private static void readWorkspaceLegacy(XMLStreamReader reader, ProjectImpl project) throws Exception {
    WorkspaceImpl workspace = project.getLookup().lookup(WorkspaceProviderImpl.class).newWorkspace();
    WorkspaceInformationImpl info = workspace.getLookup().lookup(WorkspaceInformationImpl.class);
    //Name
    info.setName(reader.getAttributeValue(null, "name"));
    //Status
    String workspaceStatus = reader.getAttributeValue(null, "status");
    if (workspaceStatus.equals("open")) {
        info.open();
    } else if (workspaceStatus.equals("closed")) {
        info.close();
    } else {
        info.invalid();
    }
    Map<String, WorkspaceXMLPersistenceProvider> providers = new LinkedHashMap<>();
    for (WorkspacePersistenceProvider w : Lookup.getDefault().lookupAll(WorkspacePersistenceProvider.class)) {
        String id = w.getIdentifier();
        if (id != null && !id.isEmpty() && w instanceof WorkspaceXMLPersistenceProvider) {
            providers.put(w.getIdentifier(), (WorkspaceXMLPersistenceProvider) w);
        }
    }
    boolean end = false;
    while (reader.hasNext() && !end) {
        Integer eventType = reader.next();
        if (eventType.equals(XMLEvent.START_ELEMENT)) {
            String name = reader.getLocalName();
            WorkspaceXMLPersistenceProvider pp = providers.get(name);
            if (pp != null) {
                try {
                    pp.readXML(reader, workspace);
                } catch (UnsupportedOperationException e) {
                }
            }
        } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
            if ("workspace".equalsIgnoreCase(reader.getLocalName())) {
                end = true;
            }
        }
    }
}
Also used : WorkspaceImpl(org.gephi.workspace.impl.WorkspaceImpl) WorkspaceProviderImpl(org.gephi.project.impl.WorkspaceProviderImpl) WorkspaceInformationImpl(org.gephi.workspace.impl.WorkspaceInformationImpl) WorkspacePersistenceProvider(org.gephi.project.spi.WorkspacePersistenceProvider) LinkedHashMap(java.util.LinkedHashMap) WorkspaceXMLPersistenceProvider(org.gephi.project.spi.WorkspaceXMLPersistenceProvider)

Aggregations

WorkspaceImpl (org.gephi.workspace.impl.WorkspaceImpl)3 WorkspaceInformationImpl (org.gephi.workspace.impl.WorkspaceInformationImpl)3 WorkspaceProviderImpl (org.gephi.project.impl.WorkspaceProviderImpl)2 WorkspacePersistenceProvider (org.gephi.project.spi.WorkspacePersistenceProvider)2 WorkspaceXMLPersistenceProvider (org.gephi.project.spi.WorkspaceXMLPersistenceProvider)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Workspace (org.gephi.project.api.Workspace)1 ProjectControllerImpl (org.gephi.project.impl.ProjectControllerImpl)1 ProjectImpl (org.gephi.project.impl.ProjectImpl)1 WorkspaceBytesPersistenceProvider (org.gephi.project.spi.WorkspaceBytesPersistenceProvider)1