Search in sources :

Example 21 with GraphElementType

use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.

the class FloatCriteriaPanelNGTest method testGetType.

/**
 * Test of getType method, of class FloatCriteriaPanel.
 */
@Test
public void testGetType() {
    System.out.println("getType");
    setupGraph();
    AdvancedFindTab parentComponent = spy(advancedTab);
    final GraphElementType type = GraphElementType.VERTEX;
    FloatCriteriaPanel floatCriteriaPanel = new FloatCriteriaPanel(parentComponent, "x", type);
    assertEquals(floatCriteriaPanel.getType(), FloatAttributeDescription.ATTRIBUTE_NAME);
}
Also used : AdvancedFindTab(au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Test(org.testng.annotations.Test)

Example 22 with GraphElementType

use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.

the class StringCriteriaPanelNGTest method testGetSearchFieldText.

/**
 * Test of getSearchFieldText method, of class StringCriteriaPanel.
 */
@Test
public void testGetSearchFieldText() {
    System.out.println("getSearchFieldText");
    setupGraph();
    AdvancedFindTab parentComponent = spy(advancedTab);
    final GraphElementType type = GraphElementType.VERTEX;
    StringCriteriaPanel stringCriteriaPanel = new StringCriteriaPanel(parentComponent, "Identifier", type);
    stringCriteriaPanel.getFilterChoiceBox().getSelectionModel().select("Is");
    stringCriteriaPanel.setSearchFieldText("test");
    assertEquals(stringCriteriaPanel.getSearchFieldText(), "test");
}
Also used : AdvancedFindTab(au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Test(org.testng.annotations.Test)

Example 23 with GraphElementType

use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.

the class StringCriteriaPanelNGTest method testGetType.

/**
 * Test of getType method, of class StringCriteriaPanel.
 */
@Test
public void testGetType() {
    System.out.println("getType");
    setupGraph();
    AdvancedFindTab parentComponent = spy(advancedTab);
    final GraphElementType type = GraphElementType.VERTEX;
    StringCriteriaPanel stringCriteriaPanel = new StringCriteriaPanel(parentComponent, "Identifier", type);
    assertEquals(stringCriteriaPanel.getType(), StringAttributeDescription.ATTRIBUTE_NAME);
}
Also used : AdvancedFindTab(au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Test(org.testng.annotations.Test)

Example 24 with GraphElementType

use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.

the class CopyGraphUtilities method copyGraphToGraph.

/**
 * Adapted from CopySelectedElementsPlugin.makeGraph
 *
 * @param original - the Graph to copy elements from
 * @param graph - the Graph to copy elements to
 * @param copyAll - whether to copy all elements or just the selected ones
 */
public static void copyGraphToGraph(final GraphReadMethods original, final GraphWriteMethods graph, final boolean copyAll) {
    final int vertexSelected = original.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.SELECTED.getName());
    final int transactionSelected = original.getAttribute(GraphElementType.TRANSACTION, VisualConcept.TransactionAttribute.SELECTED.getName());
    final int[] attributeTranslation = new int[original.getAttributeCapacity()];
    // Copy the attributes.
    for (final GraphElementType type : GraphElementType.values()) {
        final int attributeCount = original.getAttributeCount(type);
        for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
            int originalAttributeId = original.getAttribute(type, attributePosition);
            final Attribute attribute = new GraphAttribute(original, originalAttributeId);
            int newAttributeId = graph.getAttribute(type, attribute.getName());
            if (newAttributeId == Graph.NOT_FOUND) {
                newAttributeId = graph.addAttribute(type, attribute.getAttributeType(), attribute.getName(), attribute.getDescription(), attribute.getDefaultValue(), null);
            }
            attributeTranslation[originalAttributeId] = newAttributeId;
            if (type == GraphElementType.GRAPH) {
                graph.setObjectValue(newAttributeId, 0, original.getObjectValue(originalAttributeId, 0));
            }
        }
    }
    // Copy the vertices.
    final int[] vertexTranslation = new int[original.getVertexCapacity()];
    for (int position = 0; position < original.getVertexCount(); position++) {
        final int originalVertex = original.getVertex(position);
        if (copyAll || vertexSelected == Graph.NOT_FOUND || original.getBooleanValue(vertexSelected, originalVertex)) {
            final int newVertex = graph.addVertex();
            vertexTranslation[originalVertex] = newVertex;
            for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.VERTEX); attributePosition++) {
                final int originalAttributeId = original.getAttribute(GraphElementType.VERTEX, attributePosition);
                final int newAttributeId = attributeTranslation[originalAttributeId];
                graph.setObjectValue(newAttributeId, newVertex, original.getObjectValue(originalAttributeId, originalVertex));
            }
        }
    }
    // Copy the transactions.
    final int[] edgeTranslation = new int[original.getEdgeCapacity()];
    final int[] linkTranslation = new int[original.getLinkCapacity()];
    for (int position = 0; position < original.getTransactionCount(); position++) {
        final int originalTransaction = original.getTransaction(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalTransaction)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getTransactionSourceVertex(originalTransaction)) || !original.getBooleanValue(vertexSelected, original.getTransactionDestinationVertex(originalTransaction)))))) {
            continue;
        }
        final int sourceVertex = vertexTranslation[original.getTransactionSourceVertex(originalTransaction)];
        final int destinationVertex = vertexTranslation[original.getTransactionDestinationVertex(originalTransaction)];
        final boolean directed = original.getTransactionDirection(originalTransaction) < 2;
        final int newTransaction = graph.addTransaction(sourceVertex, destinationVertex, directed);
        // add the edge translations
        final int originalEdge = original.getTransactionEdge(originalTransaction);
        final int newEdge = graph.getTransactionEdge(newTransaction);
        edgeTranslation[originalEdge] = newEdge;
        // add the link translations
        final int originalLink = original.getTransactionLink(originalTransaction);
        final int newLink = graph.getTransactionLink(newTransaction);
        linkTranslation[originalLink] = newLink;
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.TRANSACTION); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.TRANSACTION, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, newTransaction, original.getObjectValue(originalAttributeId, originalTransaction));
        }
    }
    // Copy the edges
    for (int position = 0; position < original.getEdgeCount(); position++) {
        final int originalEdge = original.getEdge(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalEdge)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getEdgeSourceVertex(originalEdge)) || !original.getBooleanValue(vertexSelected, original.getEdgeDestinationVertex(originalEdge)))))) {
            continue;
        }
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.EDGE); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.EDGE, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, edgeTranslation[originalEdge], original.getObjectValue(originalAttributeId, originalEdge));
        }
    }
    // Copy the links
    for (int position = 0; position < original.getLinkCount(); position++) {
        final int originalLink = original.getLink(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalLink)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getEdgeSourceVertex(originalLink)) || !original.getBooleanValue(vertexSelected, original.getEdgeDestinationVertex(originalLink)))))) {
            continue;
        }
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.LINK); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.LINK, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, linkTranslation[originalLink], original.getObjectValue(originalAttributeId, originalLink));
        }
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Example 25 with GraphElementType

use of au.gov.asd.tac.constellation.graph.GraphElementType in project constellation by constellation-app.

the class StoreGraphRecordStore method set.

/**
 * Sets a key-value pair on the RecordStore.
 *
 * @param key must start with "source.", "transaction." or "destination."
 * @param value the value to associate with the key.
 */
@Override
public void set(String key, String value) {
    int dividerPosition = key.indexOf('.');
    int typeStartPosition = key.indexOf('<');
    int typeEndPosition = key.indexOf('>');
    String keyDescriptor = key.substring(0, dividerPosition);
    String keyAttribute;
    String keyType;
    if (typeStartPosition == -1) {
        keyAttribute = key.substring(dividerPosition + 1);
        keyType = "string";
    } else {
        keyAttribute = key.substring(dividerPosition + 1, typeStartPosition);
        keyType = key.substring(typeStartPosition + 1, typeEndPosition);
    }
    int id;
    GraphElementType elementType;
    switch(keyDescriptor) {
        case "source":
            id = currentSourceVertex;
            elementType = GraphElementType.VERTEX;
            break;
        case "destination":
            id = currentDestinationVertex;
            elementType = GraphElementType.VERTEX;
            break;
        case "transaction":
            id = currentTransaction;
            elementType = GraphElementType.TRANSACTION;
            break;
        default:
            throw new RuntimeException("key must start with source, transaction or destination.");
    }
    int attribute = getAttribute(elementType, keyAttribute);
    if (attribute == Graph.NOT_FOUND) {
        attribute = getSchema().getFactory().ensureAttribute(this, elementType, keyAttribute);
        if (attribute == Graph.NOT_FOUND) {
            attribute = addAttribute(elementType, keyType, keyAttribute, "", null, null);
        }
    }
    setStringValue(attribute, id, value);
}
Also used : GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Aggregations

GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)85 Test (org.testng.annotations.Test)34 ArrayList (java.util.ArrayList)28 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)17 Attribute (au.gov.asd.tac.constellation.graph.Attribute)16 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 HashMap (java.util.HashMap)11 AdvancedFindTab (au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab)10 FindCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues)9 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)8 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)8 Graph (au.gov.asd.tac.constellation.graph.Graph)7 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)5 SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)5 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)5 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)5 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)5 AdvancedCriteriaBorderPane (au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)5 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)5 List (java.util.List)5