Search in sources :

Example 16 with TableViewState

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

the class TableToolbarNGTest method buttonChangeChecksOnToolbarUpdate.

/**
 * Verifies that when the update tool bar method is called, the icons on the
 * selected only button and element type buttons are changed. Also verifies
 * the selected state of the selected only toggle button is changed.
 *
 * @param newSelectedOnlyState the new selected only state, true if it is
 * on, false otherwise
 * @param newElementType the new element type to be displayed in the table
 * @param expectedSelectedOnlyIcon the icon expected to be on the selected
 * only button once update is called
 * @param expectedElementTypeIcon the icon expected to be on the element
 * type button once the update it called
 */
private void buttonChangeChecksOnToolbarUpdate(final boolean newSelectedOnlyState, final GraphElementType newElementType, final Image expectedSelectedOnlyIcon, final Image expectedElementTypeIcon) throws InterruptedException {
    final TableViewState state = new TableViewState();
    final ArgumentCaptor<ImageView> selectedOnlyCaptor = ArgumentCaptor.forClass(ImageView.class);
    final ArgumentCaptor<ImageView> elementTypeCaptor = ArgumentCaptor.forClass(ImageView.class);
    final ToggleButton selectedOnlyButton = mock(ToggleButton.class);
    final Button elementTypeButton = mock(Button.class);
    when(tableToolbar.getSelectedOnlyButton()).thenReturn(selectedOnlyButton);
    when(tableToolbar.getElementTypeButton()).thenReturn(elementTypeButton);
    state.setSelectedOnly(newSelectedOnlyState);
    state.setElementType(newElementType);
    tableToolbar.updateToolbar(state);
    final CountDownLatch latch = new CountDownLatch(1);
    Platform.runLater(() -> latch.countDown());
    latch.await();
    verify(selectedOnlyButton).setSelected(newSelectedOnlyState);
    verify(selectedOnlyButton).setGraphic(selectedOnlyCaptor.capture());
    assertTrue(isImageEqual(expectedSelectedOnlyIcon, selectedOnlyCaptor.getValue().getImage()));
    verify(elementTypeButton).setGraphic(elementTypeCaptor.capture());
    assertTrue(isImageEqual(expectedElementTypeIcon, elementTypeCaptor.getValue().getImage()));
}
Also used : ToggleButton(javafx.scene.control.ToggleButton) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) MenuButton(javafx.scene.control.MenuButton) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ImageView(javafx.scene.image.ImageView) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 17 with TableViewState

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

the class TableViewPageFactoryNGTest method updateSelectionNotInSelectedOnlyMode.

@Test
public void updateSelectionNotInSelectedOnlyMode() throws InterruptedException, ExecutionException {
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setSelectedOnly(false);
    tableViewState.setElementType(GraphElementType.VERTEX);
    doReturn(List.of(100, 102)).when(tableViewPageFactory).getSelectedIds(any(Graph.class), any(TableViewState.class));
    final ObservableList<String> vertex1 = FXCollections.observableList(List.of("Vertex1Attr1", "Vertex1Attr2"));
    final ObservableList<String> vertex2 = FXCollections.observableList(List.of("Vertex2Attr1", "Vertex2Attr2"));
    final ObservableList<String> vertex3 = FXCollections.observableList(List.of("Vertex3Attr1", "Vertex3Attr2"));
    final Map<Integer, ObservableList<String>> elementIdToRowIndex = Map.of(100, vertex1, 102, vertex2, 103, vertex3);
    // Order is important here. Should match on vertex 1 and 2, so indicies 0 and 2.
    when(tableView.getItems()).thenReturn(FXCollections.observableList(List.of(vertex1, vertex3, vertex2)));
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(true);
        tableViewPageFactory.restoreSelectionFromGraph(graph, tableViewState, elementIdToRowIndex);
    }
    verify(tableViewPageFactory).getSelectedIds(graph, tableViewState);
    verify(selectionModel).clearSelection();
    verify(selectionModel).selectIndices(0, 0, 2);
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) Platform(javafx.application.Platform) ObservableList(javafx.collections.ObservableList) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 18 with TableViewState

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

the class TableViewPageFactoryNGTest method updateSelectionInSelectedOnlyMode.

@Test
public void updateSelectionInSelectedOnlyMode() {
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(true);
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setSelectedOnly(true);
        tableViewPageFactory.restoreSelectionFromGraph(graph, tableViewState, null);
        verifyNoInteractions(table);
    }
}
Also used : Platform(javafx.application.Platform) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 19 with TableViewState

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

the class TableViewPageFactoryNGTest method callEnsureExternalCallsMade.

@Test
public void callEnsureExternalCallsMade() {
    doNothing().when(tableViewPageFactory).restoreSelectionFromGraph(any(Graph.class), any(TableViewState.class), any(Map.class));
    final ObservableList<String> row1 = FXCollections.observableArrayList(List.of("row1Column1", "row1Column2"));
    final ObservableList<String> row2 = FXCollections.observableArrayList(List.of("row2Column1", "row2Column2"));
    final ObservableList<String> row3 = FXCollections.observableArrayList(List.of("row3Column1", "row3Column2"));
    final List<ObservableList<String>> newRowList = List.of(row1, row2, row3);
    final Map<Integer, ObservableList<String>> elementIdToRowIndex = Map.of();
    final int maxRowsPerPage = 2;
    final int pageIndex = 0;
    final TableColumn<ObservableList<String>, String> sortCol = mock(TableColumn.class);
    final Pair<TableColumn<ObservableList<String>, ?>, TableColumn.SortType> currentSort = ImmutablePair.of(sortCol, TableColumn.SortType.DESCENDING);
    doReturn(currentSort).when(tableViewPageFactory).getCurrentSort();
    doNothing().when(tableViewPageFactory).restoreSort(any(Pair.class));
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setSelectedOnly(false);
    when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
    when(activeTableReference.getElementIdToRowIndex()).thenReturn(elementIdToRowIndex);
    selectedOnlySelectedRows.add(row1);
    selectedOnlySelectedRows.add(row2);
    // This is called after the page set up so just mocking it so that it is realistic
    when(tableView.getItems()).thenReturn(FXCollections.observableList(List.of(row1, row2)));
    tableViewPageFactory.update(newRowList, maxRowsPerPage);
    assertEquals(tableView, tableViewPageFactory.call(pageIndex));
    verify(tableViewPageFactory).removeListeners();
    verify(tableViewPageFactory).getCurrentSort();
    verify(sortedRowListComparator).unbind();
    verify(tableView).setItems(FXCollections.observableList(List.of(row1, row2)));
    verify(sortedRowListComparator).bind(tableViewComparator);
    verify(tableViewPageFactory).restoreSort(currentSort);
    verify(tableViewPageFactory).restoreSelectionFromGraph(graph, tableViewState, elementIdToRowIndex);
    // This is the first call so selectedOnlySelectedRows will be cleared
    // and the selection is not updated
    verify(selectionModel, times(0)).selectIndices(0, 0, 1);
    verify(tableViewPageFactory).restoreListeners();
}
Also used : TableColumn(javafx.scene.control.TableColumn) SortType(javafx.scene.control.TableColumn.SortType) Graph(au.gov.asd.tac.constellation.graph.Graph) ObservableList(javafx.collections.ObservableList) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Test(org.testng.annotations.Test)

Example 20 with TableViewState

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

the class TableNGTest method updateColumnsOnFxThread.

@Test(expectedExceptions = IllegalStateException.class)
public void updateColumnsOnFxThread() {
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(true);
        table.updateColumns(graph, new TableViewState());
    }
}
Also used : Platform(javafx.application.Platform) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) 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