use of au.gov.asd.tac.constellation.graph.node.GraphNode in project constellation by constellation-app.
the class SaveAsAction method isFileInUse.
/**
* verify whether any other graph has this file opened
*
* @param filename the proposed filename
* @return boolean
*/
public boolean isFileInUse(final File filename) {
boolean fileInUse = false;
try {
Iterator<Graph> iter = GraphNode.getAllGraphs().values().iterator();
while (!fileInUse && iter.hasNext()) {
GraphNode node = GraphNode.getGraphNode(iter.next());
if (!node.getDataObject().isInMemory()) {
File existingFile = new File(node.getDataObject().getPrimaryFile().getPath());
fileInUse = filename.getCanonicalPath().equalsIgnoreCase(existingFile.getCanonicalPath());
}
}
} catch (final Exception ex) {
}
return fileInUse;
}
use of au.gov.asd.tac.constellation.graph.node.GraphNode in project constellation by constellation-app.
the class SaveGraphPlugin method execute.
@Override
protected void execute(PluginGraphs graphs, PluginInteraction interaction, PluginParameters parameters) throws InterruptedException, PluginException {
final Graph g = graphs.getAllGraphs().get(parameters.getStringValue(GRAPH_PARAMETER));
final String filePath = parameters.getStringValue(FILE_PATH_PARAMETER);
final GraphNode gn = GraphNode.getGraphNode(g);
try {
final File fileLocation = new File(filePath);
if (fileLocation.exists()) {
final DataFolder df = DataFolder.findFolder(FileUtil.createFolder(fileLocation));
// Move the GraphNode's data object to the location inputted by the user
gn.getDataObject().move(df);
SwingUtilities.invokeLater(() -> {
try {
((VisualGraphTopComponent) gn.getTopComponent()).saveGraph();
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
});
} else {
JOptionPane.showMessageDialog(null, "Error: Invalid file path parameter");
}
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
}
use of au.gov.asd.tac.constellation.graph.node.GraphNode in project constellation by constellation-app.
the class RecentGraphScreenshotUtilities method takeScreenshot.
/**
* Take a screenshot of the graph and save it to the screenshots directory
* so that it can be used by the Welcome View.
*
* @param filename The filename of the graph
*/
public static void takeScreenshot(final String filename) {
final String imageFile = getScreenshotsDir() + File.separator + filename + FileExtensionConstants.PNG;
final Path source = Paths.get(imageFile);
final GraphNode graphNode = GraphNode.getGraphNode(GraphManager.getDefault().getActiveGraph());
final VisualManager visualManager = graphNode.getVisualManager();
final BufferedImage[] originalImage = new BufferedImage[1];
originalImage[0] = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB);
if (visualManager != null) {
final Semaphore waiter = new Semaphore(0);
visualManager.exportToBufferedImage(originalImage, waiter);
waiter.acquireUninterruptibly();
}
try {
// resizeAndSave the buffered image in memory and write the image to disk
resizeAndSave(originalImage[0], source, IMAGE_SIZE, IMAGE_SIZE);
refreshScreenshotsDir();
} catch (final IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
use of au.gov.asd.tac.constellation.graph.node.GraphNode in project constellation by constellation-app.
the class AutosaveGraphPlugin method execute.
@Override
public void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final Graph graph = graphs.getGraph();
final String graphId = graph.getId();
final GraphNode gnode = GraphNode.getGraphNode(graphId);
// The user might have deleted the graph, so check first.
if (gnode != null) {
interaction.setProgress(-1, -1, "Autosaving: " + graphId, true);
// We don't want to hold the user up while we're reading from a graph they might be using.
// Make a copy of the graph so that we can release the read lock as soon as possible.
GraphReadMethods copy;
ReadableGraph rg = graph.getReadableGraph();
try {
copy = rg.copy();
} finally {
rg.release();
}
interaction.setProgress(1, 0, "Finished", true);
final File saveDir = AutosaveUtilities.getAutosaveDir();
try {
final String gname = graph.getId() + FileExtensionConstants.STAR;
StatusDisplayer.getDefault().setStatusText(String.format("Auto saving %s as %s at %s...", graphId, gname, new Date()));
final File saveFile = new File(saveDir, gname);
new GraphJsonWriter().writeGraphToZip(copy, saveFile.getPath(), new HandleIoProgress("Autosaving..."));
ConstellationLoggerHelper.exportPropertyBuilder(this, GraphRecordStoreUtilities.getVertices(copy, false, false, false).getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), saveFile, ConstellationLoggerHelper.SUCCESS);
final Properties p = new Properties();
p.setProperty(AutosaveUtilities.ID, graph.getId());
p.setProperty(AutosaveUtilities.NAME, gnode.getName());
p.setProperty(AutosaveUtilities.PATH, gnode.getDataObject().getPrimaryFile().getPath());
p.setProperty(AutosaveUtilities.UNSAVED, Boolean.toString(gnode.getDataObject().isInMemory()));
p.setProperty(AutosaveUtilities.DT, ZonedDateTime.now().format(TemporalFormatting.ZONED_DATE_TIME_FORMATTER));
try (OutputStream s = new FileOutputStream(new File(saveDir, gname + "_auto"))) {
p.store(s, null);
}
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
}
use of au.gov.asd.tac.constellation.graph.node.GraphNode in project constellation by constellation-app.
the class CloseGraphPlugin method execute.
@Override
protected void execute(PluginGraphs graphs, PluginInteraction interaction, PluginParameters parameters) throws InterruptedException, PluginException {
final Graph g = graphs.getAllGraphs().get(parameters.getStringValue(GRAPH_PARAMETER_ID));
final GraphNode gn = GraphNode.getGraphNode(g);
final boolean forced = parameters.getBooleanValue(FORCED_PARAMETER_ID);
if (forced) {
SwingUtilities.invokeLater(((VisualGraphTopComponent) gn.getTopComponent())::forceClose);
} else {
SwingUtilities.invokeLater(gn.getTopComponent()::close);
}
}
Aggregations