use of au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin in project constellation by constellation-app.
the class KTrussControllerTopComponent method setColoring.
private void setColoring() {
if (graphNode == null) {
return;
}
final boolean wasColored = state.isNestedTrussesColored();
state.toggleNestedTrussesColored();
final SimpleEditPlugin colourPlugin;
if (wasColored) {
colourPlugin = new RemoveOverlayColors();
} else {
colourPlugin = new ColorTrusses(state);
}
PluginExecution.withPlugin(colourPlugin).interactively(true).executeLater(graph);
}
use of au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin in project constellation by constellation-app.
the class MiscNGTest method testCreateTransactionToNonexistentDestinationInPluginTest.
@Test
public void testCreateTransactionToNonexistentDestinationInPluginTest() {
try {
final DualGraph graph = new DualGraph(null);
graph.setUndoManager(new UndoRedo.Manager());
PluginExecution.withPlugin(new SimpleEditPlugin() {
@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
for (int i = 0; i < 10; i++) {
final String s = String.format("x%d", i);
wg.addAttribute(GraphElementType.VERTEX, ObjectAttributeDescription.ATTRIBUTE_NAME, s, s, 99, null);
wg.addAttribute(GraphElementType.TRANSACTION, FloatAttributeDescription.ATTRIBUTE_NAME, s, s, 99, null);
}
int vx = 0;
for (int i = 0; i < 100; i++) {
vx = wg.addVertex();
}
final int tx = wg.addTransaction(vx, vx + 1, true);
Assert.fail("Shouldn't get here, wg.addTransaction() should fail.");
System.out.printf("New transaction: %d\n", tx);
}
@Override
public String getName() {
return "Build graph + tx failure test";
}
}).executeNow(graph);
} catch (InterruptedException ex) {
Assert.fail("Nothing was interrupted.");
} catch (PluginException ex) {
Assert.fail("There shouldn't be a plugin exception.");
} catch (RuntimeException ex) {
final boolean containsIllegalArgumentException = ex.getLocalizedMessage().contains("Attempt to create transaction to destination vertex that does not exist");
Assert.assertTrue(containsIllegalArgumentException);
}
}
use of au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin in project constellation by constellation-app.
the class LayersDualGraphSyncNGTest method dynamicLayerChangeTest.
@Test
public void dynamicLayerChangeTest() throws InterruptedException, PluginException {
// Check Vertex set correctly
ReadableGraph readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getIntValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getIntValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getIntValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
WritableGraph writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(bitmaskAttributeId, 0, 0b10);
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(bitmaskAttributeId, 0), 0b10);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId1), 1.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId2), 0.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
// change an attribute to trigger switching of graph object within dual graph
PluginExecution.withPlugin(new SimpleEditPlugin("Test: change attribute value") {
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final int maxTransactionsId = VisualConcept.GraphAttribute.MAX_TRANSACTIONS.ensure(graph);
graph.setLongValue(maxTransactionsId, 0, 9);
}
}).executeNow(graph);
// Check Vertex set correctly on second graph of dualgraph
readableGraph = graph.getReadableGraph();
try {
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId1), 1.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId2), 0.0f);
assertEquals((long) readableGraph.getObjectValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getObjectValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 1.0f);
} finally {
writableGraph.commit();
}
// PluginExecution.withPlugin(new UpdateLayerSelectionPlugin(queries, 1)).executeNow(graph);
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b101);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b101);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 3);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b101);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 1.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 3);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b101);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 1.0f);
} finally {
readableGraph.release();
}
writableGraph = graph.getWritableGraph("", true);
try {
writableGraph.setLongValue(layerMaskV, vxId1, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId1, 0.0f);
writableGraph.setLongValue(layerMaskV, vxId2, 0b111);
writableGraph.setFloatValue(layerVisibilityV, vxId2, 1.0f);
writableGraph.setLongValue(layerMaskV, vxId3, 1);
writableGraph.setFloatValue(layerVisibilityV, vxId3, 0.0f);
} finally {
writableGraph.commit();
}
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b111);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
PluginExecution.withPlugin(new SimpleEditPlugin("Test: change attribute value") {
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final int maxTransactionsId = VisualConcept.GraphAttribute.MAX_TRANSACTIONS.ensure(graph);
graph.setIntValue(maxTransactionsId, 0, 9);
}
}).executeNow(graph);
readableGraph = graph.getReadableGraph();
try {
assertEquals(readableGraph.getLongValue(layerMaskV, vxId1), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId1), 0.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId2), 0b111);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId2), 1.0f);
assertEquals(readableGraph.getLongValue(layerMaskV, vxId3), 1);
assertEquals(readableGraph.getFloatValue(layerVisibilityV, vxId3), 0.0f);
} finally {
readableGraph.release();
}
}
Aggregations