Search in sources :

Example 6 with GraphNode

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;
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) File(java.io.File) IOException(java.io.IOException)

Example 7 with GraphNode

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());
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) IOException(java.io.IOException) File(java.io.File) DataFolder(org.openide.loaders.DataFolder) VisualGraphTopComponent(au.gov.asd.tac.constellation.graph.interaction.gui.VisualGraphTopComponent)

Example 8 with GraphNode

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);
    }
}
Also used : Path(java.nio.file.Path) VisualManager(au.gov.asd.tac.constellation.utilities.visual.VisualManager) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 9 with GraphNode

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);
        }
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) HandleIoProgress(au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 10 with GraphNode

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);
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode)

Aggregations

GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)21 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)11 TopComponent (org.openide.windows.TopComponent)9 Test (org.testng.annotations.Test)9 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)8 AdvancedFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin)8 FindResult (au.gov.asd.tac.constellation.views.find.advanced.FindResult)8 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Graph (au.gov.asd.tac.constellation.graph.Graph)6 File (java.io.File)5 IOException (java.io.IOException)5 VisualManager (au.gov.asd.tac.constellation.utilities.visual.VisualManager)3 RestServiceException (au.gov.asd.tac.constellation.webserver.restapi.RestServiceException)2 BufferedImage (java.awt.image.BufferedImage)2 Semaphore (java.util.concurrent.Semaphore)2 GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1 GraphDataObject (au.gov.asd.tac.constellation.graph.file.GraphDataObject)1