use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class CompositesNGTest method ensureCompositeStateImmutabilityTest.
// This test checks that expanding composite node states that have been copied to another graph do not affect the
// composite node states in the original graph.
@Test
public void ensureCompositeStateImmutabilityTest() throws InterruptedException, PluginException {
final WritableGraph wg = graph.getWritableGraph("test", true);
wg.getSchema().newGraph(wg);
int v0, v1, v2;
final String v0name, v1name, v2name;
final int nameAttr;
final int selectedAttr;
final Plugin copyPlugin;
try {
// Add three 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);
// 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);
// Add a transaction from v0 to v1
final int t0_1 = wg.addTransaction(v0, v1, true);
wg.getSchema().newTransaction(wg, t0_1);
// Select v0 and v2, but not v1
selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
wg.setBooleanValue(selectedAttr, v0, true);
wg.setBooleanValue(selectedAttr, v2, true);
wg.setBooleanValue(selectedAttr, v1, false);
} finally {
wg.commit();
}
// Make a composite from the selection, then select everything, and copy to a new graph
copyPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
PluginExecutor.startWith(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION).followedBy(VisualGraphPluginRegistry.SELECT_ALL).followedBy(copyPlugin).executeNow(graph);
final WritableGraph copyWg = ((CopyToNewGraphPlugin) copyPlugin).getCopy().getWritableGraph("test", true);
try {
// Expand all composites
PluginExecution.withPlugin(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES).executeNow(copyWg);
} finally {
copyWg.commit();
}
// Now we check there has been no effect on the composite state on the original graph
// by expanding it and then checking it is the same as the orignal graph
final WritableGraph wg2 = graph.getWritableGraph("test", true);
try {
// Expand all composites
PluginExecution.withPlugin(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES).executeNow(wg2);
} finally {
wg2.commit();
}
final ReadableGraph rg = graph.getReadableGraph();
try {
// Assert that there are three vertices all with their original names
assertEquals(rg.getVertexCount(), 3);
for (int i = 0; i < 3; 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 {
v2 = id;
}
}
assertEquals(rg.getStringValue(nameAttr, v0), v0name);
assertEquals(rg.getStringValue(nameAttr, v1), v1name);
assertEquals(rg.getStringValue(nameAttr, v2), v2name);
// Assert that the two transactions exist as expected and no others
assertEquals(rg.getTransactionCount(), 1);
final int l0_1 = rg.getLink(v0, v1);
assertEquals(rg.getLinkTransactionCount(l0_1), 1);
final int t0_1 = rg.getLinkTransaction(l0_1, 0);
assertFalse(rg.getTransactionDirection(t0_1) == Graph.FLAT);
assertEquals(rg.getTransactionSourceVertex(t0_1), v0);
final int l1_2 = rg.getLink(v1, v2);
assertEquals(l1_2, Graph.NOT_FOUND);
final int l0_2 = rg.getLink(v0, v2);
assertEquals(l0_2, Graph.NOT_FOUND);
} finally {
rg.release();
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class PointSelectionPluginNGTest method testOnlyTransactionsSelectedAndVertexSelected.
/**
* Tests when a vertex is selected and; only transactions are selected,
* toggle selection is true, and clear selection is true.
*
* @throws Exception
*/
@Test
public void testOnlyTransactionsSelectedAndVertexSelected() throws Exception {
selectAllAndAssert(GraphElementType.TRANSACTION, true);
vxIds.add(vxId1);
Plugin selectPoint = new PointSelectionPlugin(vxIds, txIds, true, true);
PluginExecution.withPlugin(selectPoint).executeNow(storeGraph);
assertTrue(storeGraph.getBooleanValue(vAttrId, vxId1));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId2));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId3));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId1));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId2));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId3));
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class PointSelectionPluginNGTest method testNoElementsSelectedOnGraph.
/**
* Tests selections with both the toggleSelection and clearSelection options
* on a graph that begins with no elements selected.
*
* @throws Exception
*/
@Test
public void testNoElementsSelectedOnGraph() throws Exception {
// Select vertex vxId1 with clearSelection. All other elements should remain deselected.
vxIds.add(vxId1);
Plugin selectPoint1 = new PointSelectionPlugin(vxIds, txIds, false, true);
PluginExecution.withPlugin(selectPoint1).executeNow(storeGraph);
assertTrue(storeGraph.getBooleanValue(vAttrId, vxId1));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId2));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId3));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId1));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId2));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId3));
vxIds.clear();
txIds.clear();
// Select vertex vxId2 with clearSelection. Should deselect vertex vxId1.
vxIds.add(vxId2);
Plugin selectPoint2 = new PointSelectionPlugin(vxIds, txIds, false, true);
PluginExecution.withPlugin(selectPoint2).executeNow(storeGraph);
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId1));
assertTrue(storeGraph.getBooleanValue(vAttrId, vxId2));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId3));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId1));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId2));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId3));
vxIds.clear();
txIds.clear();
// Select transaction txId3 with toggleSelection. Vertex vxId2 should remain selected.
txIds.add(txId3);
Plugin selectPoint3 = new PointSelectionPlugin(vxIds, txIds, true, false);
PluginExecution.withPlugin(selectPoint3).executeNow(storeGraph);
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId1));
assertTrue(storeGraph.getBooleanValue(vAttrId, vxId2));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId3));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId1));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId2));
assertTrue(storeGraph.getBooleanValue(tAttrId, txId3));
vxIds.clear();
txIds.clear();
// Reselect vertex vxId2 with toggleSelection. Should deselect vertex vxId2 and transaction txId3 should remain selected.
vxIds.add(vxId2);
Plugin selectPoint4 = new PointSelectionPlugin(vxIds, txIds, true, false);
PluginExecution.withPlugin(selectPoint4).executeNow(storeGraph);
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId1));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId2));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId3));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId1));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId2));
assertTrue(storeGraph.getBooleanValue(tAttrId, txId3));
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class PointSelectionPluginNGTest method testNoElementsSelectedAndVertexSelected.
/**
* Tests when a vertex is selected and; all vertices and transaction are
* unselected, toggle selection is true, and clear selection is true.
*
* @throws Exception
*/
@Test
public void testNoElementsSelectedAndVertexSelected() throws Exception {
vxIds.add(vxId1);
Plugin selectPoint = new PointSelectionPlugin(vxIds, txIds, true, true);
PluginExecution.withPlugin(selectPoint).executeNow(storeGraph);
assertTrue(storeGraph.getBooleanValue(vAttrId, vxId1));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId2));
assertFalse(storeGraph.getBooleanValue(vAttrId, vxId3));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId1));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId2));
assertFalse(storeGraph.getBooleanValue(tAttrId, txId3));
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class NamedSelectionManager method performSave.
/**
* Requests a new named selection to be created on the graph for the given
* ID number.
* <p>
* Selected graph elements will have their 'named selection' attribute
* updated to reflect their membership in the new named selection.
*
* @param graph The graph that is having the named selection created on.
* @param id The id of the named selection that is to be included on
* currently selected graph elements.
*/
private void performSave(final Graph graph, final int id) {
final Plugin namedSelectionEdit = new NamedSelectionEditorPlugin(id);
final Future<?> f = PluginExecution.withPlugin(namedSelectionEdit).executeLater(graph);
try {
f.get();
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, "Named Selection save was interrupted", ex);
Thread.currentThread().interrupt();
} catch (final ExecutionException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
Aggregations