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