use of org.gephi.project.impl.WorkspaceProviderImpl 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);
}
Aggregations