Search in sources :

Example 11 with GraphLabel

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.

the class SaveGraphUtilities method makeGraphInteractable.

private static void makeGraphInteractable(final GraphWriteMethods graph) {
    // add attributes required for interaction
    // graph
    VisualConcept.GraphAttribute.CAMERA.ensure(graph);
    VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(graph);
    VisualConcept.GraphAttribute.DRAWING_MODE.ensure(graph);
    // vertex
    VisualConcept.VertexAttribute.X.ensure(graph);
    VisualConcept.VertexAttribute.Y.ensure(graph);
    VisualConcept.VertexAttribute.Z.ensure(graph);
    VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    // transaction
    VisualConcept.TransactionAttribute.SELECTED.ensure(graph);
    final int bottomLabelsAttribute = VisualConcept.GraphAttribute.BOTTOM_LABELS.ensure(graph);
    final GraphLabels newBottomLabels = new GraphLabels(Arrays.asList(new GraphLabel(VisualConcept.VertexAttribute.LABEL.getName(), ConstellationColor.AZURE)));
    graph.setObjectValue(bottomLabelsAttribute, 0, newBottomLabels);
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 12 with GraphLabel

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.

the class TransactionGraphLabelsAttributeInteractionNGTest method testGetDisplayText.

/**
 * Test of getDisplayText method, of class TransactionGraphLabelsAttributeInteraction.
 */
@Test
public void testGetDisplayText() {
    System.out.println("getDisplayText");
    final TransactionGraphLabelsAttributeInteraction instance = new TransactionGraphLabelsAttributeInteraction();
    final String nullResult = instance.getDisplayText(null);
    assertNull(nullResult);
    final GraphLabels emptyLabels = new GraphLabels(Collections.emptyList());
    final String emptyGraphLabelsResult = instance.getDisplayText(emptyLabels);
    assertEquals(emptyGraphLabelsResult, "");
    final GraphLabel testLabel1 = new GraphLabel("test1", ConstellationColor.BANANA, 5F);
    final GraphLabel testLabel2 = new GraphLabel("test2", ConstellationColor.getColorValue(0.1F, 0.2F, 0.3F, 1F), 7F);
    final GraphLabels labels = new GraphLabels(Arrays.asList(testLabel1, testLabel2));
    final String graphLabelsResult = instance.getDisplayText(labels);
    assertEquals(graphLabelsResult, "test1: (Banana), test2: (#19334c)");
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel) Test(org.testng.annotations.Test)

Example 13 with GraphLabel

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.

the class VisualSchemaV4UpdateProvider method schemaUpdate.

@Override
protected void schemaUpdate(StoreGraph graph) {
    boolean updateVertexKeys = false;
    // update vertex identifier attribute
    if (VisualConcept.VertexAttribute.IDENTIFIER.get(graph) == Graph.NOT_FOUND) {
        updateVertexKeys = true;
    }
    // update vertex label attribute
    final int oldVertexLabelAttributeId = graph.getAttribute(GraphElementType.VERTEX, LABEL_ATTRIBUTE_NAME);
    if (oldVertexLabelAttributeId != GraphConstants.NOT_FOUND) {
        graph.setPrimaryKey(GraphElementType.VERTEX);
        final int newVertexLabelAttributeId = VisualConcept.VertexAttribute.LABEL.ensure(graph);
        final int vertexIdentiferAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
        for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
            final int vertexId = graph.getVertex(vertexPosition);
            final String labelValue = graph.getStringValue(oldVertexLabelAttributeId, vertexId);
            graph.setStringValue(newVertexLabelAttributeId, vertexId, labelValue);
            if (graph.getStringValue(vertexIdentiferAttributeId, vertexId) == null) {
                graph.setStringValue(vertexIdentiferAttributeId, vertexId, labelValue);
            }
        }
        graph.removeAttribute(oldVertexLabelAttributeId);
        updateVertexKeys = true;
    }
    // update vertex keys and complete vertices
    if (updateVertexKeys) {
        final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.VERTEX);
        final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
        graph.setPrimaryKey(GraphElementType.VERTEX, keyAttributeIds);
    }
    // update vertex labels
    final int vertexBottomLabelsAttributeId = VisualConcept.GraphAttribute.BOTTOM_LABELS.get(graph);
    if (vertexBottomLabelsAttributeId != GraphConstants.NOT_FOUND) {
        final GraphLabel label = new GraphLabel(VisualConcept.VertexAttribute.LABEL.getName(), graph.getSchema().getFactory().getVertexLabelColor());
        graph.setObjectValue(vertexBottomLabelsAttributeId, 0, new GraphLabels(Arrays.asList(label)));
    }
    boolean updateTransactionKeys = false;
    // update transaction identifier attribute
    if (VisualConcept.TransactionAttribute.IDENTIFIER.get(graph) == Graph.NOT_FOUND) {
        updateTransactionKeys = true;
    }
    final int oldTransactionUniqueIdAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, UNIQUE_ID_ATTRIBUTE_NAME);
    if (oldTransactionUniqueIdAttributeId != GraphConstants.NOT_FOUND) {
        graph.setPrimaryKey(GraphElementType.TRANSACTION);
        final int newTransactionIdentifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
        for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
            final int transactionId = graph.getTransaction(transactionPosition);
            final String uniqueIdValue = graph.getStringValue(oldTransactionUniqueIdAttributeId, transactionId);
            graph.setStringValue(newTransactionIdentifierAttributeId, transactionId, uniqueIdValue);
        }
        graph.removeAttribute(oldTransactionUniqueIdAttributeId);
        updateTransactionKeys = true;
    }
    // update transaction label attribute
    final int oldTransactionLabelAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, LABEL_ATTRIBUTE_NAME);
    if (oldTransactionLabelAttributeId != GraphConstants.NOT_FOUND) {
        graph.setPrimaryKey(GraphElementType.TRANSACTION);
        final int newTransactionLabelAttributeId = VisualConcept.TransactionAttribute.LABEL.ensure(graph);
        final int transactionIdentiferAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
        for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
            final int transactionId = graph.getTransaction(transactionPosition);
            final String labelValue = graph.getStringValue(oldTransactionLabelAttributeId, transactionId);
            graph.setStringValue(newTransactionLabelAttributeId, transactionId, labelValue);
            if (graph.getStringValue(transactionIdentiferAttributeId, transactionId) == null) {
                graph.setStringValue(transactionIdentiferAttributeId, transactionId, labelValue);
            }
        }
        graph.removeAttribute(oldTransactionLabelAttributeId);
        updateTransactionKeys = true;
    }
    // update transaction keys and complete transactions
    if (updateTransactionKeys) {
        final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.TRANSACTION);
        final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
        graph.setPrimaryKey(GraphElementType.TRANSACTION, keyAttributeIds);
    }
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) UpdateProvider(au.gov.asd.tac.constellation.graph.versioning.UpdateProvider) Arrays(java.util.Arrays) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) SchemaUpdateProvider(au.gov.asd.tac.constellation.graph.versioning.SchemaUpdateProvider) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) VisualSchemaFactory(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaFactory) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) GraphConstants(au.gov.asd.tac.constellation.graph.GraphConstants) Graph(au.gov.asd.tac.constellation.graph.Graph) List(java.util.List) SchemaFactoryUtilities(au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel) ServiceProvider(org.openide.util.lookup.ServiceProvider) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 14 with GraphLabel

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.

the class NodeGraphLabelsV1AttributeUpdateProvider method updateAttributeValue.

@Override
public Object updateAttributeValue(final Object value) {
    if (value == null) {
        return null;
    }
    final ElementGraphLabelsV0 v0 = (ElementGraphLabelsV0) value;
    final List<ElementGraphLabelV0> labelsV0 = v0.getLabels();
    final List<GraphLabel> labels = new ArrayList<>();
    for (final ElementGraphLabelV0 labelV0 : labelsV0) {
        final GraphLabel label = new GraphLabel(labelV0.getAttributeName(), labelV0.getColor(), labelV0.getSize());
        labels.add(label);
    }
    return new GraphLabels(labels);
}
Also used : ArrayList(java.util.ArrayList) GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 15 with GraphLabel

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.

the class TransactionGraphLabelsV1AttributeUpdateProvider method updateAttributeValue.

@Override
public Object updateAttributeValue(final Object value) {
    if (value == null) {
        return null;
    }
    final ElementGraphLabelsV0 v0 = (ElementGraphLabelsV0) value;
    final List<ElementGraphLabelV0> labelsV0 = v0.getLabels();
    final List<GraphLabel> labels = new ArrayList<>();
    for (final ElementGraphLabelV0 labelV0 : labelsV0) {
        final GraphLabel label = new GraphLabel(labelV0.getAttributeName(), labelV0.getColor(), labelV0.getSize());
        labels.add(label);
    }
    return new GraphLabels(labels);
}
Also used : ArrayList(java.util.ArrayList) GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Aggregations

GraphLabel (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)16 GraphLabels (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels)16 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)4 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)2 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)2 Arrays (java.util.Arrays)2 List (java.util.List)2 ServiceProvider (org.openide.util.lookup.ServiceProvider)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphConstants (au.gov.asd.tac.constellation.graph.GraphConstants)1 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 BooleanAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.BooleanAttributeDescription)1 FloatAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.FloatAttributeDescription)1 StringAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.StringAttributeDescription)1 InteractiveGraphPluginRegistry (au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry)1 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)1 SchemaFactoryUtilities (au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities)1