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