Search in sources :

Example 1 with SimpleEditPlugin

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);
}
Also used : SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin)

Example 2 with SimpleEditPlugin

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);
    }
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) UndoRedo(org.openide.awt.UndoRedo) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 3 with SimpleEditPlugin

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();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Aggregations

SimpleEditPlugin (au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin)3 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)2 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)2 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)2 Test (org.testng.annotations.Test)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)1 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)1 UndoRedo (org.openide.awt.UndoRedo)1