Search in sources :

Example 61 with GraphAttribute

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

the class TableNGTest method createColumnIndexPart.

@Test
public void createColumnIndexPart() {
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    // Build the graph that the columns will be extracted from. There are two
    // verticies and one transaction. When new columns are created for verticies,
    // a source version and a destination version is created. Trasactions attributes
    // have a 1:1 relationship with the columns created.
    when(readableGraph.getAttributeCount(GraphElementType.VERTEX)).thenReturn(2);
    when(readableGraph.getAttributeCount(GraphElementType.TRANSACTION)).thenReturn(1);
    when(readableGraph.getAttribute(GraphElementType.VERTEX, 0)).thenReturn(101);
    when(readableGraph.getAttributeName(101)).thenReturn("COLUMN_A");
    final Attribute attribute1 = new GraphAttribute(readableGraph, 101);
    final TableColumn<ObservableList<String>, String> column1 = mock(TableColumn.class);
    when(readableGraph.getAttribute(GraphElementType.VERTEX, 1)).thenReturn(102);
    when(readableGraph.getAttributeName(102)).thenReturn("COLUMN_B");
    final Attribute attribute2 = new GraphAttribute(readableGraph, 102);
    final TableColumn<ObservableList<String>, String> column2 = mock(TableColumn.class);
    when(readableGraph.getAttribute(GraphElementType.TRANSACTION, 0)).thenReturn(103);
    when(readableGraph.getAttributeName(103)).thenReturn("COLUMN_C");
    final Attribute attribute3 = new GraphAttribute(readableGraph, 103);
    final TableColumn<ObservableList<String>, String> column3 = mock(TableColumn.class);
    // This is a reference to the old column index
    final Map<String, TableColumn<ObservableList<String>, String>> columnReferenceMap = Map.of("source.COLUMN_A", column1, "destination.COLUMN_B", column2, "transaction.COLUMN_C", column3);
    // When the column being added is not in the old column index reference a new one
    // needs to be created
    final TableColumn<ObservableList<String>, String> newColumn1 = mock(TableColumn.class);
    final TableColumn<ObservableList<String>, String> newColumn2 = mock(TableColumn.class);
    when(table.createColumn("source.COLUMN_B")).thenReturn(newColumn1);
    when(table.createColumn("destination.COLUMN_A")).thenReturn(newColumn2);
    // Create the expected outputs for source, destination and trasaction column creations
    final CopyOnWriteArrayList<Column> sourceColumnIndex = new CopyOnWriteArrayList<>();
    sourceColumnIndex.add(new Column("source.", attribute1, column1));
    sourceColumnIndex.add(new Column("source.", attribute2, newColumn1));
    final CopyOnWriteArrayList<Column> destinationColumnIndex = new CopyOnWriteArrayList<>();
    destinationColumnIndex.add(new Column("destination.", attribute1, newColumn2));
    destinationColumnIndex.add(new Column("destination.", attribute2, column2));
    final CopyOnWriteArrayList<Column> transactionColumnIndex = new CopyOnWriteArrayList<>();
    transactionColumnIndex.add(new Column("transaction.", attribute3, column3));
    assertEquals(sourceColumnIndex, table.createColumnIndexPart(readableGraph, GraphElementType.VERTEX, "source.", columnReferenceMap));
    assertEquals(destinationColumnIndex, table.createColumnIndexPart(readableGraph, GraphElementType.VERTEX, "destination.", columnReferenceMap));
    assertEquals(transactionColumnIndex, table.createColumnIndexPart(readableGraph, GraphElementType.TRANSACTION, "transaction.", columnReferenceMap));
}
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) ObservableList(javafx.collections.ObservableList) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) TableColumn(javafx.scene.control.TableColumn) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) TableColumn(javafx.scene.control.TableColumn) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Example 62 with GraphAttribute

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

the class ColumnVisibilityContextMenu method init.

/**
 * Initializes the column visibility context menu. Until this method is
 * called, all menu UI components will be null.
 */
public void init() {
    contextMenu = new ContextMenu();
    showAllColumnsMenu = createCustomMenu(ALL_COLUMNS, e -> {
        getActiveTableReference().updateVisibleColumns(getTableViewTopComponent().getCurrentGraph(), getTableViewTopComponent().getCurrentState(), extractColumnAttributes(table.getColumnIndex()), UpdateMethod.REPLACE);
        e.consume();
    });
    showDefaultColumnsMenu = createCustomMenu(DEFAULT_COLUMNS, e -> {
        getActiveTableReference().updateVisibleColumns(getTableViewTopComponent().getCurrentGraph(), getTableViewTopComponent().getCurrentState(), extractColumnAttributes(table.getColumnIndex().stream().filter(column -> Character.isUpperCase(column.getAttribute().getName().charAt(0))).collect(Collectors.toList())), UpdateMethod.REPLACE);
        e.consume();
    });
    showPrimaryColumnsMenu = createCustomMenu(KEY_COLUMNS, e -> {
        if (getTableViewTopComponent().getCurrentGraph() != null) {
            final Set<GraphAttribute> keyAttributes = new HashSet<>();
            final ReadableGraph readableGraph = getTableViewTopComponent().getCurrentGraph().getReadableGraph();
            try {
                final int[] vertexKeys = readableGraph.getPrimaryKey(GraphElementType.VERTEX);
                for (final int vertexKey : vertexKeys) {
                    keyAttributes.add(new GraphAttribute(readableGraph, vertexKey));
                }
                final int[] transactionKeys = readableGraph.getPrimaryKey(GraphElementType.TRANSACTION);
                for (final int transactionKey : transactionKeys) {
                    keyAttributes.add(new GraphAttribute(readableGraph, transactionKey));
                }
            } finally {
                readableGraph.release();
            }
            getActiveTableReference().updateVisibleColumns(getTableViewTopComponent().getCurrentGraph(), getTableViewTopComponent().getCurrentState(), extractColumnAttributes(table.getColumnIndex().stream().filter(column -> keyAttributes.stream().anyMatch(keyAttribute -> keyAttribute.equals(column.getAttribute()))).collect(Collectors.toList())), UpdateMethod.REPLACE);
            e.consume();
        }
    });
    hideAllColumnsMenu = createCustomMenu(NO_COLUMNS, e -> {
        table.getColumnIndex().forEach(column -> column.getTableColumn().setVisible(false));
        getActiveTableReference().updateVisibleColumns(getTableViewTopComponent().getCurrentGraph(), getTableViewTopComponent().getCurrentState(), Collections.emptyList(), UpdateMethod.REPLACE);
        e.consume();
    });
    contextMenu.getItems().addAll(showAllColumnsMenu, showDefaultColumnsMenu, showPrimaryColumnsMenu, hideAllColumnsMenu, new SeparatorMenuItem());
    // This next section basically creates three menus. One for each element type, vertex vource,
    // vertex destination and transactions. All columns are attributes of one of these entities.
    // The columns are split and added to their respective menus. Each menu also gets a filter
    // text box.
    final MenuButton sourceVertexColumnsButton = createMenuButton(SPLIT_SOURCE, SPLIT_SOURCE_ICON);
    final MenuButton destinationVertexColumnsButton = createMenuButton(SPLIT_DESTINATION, SPLIT_DESTINATION_ICON);
    final MenuButton transactionColumnsButton = createMenuButton(SPLIT_TRANSACTION, SPLIT_TRANSACTION_ICON);
    final List<CustomMenuItem> columnCheckboxesSource = new ArrayList<>();
    final List<CustomMenuItem> columnCheckboxesDestination = new ArrayList<>();
    final List<CustomMenuItem> columnCheckboxesTransaction = new ArrayList<>();
    // Create the filter items and add them to the button
    final CustomMenuItem columnFilterSource = createColumnFilterMenu(columnCheckboxesSource);
    final CustomMenuItem columnFilterDestination = createColumnFilterMenu(columnCheckboxesDestination);
    final CustomMenuItem columnFilterTransaction = createColumnFilterMenu(columnCheckboxesTransaction);
    sourceVertexColumnsButton.getItems().add(columnFilterSource);
    destinationVertexColumnsButton.getItems().add(columnFilterDestination);
    transactionColumnsButton.getItems().add(columnFilterTransaction);
    // Generate check boxes for each column and separate them into their groups
    table.getColumnIndex().forEach(columnTuple -> {
        final String columnHeading = columnTuple.getAttributeNamePrefix();
        if (columnHeading != null) {
            switch(columnHeading) {
                case GraphRecordStoreUtilities.SOURCE:
                    columnCheckboxesSource.add(createColumnVisibilityMenu(columnTuple));
                    break;
                case GraphRecordStoreUtilities.DESTINATION:
                    columnCheckboxesDestination.add(createColumnVisibilityMenu(columnTuple));
                    break;
                case GraphRecordStoreUtilities.TRANSACTION:
                    columnCheckboxesTransaction.add(createColumnVisibilityMenu(columnTuple));
                    break;
                default:
                    break;
            }
        }
    });
    // Add the check boxes to the button (which already have the filter added)
    // and add the button to a new menu which can be added to the context menu
    sourceVertexColumnsMenu = createDynamicColumnMenu(sourceVertexColumnsButton, columnCheckboxesSource);
    destinationVertexColumnMenu = createDynamicColumnMenu(destinationVertexColumnsButton, columnCheckboxesDestination);
    tansactionColumnMenu = createDynamicColumnMenu(transactionColumnsButton, columnCheckboxesTransaction);
    Optional.ofNullable(sourceVertexColumnsMenu).ifPresent(menu -> contextMenu.getItems().add(menu));
    Optional.ofNullable(destinationVertexColumnMenu).ifPresent(menu -> contextMenu.getItems().add(menu));
    Optional.ofNullable(tansactionColumnMenu).ifPresent(menu -> contextMenu.getItems().add(menu));
}
Also used : EventHandler(javafx.event.EventHandler) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) UpdateMethod(au.gov.asd.tac.constellation.views.tableview.api.UpdateMethod) ActiveTableReference(au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference) Side(javafx.geometry.Side) ArrayList(java.util.ArrayList) CustomMenuItem(javafx.scene.control.CustomMenuItem) HashSet(java.util.HashSet) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) ContextMenu(javafx.scene.control.ContextMenu) Attribute(au.gov.asd.tac.constellation.graph.Attribute) UserInterfaceIconProvider(au.gov.asd.tac.constellation.utilities.icon.UserInterfaceIconProvider) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) TableViewTopComponent(au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) CheckBox(javafx.scene.control.CheckBox) Set(java.util.Set) ThreeTuple(au.gov.asd.tac.constellation.utilities.datastructure.ThreeTuple) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) KeyEvent(javafx.scene.input.KeyEvent) Collectors(java.util.stream.Collectors) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) ActionEvent(javafx.event.ActionEvent) ImageView(javafx.scene.image.ImageView) MenuButton(javafx.scene.control.MenuButton) Optional(java.util.Optional) Collections(java.util.Collections) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) HashSet(java.util.HashSet) Set(java.util.Set) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) MenuButton(javafx.scene.control.MenuButton) ContextMenu(javafx.scene.control.ContextMenu) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) CustomMenuItem(javafx.scene.control.CustomMenuItem)

Example 63 with GraphAttribute

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

the class Table method createColumnIndexPart.

/**
 * For the specified element type (vertex or transaction), iterates through
 * that element types attributes in the graph and generates columns for each
 * one.
 * <p/>
 * The column name will be the attribute name prefixed by the passed
 * {@code attributeNamePrefix} parameter. This parameter will be one of
 * "source.", "destination." or "transaction.".
 * <p/>
 * The column reference map contains previously generated columns and is
 * used as a reference so that new column objects are not created
 * needlessly.
 *
 * @param readableGraph the graph to extract the attributes from
 * @param elementType the type of elements that the attributes will be
 * extracted from, {@link GraphElementType#VERTEX} or
 * {@link GraphElementType#TRANSACTION}
 * @param attributeNamePrefix the string that will prefix the attribute name
 * in the column name, will be one of "source.", "destination." or
 * "transaction."
 * @param columnReferenceMap a map of existing columns that can be used
 * instead of creating new ones if the column names match up
 */
protected List<Column> createColumnIndexPart(final ReadableGraph readableGraph, final GraphElementType elementType, final String attributeNamePrefix, final Map<String, TableColumn<ObservableList<String>, String>> columnReferenceMap) {
    final List<Column> tmpColumnIndex = new CopyOnWriteArrayList<>();
    final int attributeCount = readableGraph.getAttributeCount(elementType);
    IntStream.range(0, attributeCount).forEach(attributePosition -> {
        final int attributeId = readableGraph.getAttribute(elementType, attributePosition);
        final String attributeName = attributeNamePrefix + readableGraph.getAttributeName(attributeId);
        final TableColumn<ObservableList<String>, String> column = columnReferenceMap.containsKey(attributeName) ? columnReferenceMap.get(attributeName) : createColumn(attributeName);
        tmpColumnIndex.add(new Column(attributeNamePrefix, new GraphAttribute(readableGraph, attributeId), column));
    });
    return tmpColumnIndex;
}
Also used : TableColumn(javafx.scene.control.TableColumn) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) ObservableList(javafx.collections.ObservableList) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 64 with GraphAttribute

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

the class TableViewStateIoProvider method readObject.

@Override
public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, final ImmutableObjectCache cache) throws IOException {
    if (!jnode.isNull() && !jnode.isEmpty()) {
        final boolean selectedOnly = jnode.get("selectedOnly").asBoolean();
        final GraphElementType elementType = GraphElementType.valueOf(jnode.get("elementType").asText());
        final List<Tuple<String, Attribute>> transactionColumnAttributes = new ArrayList<>();
        if (jnode.get(TRANSACTION_COLUMN_ATTRIBUTES) != null) {
            final Iterator<JsonNode> attributeIterator = jnode.get(TRANSACTION_COLUMN_ATTRIBUTES).iterator();
            while (attributeIterator.hasNext()) {
                final JsonNode attributeNode = attributeIterator.next();
                final String attributePrefix = attributeNode.get(ATTRIBUTE_PREFIX).asText();
                final Attribute attribute = new GraphAttribute(graph, graph.getAttribute(GraphElementType.valueOf(attributeNode.get(ATTRIBUTE_ELEMENT_TYPE).asText()), attributeNode.get(ATTRIBUTE_NAME).asText()));
                transactionColumnAttributes.add(Tuple.create(attributePrefix, attribute));
            }
        }
        final List<Tuple<String, Attribute>> vertexColumnAttributes = new ArrayList<>();
        if (jnode.get(VERTEX_COLUMN_ATTRIBUTES) != null) {
            final Iterator<JsonNode> attributeIterator = jnode.get(VERTEX_COLUMN_ATTRIBUTES).iterator();
            while (attributeIterator.hasNext()) {
                final JsonNode attributeNode = attributeIterator.next();
                final String attributePrefix = attributeNode.get(ATTRIBUTE_PREFIX).asText();
                final Attribute attribute = new GraphAttribute(graph, graph.getAttribute(GraphElementType.valueOf(attributeNode.get(ATTRIBUTE_ELEMENT_TYPE).asText()), attributeNode.get(ATTRIBUTE_NAME).asText()));
                vertexColumnAttributes.add(Tuple.create(attributePrefix, attribute));
            }
        }
        final TableViewState state = new TableViewState();
        state.setSelectedOnly(selectedOnly);
        state.setElementType(elementType);
        state.setTransactionColumnAttributes(transactionColumnAttributes);
        state.setVertexColumnAttributes(vertexColumnAttributes);
        graph.setObjectValue(attributeId, elementId, state);
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

Example 65 with GraphAttribute

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

the class GraphAttributeParameterValue method setObjectValue.

@Override
public boolean setObjectValue(final Object o) {
    if (o instanceof GraphAttribute) {
        final GraphAttribute objectAttribute = (GraphAttribute) o;
        final boolean equal = Objects.equals(objectAttribute, attribute);
        if (!equal) {
            attribute = objectAttribute;
        }
        return equal;
    }
    return false;
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

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