Search in sources :

Example 61 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class Table method updateColumns.

/**
 * Update the columns in the table using the graph and state. This will
 * clear and refresh the column index and then trigger a refresh of the
 * table view, populating from the new column index.
 * <p/>
 * If the table's state has an element type of VERTEX then all the columns
 * will be prefixed with ".source".
 * <p/>
 * If the element type is TRANSACTION then the attributes belonging to
 * transactions will be prefixed with ".transaction". The vertex attributes
 * will also be added as columns in this case. When the state's element type
 * is TRANSACTION the vertex attributes will be prefixed with both ".source"
 * and ".destination" so that it is distinguishable on which end of the
 * transaction those values are present.
 * <p/>
 * Note that column references are reused where possible to ensure certain
 * toolbar/menu operations to work correctly.
 * <p/>
 * The entire method is synchronized so it should be thread safe and keeps
 * the locking logic simpler. Maybe this method could be broken out further.
 *
 * @param graph the graph to retrieve data from.
 * @param state the current table view state.
 */
public void updateColumns(final Graph graph, final TableViewState state) {
    synchronized (TABLE_LOCK) {
        if (graph != null && state != null) {
            if (Platform.isFxApplicationThread()) {
                throw new IllegalStateException(ATTEMPT_PROCESS_JAVAFX);
            }
            if (SwingUtilities.isEventDispatchThread()) {
                throw new IllegalStateException(ATTEMPT_PROCESS_EDT);
            }
            // Clear current columnIndex, but cache the column objects for reuse
            final Map<String, TableColumn<ObservableList<String>, String>> columnReferenceMap = getColumnIndex().stream().collect(Collectors.toMap(column -> column.getTableColumn().getText(), column -> column.getTableColumn(), (e1, e2) -> e1));
            getColumnIndex().clear();
            // Update columnIndex based on graph attributes
            final ReadableGraph readableGraph = graph.getReadableGraph();
            try {
                // Creates "source." columns from vertex attributes
                getColumnIndex().addAll(createColumnIndexPart(readableGraph, GraphElementType.VERTEX, GraphRecordStoreUtilities.SOURCE, columnReferenceMap));
                if (state.getElementType() == GraphElementType.TRANSACTION) {
                    // Creates "transaction." columns from transaction attributes
                    getColumnIndex().addAll(createColumnIndexPart(readableGraph, GraphElementType.TRANSACTION, GraphRecordStoreUtilities.TRANSACTION, columnReferenceMap));
                    // Creates "destination." columns from vertex attributes
                    getColumnIndex().addAll(createColumnIndexPart(readableGraph, GraphElementType.VERTEX, GraphRecordStoreUtilities.DESTINATION, columnReferenceMap));
                }
            } finally {
                readableGraph.release();
            }
            // If there are no visible columns specified, write the key columns to the state
            if (state.getColumnAttributes() == null) {
                openColumnVisibilityMenu();
                return;
            }
            // Sort columns in columnIndex by state, prefix and attribute name
            getColumnIndex().sort(new ColumnIndexSort(state));
            // Style and format columns in columnIndex
            getColumnIndex().forEach(columnTuple -> {
                final TableColumn<ObservableList<String>, String> column = columnTuple.getTableColumn();
                // assign cells to columns
                column.setCellValueFactory(cellData -> {
                    final int cellIndex = tableView.getColumns().indexOf(cellData.getTableColumn());
                    if (cellIndex < cellData.getValue().size()) {
                        return new SimpleStringProperty(cellData.getValue().get(cellIndex));
                    } else {
                        return null;
                    }
                });
                // Assign values and styles to cells
                column.setCellFactory(cellColumn -> new TableCellFactory(cellColumn, this));
            });
            // calculated column changes
            if (!Thread.currentThread().isInterrupted()) {
                // The update columns task holds state between executions. So we need to
                // reset some fields each time before it is run.
                updateColumnsTask.reset(columnReferenceMap, state);
                Platform.runLater(updateColumnsTask);
            }
        }
    }
}
Also used : TableCellFactory(au.gov.asd.tac.constellation.views.tableview.factory.TableCellFactory) IntStream(java.util.stream.IntStream) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) ColumnIndexSort(au.gov.asd.tac.constellation.views.tableview.utilities.ColumnIndexSort) ActiveTableReference(au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) Graph(au.gov.asd.tac.constellation.graph.Graph) SwingUtilities(javax.swing.SwingUtilities) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) Insets(javafx.geometry.Insets) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ListChangeListener(javafx.collections.ListChangeListener) Pair(org.apache.commons.lang3.tuple.Pair) UpdateDataTask(au.gov.asd.tac.constellation.views.tableview.tasks.UpdateDataTask) AbstractAttributeInteraction(au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction) Map(java.util.Map) TableView(javafx.scene.control.TableView) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) MenuItem(javafx.scene.control.MenuItem) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) SelectedOnlySelectionListener(au.gov.asd.tac.constellation.views.tableview.listeners.SelectedOnlySelectionListener) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) Logger(java.util.logging.Logger) ImmutableObjectCache(au.gov.asd.tac.constellation.utilities.datastructure.ImmutableObjectCache) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) UpdateColumnsTask(au.gov.asd.tac.constellation.views.tableview.tasks.UpdateColumnsTask) TableSelectionListener(au.gov.asd.tac.constellation.views.tableview.listeners.TableSelectionListener) TABLE_LOCK(au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent.TABLE_LOCK) TableViewUtilities(au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TableCellFactory(au.gov.asd.tac.constellation.views.tableview.factory.TableCellFactory) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ObservableList(javafx.collections.ObservableList) ColumnIndexSort(au.gov.asd.tac.constellation.views.tableview.utilities.ColumnIndexSort) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn)

Example 62 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState 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 63 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableViewTopComponentNGTest method getColumnAttributeChanges.

@Test
public void getColumnAttributeChanges() {
    final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
    when(tableViewTopComponent.getRemovedAttributes(or(any(TableViewState.class), isNull()), or(any(TableViewState.class), isNull()))).thenCallRealMethod();
    when(tableViewTopComponent.getAddedAttributes(or(any(TableViewState.class), isNull()), or(any(TableViewState.class), isNull()))).thenCallRealMethod();
    final Attribute attribute1 = mock(Attribute.class);
    final Attribute attribute2 = mock(Attribute.class);
    final Attribute attribute3 = mock(Attribute.class);
    final TableViewState oldState = new TableViewState();
    oldState.setColumnAttributes(List.of(Tuple.create(".source", attribute1), Tuple.create(".destination", attribute2)));
    final TableViewState newState = new TableViewState();
    newState.setColumnAttributes(List.of(Tuple.create(".destination", attribute2), Tuple.create(".transaction", attribute3)));
    // Removed column attributes
    assertEquals(Set.of(Tuple.create(".source", attribute1)), tableViewTopComponent.getRemovedAttributes(oldState, newState));
    assertEquals(Set.of(), tableViewTopComponent.getRemovedAttributes(null, newState));
    assertEquals(Set.of(Tuple.create(".source", attribute1), Tuple.create(".destination", attribute2)), tableViewTopComponent.getRemovedAttributes(oldState, null));
    // Added column attributes
    assertEquals(Set.of(Tuple.create(".transaction", attribute3)), tableViewTopComponent.getAddedAttributes(oldState, newState));
    assertEquals(Set.of(Tuple.create(".destination", attribute2), Tuple.create(".transaction", attribute3)), tableViewTopComponent.getAddedAttributes(null, newState));
    assertEquals(Set.of(), tableViewTopComponent.getAddedAttributes(oldState, null));
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 64 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class ActiveTableReferenceNGTest method updateVisibleColumnsAdd.

@Test
public void updateVisibleColumnsAdd() {
    try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        final Graph graph = mock(Graph.class);
        final Attribute attribute = mock(Attribute.class);
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        final List<Tuple<String, Attribute>> paramColumnAttributes = List.of(Tuple.create("paramAttr", attribute));
        final List<Tuple<String, Attribute>> stateColumnAttributes = List.of(Tuple.create("stateAttr", attribute), Tuple.create("paramAttr", attribute));
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setColumnAttributes(stateColumnAttributes);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(executeUpdateStatePlugin(pluginExecution, tableViewState, List.of(Tuple.create("stateAttr", attribute), Tuple.create("paramAttr", attribute), Tuple.create("paramAttr", attribute))));
        activeTableReference.updateVisibleColumns(graph, tableViewState, paramColumnAttributes, UpdateMethod.ADD);
        verify(pluginExecution).executeLater(graph);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Example 65 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class ActiveTableReferenceNGTest method updateVisibleColumnsReplace.

@Test
public void updateVisibleColumnsReplace() {
    try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        final Graph graph = mock(Graph.class);
        final Attribute attribute = mock(Attribute.class);
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        final List<Tuple<String, Attribute>> paramColumnAttributes = List.of(Tuple.create("paramAttr", attribute));
        final List<Tuple<String, Attribute>> stateColumnAttributes = List.of(Tuple.create("stateAttr1", attribute), Tuple.create("stateAttr2", attribute));
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setColumnAttributes(stateColumnAttributes);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(executeUpdateStatePlugin(pluginExecution, tableViewState, List.of(Tuple.create("paramAttr", attribute))));
        activeTableReference.updateVisibleColumns(graph, tableViewState, paramColumnAttributes, UpdateMethod.REPLACE);
        verify(pluginExecution).executeLater(graph);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Aggregations

TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)65 Test (org.testng.annotations.Test)50 Graph (au.gov.asd.tac.constellation.graph.Graph)24 Platform (javafx.application.Platform)19 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)14 ObservableList (javafx.collections.ObservableList)14 Attribute (au.gov.asd.tac.constellation.graph.Attribute)13 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)12 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)10 TableColumn (javafx.scene.control.TableColumn)10 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)7 ListChangeListener (javafx.collections.ListChangeListener)7 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)6 TableViewUtilities (au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities)6 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)5 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)5 Table (au.gov.asd.tac.constellation.views.tableview.components.Table)5 ArrayList (java.util.ArrayList)5