Search in sources :

Example 26 with GraphAttribute

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

the class ImportController method updateAutoAddedAttributes.

/**
 * Get the attributes that will automatically be added to the attribute
 * list.
 *
 * @param elementType
 * @param attributes
 * @param rg
 */
private void updateAutoAddedAttributes(final GraphElementType elementType, final Map<String, Attribute> attributes, final GraphReadMethods rg, final boolean showSchemaAttributes) {
    attributes.clear();
    // Add attributes from the graph
    int attributeCount = rg.getAttributeCount(elementType);
    for (int i = 0; i < attributeCount; i++) {
        int attributeId = rg.getAttribute(elementType, i);
        Attribute attribute = new GraphAttribute(rg, attributeId);
        attributes.put(attribute.getName(), attribute);
    }
    // Add attributes from the schema
    if (showSchemaAttributes && rg.getSchema() != null) {
        final SchemaFactory factory = rg.getSchema().getFactory();
        for (final SchemaAttribute sattr : factory.getRegisteredAttributes(elementType).values()) {
            final Attribute attribute = new GraphAttribute(elementType, sattr.getAttributeType(), sattr.getName(), sattr.getDescription());
            if (!attributes.containsKey(attribute.getName())) {
                attributes.put(attribute.getName(), attribute);
            }
        }
    }
    // Add pseudo-attributes
    if (elementType == GraphElementType.TRANSACTION) {
        final Attribute attribute = new GraphAttribute(elementType, BooleanAttributeDescription.ATTRIBUTE_NAME, DIRECTED, "Is this transaction directed?");
        attributes.put(attribute.getName(), attribute);
    }
    // Add primary keys
    for (int key : rg.getPrimaryKey(elementType)) {
        keys.add(key);
    }
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 27 with GraphAttribute

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

the class ScatterOptionsPane method refreshOptions.

/**
 * Refresh the state of the ScatterOptionsPane based on the given
 * ScatterPlotState.
 *
 * @param state the ScatterPlotState.
 */
protected void refreshOptions(ScatterPlotState state) {
    if (scatterPlot.getScatterPlot().getCurrentGraph() == null || state == null) {
        return;
    }
    Platform.runLater(() -> {
        isUpdating = true;
        final ObservableList<Attribute> attributes = FXCollections.observableArrayList();
        ReadableGraph readableGraph = scatterPlot.getScatterPlot().getCurrentGraph().getReadableGraph();
        try {
            final int attributeCount = readableGraph.getAttributeCount(state.getElementType());
            for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
                final int attributeId = readableGraph.getAttribute(state.getElementType(), attributePosition);
                final Attribute attribute = new GraphAttribute(readableGraph, attributeId);
                attributes.add(attribute);
            }
        } finally {
            readableGraph.release();
        }
        FXCollections.sort(attributes, (attribute1, attribute2) -> attribute1.getName().compareTo(attribute2.getName()));
        xAttributeComboBox.setItems(attributes);
        yAttributeComboBox.setItems(attributes);
        elementTypeComboBox.getSelectionModel().select(state.getElementType().getShortLabel());
        xAttributeComboBox.getSelectionModel().select(state.getXAttribute());
        yAttributeComboBox.getSelectionModel().select(state.getYAttribute());
        selectedOnlyButton.setSelected(state.isSelectedOnly());
        isUpdating = false;
    });
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 28 with GraphAttribute

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

the class ScatterPlotStateIoProvider method readObject.

@Override
public void readObject(int attributeId, int elementId, JsonNode jnode, GraphWriteMethods graph, Map<Integer, Integer> vertexMap, Map<Integer, Integer> transactionMap, GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException {
    if (!jnode.isNull()) {
        final ScatterPlotState state = new ScatterPlotState();
        GraphElementType elementType = GraphElementType.valueOf(jnode.get("elementType").asText());
        final Attribute xAttribute = "null".equalsIgnoreCase(jnode.get(X_ATTRIBUTE).asText()) ? null : new GraphAttribute(graph, graph.getAttribute(elementType, jnode.get(X_ATTRIBUTE).asText()));
        final Attribute yAttribute = "null".equalsIgnoreCase(jnode.get(Y_ATTRIBUTE).asText()) ? null : new GraphAttribute(graph, graph.getAttribute(elementType, jnode.get(Y_ATTRIBUTE).asText()));
        state.setElementType(elementType);
        state.setXAttribute(xAttribute);
        state.setYAttribute(yAttribute);
        state.setSelectedOnly(jnode.get("selectedOnly").asBoolean());
        graph.setObjectValue(attributeId, elementId, state);
    }
}
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 29 with GraphAttribute

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

the class ColumnNGTest method init.

@Test
public void init() {
    final Column column = new Column();
    assertNull(column.getAttributeNamePrefix());
    assertNull(column.getAttribute());
    assertNull(column.getTableColumn());
    final String prefix = "source.";
    final GraphAttribute attribute = new GraphAttribute(GraphElementType.VERTEX, "string", "COLUMN_A", "Describes all things A's");
    final TableColumn tableColumn = new TableColumn<>("source.COLUMN_A");
    column.setAttributeNamePrefix(prefix);
    column.setAttribute(attribute);
    column.setTableColumn(tableColumn);
    assertSame(prefix, column.getAttributeNamePrefix());
    assertSame(attribute, column.getAttribute());
    assertSame(tableColumn, column.getTableColumn());
}
Also used : TableColumn(javafx.scene.control.TableColumn) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) TableColumn(javafx.scene.control.TableColumn) Test(org.testng.annotations.Test)

Example 30 with GraphAttribute

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

the class TableNGTest method getRowDataForVertex.

@Test
public void getRowDataForVertex() {
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    final Map<Integer, ObservableList<String>> elementIdToRowIndex = new HashMap<>();
    final Map<ObservableList<String>, Integer> rowToElementIdIndex = new HashMap<>();
    doReturn(elementIdToRowIndex).when(activeTableReference).getElementIdToRowIndex();
    doReturn(rowToElementIdIndex).when(activeTableReference).getRowToElementIdIndex();
    final int vertexId = 42;
    // Set up the attributes for each column
    when(readableGraph.getAttribute(GraphElementType.VERTEX, "COLUMN_A")).thenReturn(101);
    when(readableGraph.getAttributeName(101)).thenReturn("COLUMN_A");
    when(readableGraph.getAttributeElementType(101)).thenReturn(GraphElementType.VERTEX);
    when(readableGraph.getAttributeType(101)).thenReturn("string");
    final Object objectValue1 = new Object();
    when(readableGraph.getObjectValue(101, vertexId)).thenReturn(objectValue1);
    final Attribute attribute1 = new GraphAttribute(readableGraph, 101);
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    columnIndex.add(new Column(null, attribute1, null));
    when(table.getColumnIndex()).thenReturn(columnIndex);
    try (final MockedStatic<AbstractAttributeInteraction> attrInteractionMockedStatic = Mockito.mockStatic(AbstractAttributeInteraction.class)) {
        final AbstractAttributeInteraction interaction = mock(AbstractAttributeInteraction.class);
        attrInteractionMockedStatic.when(() -> AbstractAttributeInteraction.getInteraction("string")).thenReturn(interaction);
        when(interaction.getDisplayText(objectValue1)).thenReturn("column1Value");
        assertEquals(FXCollections.observableArrayList("column1Value"), table.getRowDataForVertex(readableGraph, vertexId));
        assertEquals(Map.of(vertexId, FXCollections.observableArrayList("column1Value")), elementIdToRowIndex);
        assertEquals(Map.of(FXCollections.observableArrayList("column1Value"), vertexId), rowToElementIdIndex);
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) HashMap(java.util.HashMap) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ObservableList(javafx.collections.ObservableList) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) TableColumn(javafx.scene.control.TableColumn) AbstractAttributeInteraction(au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Aggregations

GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)65 Attribute (au.gov.asd.tac.constellation.graph.Attribute)45 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)25 ArrayList (java.util.ArrayList)25 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)19 HashMap (java.util.HashMap)16 Test (org.testng.annotations.Test)15 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)10 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)9 Graph (au.gov.asd.tac.constellation.graph.Graph)8 AdvancedFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin)8 FindResult (au.gov.asd.tac.constellation.views.find.advanced.FindResult)8 TopComponent (org.openide.windows.TopComponent)8 TableColumn (javafx.scene.control.TableColumn)6 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 List (java.util.List)5 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)4 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 GraphRecordStoreUtilities (au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities)3