Search in sources :

Example 1 with GraphDataObject

use of au.gov.asd.tac.constellation.graph.file.GraphDataObject in project constellation by constellation-app.

the class SimpleGraphOpener method openGraph.

@Override
public void openGraph(final Graph graph, final String name, Runnable doAfter) {
    final GraphDataObject gdo = GraphObjectUtilities.createMemoryDataObject(name, true);
    new SimpleGraphFileOpener(gdo, graph, doAfter).execute();
}
Also used : GraphDataObject(au.gov.asd.tac.constellation.graph.file.GraphDataObject)

Example 2 with GraphDataObject

use of au.gov.asd.tac.constellation.graph.file.GraphDataObject in project constellation by constellation-app.

the class VisualGraphOpener method openGraph.

@Override
public void openGraph(final Graph graph, final String name) {
    final GraphDataObject gdo = GraphObjectUtilities.createMemoryDataObject(name, true);
    new GraphFileOpener(gdo, graph, null).execute();
}
Also used : GraphDataObject(au.gov.asd.tac.constellation.graph.file.GraphDataObject)

Example 3 with GraphDataObject

use of au.gov.asd.tac.constellation.graph.file.GraphDataObject in project constellation by constellation-app.

the class VisualGraphOpener method openGraph.

@Override
public void openGraph(final Graph graph, final String name, Runnable doAfter) {
    final GraphDataObject gdo = GraphObjectUtilities.createMemoryDataObject(name, true);
    new GraphFileOpener(gdo, graph, doAfter).execute();
}
Also used : GraphDataObject(au.gov.asd.tac.constellation.graph.file.GraphDataObject)

Example 4 with GraphDataObject

use of au.gov.asd.tac.constellation.graph.file.GraphDataObject in project constellation by constellation-app.

the class AutosaveGraphPluginNGTest method testExecute.

/**
 * Test of execute method, of class AutosaveGraphPlugin.
 *
 * @throws java.lang.Exception
 */
@Test
public void testExecute() throws Exception {
    final File saveDir = AutosaveUtilities.getAutosaveDir();
    final File saveFile = new File(saveDir, graph.getId() + FileExtensionConstants.STAR);
    // check the autosave file doesn't exist before running the plugin
    assertEquals(saveFile.exists(), false);
    TopComponent tc = new TopComponent();
    tc.setName("TestName");
    final GraphDataObject gdo = GraphObjectUtilities.createMemoryDataObject("graph", true);
    final GraphNode graphNode = new GraphNode(graph, gdo, tc, null);
    AutosaveGraphPlugin instance = new AutosaveGraphPlugin();
    PluginExecution.withPlugin(instance).executeNow(graph);
    // check that the autosave file does now exist
    assertEquals(saveFile.exists(), true);
    final Graph openSavedGraph = new GraphJsonReader().readGraphZip(saveFile, new TextIoProgress(false));
    final ReadableGraph rg = openSavedGraph.getReadableGraph();
    try {
        // check that the graph from the autosave matches the original graph
        assertEquals(rg.getVertexCount(), 7);
        assertEquals(rg.getStringValue(vAttrId, vxId1), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId2), "true");
        assertEquals(rg.getStringValue(vAttrId, vxId3), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId4), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId5), "true");
        assertEquals(rg.getTransactionCount(), 5);
    } finally {
        rg.release();
        // deleting the file afterwards
        AutosaveUtilities.deleteAutosave(saveFile);
        graphNode.destroy();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphDataObject(au.gov.asd.tac.constellation.graph.file.GraphDataObject) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File) TopComponent(org.openide.windows.TopComponent) GraphJsonReader(au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader) Test(org.testng.annotations.Test)

Example 5 with GraphDataObject

use of au.gov.asd.tac.constellation.graph.file.GraphDataObject in project constellation by constellation-app.

the class NebulaDataObject method open.

@Override
public void open() {
    final Properties props = new Properties();
    try (final FileReader reader = new FileReader(getPrimaryFile().getPath())) {
        props.load(reader);
    } catch (final IOException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    // Generate a color for the nebula marker.
    // First, see if the user has specified a color in the nebula file.
    Color c = null;
    final String cname = props.getProperty("colour") != null ? props.getProperty("colour") : props.getProperty("color");
    if (cname != null) {
        ConstellationColor cv = ConstellationColor.fromHtmlColor(cname);
        if (cv == null) {
            cv = ConstellationColor.getColorValue(cname);
        }
        if (cv != null) {
            c = cv.getJavaColor();
        }
    }
    // Therefore, we track the random colors as we create them,
    if (c == null) {
        c = NEBULA_COLOR.get(getPrimaryFile().getPath());
    }
    // Otherwise, create a random color for this nebula.
    if (c == null) {
        final float h = new SecureRandom().nextFloat();
        c = Color.getHSBColor(h, 0.5F, 0.95F);
        NEBULA_COLOR.put(getPrimaryFile().getPath(), c);
    }
    for (final Enumeration<DataObject> i = getFolder().children(); i.hasMoreElements(); ) {
        final DataObject dobj = i.nextElement();
        if (dobj instanceof GraphDataObject) {
            final GraphDataObject gdo = (GraphDataObject) dobj;
            gdo.setNebulaDataObject(this);
            gdo.setNebulaColor(c);
            GraphOpener.getDefault().openGraph(gdo);
        }
    }
    // Because we haven't registered an editor, a TopComponent won't open for this file (which is good).
    // However, the recent files stuff works by watching for opening TopComponents (which is bad).
    // So, do it manually.
    // FileObject.getPath() returns a path containing "/"; we need to convert it to local separators for RecentFiles.
    final String path = new File(getPrimaryFile().getPath()).getAbsolutePath();
    RecentFiles.addFile(path);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) MultiDataObject(org.openide.loaders.MultiDataObject) DataObject(org.openide.loaders.DataObject) GraphDataObject(au.gov.asd.tac.constellation.graph.file.GraphDataObject) Color(java.awt.Color) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) GraphDataObject(au.gov.asd.tac.constellation.graph.file.GraphDataObject) SecureRandom(java.security.SecureRandom) FileReader(java.io.FileReader) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

Aggregations

GraphDataObject (au.gov.asd.tac.constellation.graph.file.GraphDataObject)9 File (java.io.File)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 TopComponent (org.openide.windows.TopComponent)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1 ZonedDateTimeAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.ZonedDateTimeAttributeDescription)1 GraphJsonReader (au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader)1 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)1 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)1 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)1 TextIoProgress (au.gov.asd.tac.constellation.utilities.gui.TextIoProgress)1 Color (java.awt.Color)1 FileReader (java.io.FileReader)1 SecureRandom (java.security.SecureRandom)1 ZonedDateTime (java.time.ZonedDateTime)1 Date (java.util.Date)1 NotifyDescriptor (org.openide.NotifyDescriptor)1