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);
}
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;
}
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);
}
}
}
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));
}
}
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();
}
Aggregations