use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class UpdateNGTest method writeLockAndReadLock.
@Test
public void writeLockAndReadLock() throws InterruptedException {
final DualGraph g = new DualGraph(null);
final WritableGraph wg = g.getWritableGraph("Write", true);
try {
wg.addVertex();
ReadableGraph rg = g.getReadableGraph();
try {
assert (rg.getVertexCount() == 1);
} finally {
rg.release();
}
} finally {
wg.commit();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class NewSchemaGraphAction method getMenuPresenters.
@Override
public JComponent[] getMenuPresenters() {
menu = new JMenu("New Graph");
for (final SchemaFactory schemaFactory : SchemaFactoryUtilities.getSchemaFactories().values()) {
if (isValid(schemaFactory)) {
if (!ICON_CACHE.containsKey(schemaFactory.getName())) {
ICON_CACHE.put(schemaFactory.getName(), schemaFactory.getIcon().buildIcon(16));
}
final JMenuItem item = new JMenuItem(schemaFactory.getLabel(), ICON_CACHE.get(schemaFactory.getName()));
item.setToolTipText(schemaFactory.getDescription());
item.setActionCommand(schemaFactory.getName());
item.addActionListener((final ActionEvent e) -> new Thread() {
@Override
public void run() {
setName(GRAPH_ACTION_THREAD_NAME);
final Graph graph = new DualGraph(schemaFactory.createSchema());
final WritableGraph wg = graph.getWritableGraphNow("New " + schemaFactory.getName(), false);
try {
graph.getSchema().newGraph(wg);
} finally {
wg.commit();
}
final String graphName = schemaFactory.getLabel().trim().toLowerCase();
GraphOpener.getDefault().openGraph(graph, graphName);
}
}.start());
menu.add(item);
}
}
menu.addSeparator();
recreateTemplateMenuItems();
return new JComponent[] { menu };
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class SchemaDestination method getGraph.
@Override
public Graph getGraph() {
final SchemaFactory schemaFactory = getDestination();
final Graph graph = new DualGraph(schemaFactory.createSchema());
final WritableGraph wg = graph.getWritableGraphNow("New Graph", true);
try {
graph.getSchema().newGraph(wg);
} finally {
wg.commit();
}
return graph;
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class CutCopyPasteNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
final Schema ss = SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema();
graph = new DualGraph(ss);
WritableGraph wg = graph.getWritableGraph("add", true);
try {
attrX = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "x", "x", 0.0, null);
if (attrX == Graph.NOT_FOUND) {
fail();
}
attrY = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "y", "y", 0.0, null);
if (attrY == Graph.NOT_FOUND) {
fail();
}
attrZ = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "z", "z", 0.0, null);
if (attrZ == Graph.NOT_FOUND) {
fail();
}
vNameAttr = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
if (vNameAttr == Graph.NOT_FOUND) {
fail();
}
tNameAttr = wg.addAttribute(GraphElementType.TRANSACTION, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
if (tNameAttr == Graph.NOT_FOUND) {
fail();
}
vSelAttr = wg.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
if (vSelAttr == Graph.NOT_FOUND) {
fail();
}
tSelAttr = wg.addAttribute(GraphElementType.TRANSACTION, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
if (tSelAttr == Graph.NOT_FOUND) {
fail();
}
vxId1 = wg.addVertex();
wg.setFloatValue(attrX, vxId1, 1.0f);
wg.setFloatValue(attrY, vxId1, 1.0f);
wg.setBooleanValue(vSelAttr, vxId1, false);
wg.setStringValue(vNameAttr, vxId1, "name1");
vxId2 = wg.addVertex();
wg.setFloatValue(attrX, vxId2, 5.0f);
wg.setFloatValue(attrY, vxId2, 1.0f);
wg.setBooleanValue(vSelAttr, vxId2, true);
wg.setStringValue(vNameAttr, vxId2, "name2");
vxId3 = wg.addVertex();
wg.setFloatValue(attrX, vxId3, 1.0f);
wg.setFloatValue(attrY, vxId3, 5.0f);
wg.setBooleanValue(vSelAttr, vxId3, false);
wg.setStringValue(vNameAttr, vxId3, "name3");
vxId4 = wg.addVertex();
wg.setFloatValue(attrX, vxId4, 5.0f);
wg.setFloatValue(attrY, vxId4, 5.4f);
wg.setBooleanValue(vSelAttr, vxId4, true);
wg.setStringValue(vNameAttr, vxId4, "name4");
vxId5 = wg.addVertex();
wg.setFloatValue(attrX, vxId5, 15.0f);
wg.setFloatValue(attrY, vxId5, 15.5f);
wg.setBooleanValue(vSelAttr, vxId5, false);
wg.setStringValue(vNameAttr, vxId5, "name5");
vxId6 = wg.addVertex();
wg.setFloatValue(attrX, vxId6, 26.0f);
wg.setFloatValue(attrY, vxId6, 26.60f);
wg.setBooleanValue(vSelAttr, vxId6, true);
wg.setStringValue(vNameAttr, vxId6, "name6");
vxId7 = wg.addVertex();
wg.setFloatValue(attrX, vxId7, 37.0f);
wg.setFloatValue(attrY, vxId7, 37.7f);
wg.setBooleanValue(vSelAttr, vxId7, false);
wg.setStringValue(vNameAttr, vxId7, "name7");
txId1 = wg.addTransaction(vxId1, vxId2, true);
wg.setBooleanValue(tSelAttr, txId1, false);
wg.setStringValue(tNameAttr, txId1, "name101");
txId2 = wg.addTransaction(vxId1, vxId3, true);
wg.setBooleanValue(tSelAttr, txId2, true);
wg.setStringValue(tNameAttr, txId2, "name102");
txId3 = wg.addTransaction(vxId2, vxId4, true);
wg.setBooleanValue(tSelAttr, txId3, false);
wg.setStringValue(tNameAttr, txId3, "name103");
txId4 = wg.addTransaction(vxId4, vxId2, true);
wg.setBooleanValue(tSelAttr, txId4, true);
wg.setStringValue(tNameAttr, txId4, "name104");
txId5 = wg.addTransaction(vxId5, vxId6, true);
wg.setBooleanValue(tSelAttr, txId5, false);
wg.setStringValue(tNameAttr, txId5, "name105");
} finally {
wg.commit();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class CompositesNGTest method compositeCompositeAndNonCompositeTest.
@Test
public void compositeCompositeAndNonCompositeTest() throws InterruptedException, PluginException {
final WritableGraph wg = graph.getWritableGraph("test", true);
wg.getSchema().newGraph(wg);
int v0, v1, v2, v3;
final String v0name, v1name, v2name, v3name;
final int nameAttr;
final int selectedAttr;
final int compositeAttr;
try {
// Add four vertices
v0 = wg.addVertex();
wg.getSchema().newVertex(wg, v0);
v1 = wg.addVertex();
wg.getSchema().newVertex(wg, v1);
v2 = wg.addVertex();
wg.getSchema().newVertex(wg, v2);
v3 = wg.addVertex();
wg.getSchema().newVertex(wg, v3);
// Store the names of these vertices
nameAttr = VisualConcept.VertexAttribute.LABEL.get(wg);
v0name = wg.getStringValue(nameAttr, v0);
v1name = wg.getStringValue(nameAttr, v1);
v2name = wg.getStringValue(nameAttr, v2);
v3name = wg.getStringValue(nameAttr, v3);
// Add transactions from v0 to v1, and from v1 to v2
final int t0_1 = wg.addTransaction(v0, v1, true);
wg.getSchema().newTransaction(wg, t0_1);
final int t1_2 = wg.addTransaction(v1, v2, true);
wg.getSchema().newTransaction(wg, t1_2);
// Select v0 and v1, but not v2 or v3
selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
wg.setBooleanValue(selectedAttr, v0, true);
wg.setBooleanValue(selectedAttr, v1, true);
wg.setBooleanValue(selectedAttr, v2, false);
wg.setBooleanValue(selectedAttr, v3, false);
// Make a composite from the selection then deselect all
PluginExecutor.startWith(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).followedBy(PluginRegistry.get(VisualGraphPluginRegistry.DESELECT_ALL)).executeNow(wg);
compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(wg);
// Select v2 and the newly made composite
int compNode = wg.getVertex(0);
if (compNode == v2 || compNode == v3) {
compNode = wg.getVertex(1);
}
if (compNode == v2 || compNode == v3) {
compNode = wg.getVertex(2);
}
wg.setBooleanValue(selectedAttr, v2, true);
wg.setBooleanValue(selectedAttr, compNode, true);
// Make a composite from the selection
PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).executeNow(wg);
} finally {
wg.commit();
}
final ReadableGraph rg = graph.getReadableGraph();
try {
// Assert that there is one vertex that is a composite containing three nodes,
// and v3 as the non-composite
assertEquals(rg.getVertexCount(), 2);
final int compositeNode = rg.getVertex(0) == v3 ? rg.getVertex(1) : rg.getVertex(0);
final CompositeNodeState compositeState = (CompositeNodeState) rg.getObjectValue(compositeAttr, compositeNode);
assertNotNull(compositeState);
assertEquals(compositeState.getNumberOfNodes(), 3);
assertTrue(compositeState.isComposite());
assertEquals(rg.getStringValue(nameAttr, v3), v3name);
final CompositeNodeState compositeState0 = (CompositeNodeState) rg.getObjectValue(compositeAttr, v3);
assertNull(compositeState0);
// Assert that there are no transactions on the graph
assertEquals(rg.getTransactionCount(), 0);
} finally {
rg.release();
}
final WritableGraph wg2 = graph.getWritableGraph("test", true);
try {
// Expand all composites
PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES)).executeNow(wg2);
} finally {
wg2.commit();
}
final ReadableGraph rg2 = graph.getReadableGraph();
try {
// Assert that the original four vertices exist; all with expanded composite states
// except v3
assertEquals(rg2.getVertexCount(), 4);
v0 = Graph.NOT_FOUND;
v1 = Graph.NOT_FOUND;
v2 = Graph.NOT_FOUND;
v3 = Graph.NOT_FOUND;
for (int i = 0; i < 4; i++) {
final int id = rg.getVertex(i);
final String name = rg.getStringValue(nameAttr, id);
if (name.equals(v0name)) {
v0 = id;
} else if (name.equals(v1name)) {
v1 = id;
} else if (name.equals(v2name)) {
v2 = id;
} else {
v3 = id;
}
}
assertEquals(rg2.getStringValue(nameAttr, v0), v0name);
final CompositeNodeState compositeState0 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v0);
assertNotNull(compositeState0);
assertEquals(compositeState0.getNumberOfNodes(), 3);
assertTrue(compositeState0.comprisesAComposite());
assertEquals(rg2.getStringValue(nameAttr, v1), v1name);
final CompositeNodeState compositeState1 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v1);
assertNotNull(compositeState1);
assertEquals(compositeState1.getNumberOfNodes(), 3);
assertTrue(compositeState1.comprisesAComposite());
assertEquals(rg2.getStringValue(nameAttr, v2), v2name);
final CompositeNodeState compositeState2 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v2);
assertNotNull(compositeState2);
assertEquals(compositeState2.getNumberOfNodes(), 3);
assertTrue(compositeState2.comprisesAComposite());
assertEquals(rg2.getStringValue(nameAttr, v3), v3name);
final CompositeNodeState compositeState3 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v3);
assertNull(compositeState3);
// assert that the original transactions exist and none others
assertEquals(rg.getTransactionCount(), 2);
final int l0_1 = rg2.getLink(v0, v1);
assertEquals(rg2.getLinkTransactionCount(l0_1), 1);
final int t0_1 = rg2.getLinkTransaction(l0_1, 0);
assertFalse(rg2.getTransactionDirection(t0_1) == Graph.FLAT);
assertEquals(rg2.getTransactionSourceVertex(t0_1), v0);
final int l1_2 = rg2.getLink(v1, v2);
assertEquals(rg2.getLinkTransactionCount(l1_2), 1);
final int t1_2 = rg2.getLinkTransaction(l1_2, 0);
assertFalse(rg2.getTransactionDirection(t1_2) == Graph.FLAT);
assertEquals(rg2.getTransactionSourceVertex(t1_2), v1);
} finally {
rg2.release();
}
}
Aggregations