Search in sources :

Example 1 with Column

use of au.gov.asd.tac.constellation.views.tableview.api.Column in project constellation by constellation-app.

the class ColumnVisibilityContextMenuNGTest method createColumnVisibilityMenuItemNotSelected.

@Test
public void createColumnVisibilityMenuItemNotSelected() {
    final String columnText = "Some Column Text";
    final boolean isSelected = false;
    when(column1.getText()).thenReturn(columnText);
    when(column1.visibleProperty()).thenReturn(new SimpleBooleanProperty(isSelected));
    final CustomMenuItem columnVisibilityMenuItem = columnVisibilityContextMenu.createColumnVisibilityMenu(new Column(columnType1, attribute1, column1));
    verifyColumnVisibilityCheckBox(columnVisibilityMenuItem, isSelected, columnText, List.of(Tuple.create(columnType1, attribute1)), UpdateMethod.REMOVE);
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) TableColumn(javafx.scene.control.TableColumn) CustomMenuItem(javafx.scene.control.CustomMenuItem) Test(org.testng.annotations.Test)

Example 2 with Column

use of au.gov.asd.tac.constellation.views.tableview.api.Column in project constellation by constellation-app.

the class TableCellFactoryNGTest method updateItemTestMouseClickWrongButton.

@Test
public void updateItemTestMouseClickWrongButton() {
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    when(table.getColumnIndex()).thenReturn(columnIndex);
    tableCellFactory.updateItem("Test Value", false);
    final MouseEvent mouseEvent = mock(MouseEvent.class);
    when(mouseEvent.getButton()).thenReturn(MouseButton.PRIMARY);
    tableCellFactory.getOnMouseClicked().handle(mouseEvent);
    verify(tableCellFactory, times(0)).getRightClickContextMenu();
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) TableColumn(javafx.scene.control.TableColumn) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Example 3 with Column

use of au.gov.asd.tac.constellation.views.tableview.api.Column in project constellation by constellation-app.

the class TableCellFactoryNGTest method updateItemTestMouseClick.

@Test
public void updateItemTestMouseClick() {
    final ObservableList<String> styleClass = spy(FXCollections.observableArrayList());
    doReturn(styleClass).when(tableCellFactory).getStyleClass();
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    when(table.getColumnIndex()).thenReturn(columnIndex);
    tableCellFactory.updateItem("Test Value", false);
    final TableView<ObservableList<String>> tableView = mock(TableView.class);
    final RightClickContextMenu rightClickContextMenu = mock(RightClickContextMenu.class);
    final ContextMenu contextMenu = mock(ContextMenu.class);
    final MouseEvent mouseEvent = mock(MouseEvent.class);
    doReturn(rightClickContextMenu).when(tableCellFactory).getRightClickContextMenu();
    when(rightClickContextMenu.getContextMenu()).thenReturn(contextMenu);
    when(mouseEvent.getScreenX()).thenReturn(20.0d);
    when(mouseEvent.getScreenY()).thenReturn(40.0d);
    when(mouseEvent.getButton()).thenReturn(MouseButton.SECONDARY);
    when(table.getTableView()).thenReturn(tableView);
    tableCellFactory.getOnMouseClicked().handle(mouseEvent);
    verify(contextMenu).show(tableView, 20.0d, 40.0d);
    assertEquals(FXCollections.observableArrayList(), styleClass);
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) TableColumn(javafx.scene.control.TableColumn) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) ObservableList(javafx.collections.ObservableList) ContextMenu(javafx.scene.control.ContextMenu) RightClickContextMenu(au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RightClickContextMenu(au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Example 4 with Column

use of au.gov.asd.tac.constellation.views.tableview.api.Column in project constellation by constellation-app.

the class TableCellFactoryNGTest method verifyStyle.

/**
 * Verifies that the cell text is set correctly and the correct style for
 * the column is added to the style class list.
 *
 * @param item the string passed in to be set in the table cell
 * @param columnPrefix the column prefix for this cells column
 * @param expectedText the expected string that will be set to the cell
 * @param expectedStyles the expected styles that should be present in the
 * style class list
 */
private void verifyStyle(final String item, final String columnPrefix, final String expectedText, final List<String> expectedStyles) {
    clearInvocations(tableCellFactory, table);
    final ObservableList<String> styleClass = spy(FXCollections.observableArrayList());
    doReturn(styleClass).when(tableCellFactory).getStyleClass();
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    columnIndex.add(new Column("source.", null, mock(TableColumn.class)));
    columnIndex.add(new Column(columnPrefix, null, cellColumn));
    columnIndex.add(new Column("transaction.", null, mock(TableColumn.class)));
    when(table.getColumnIndex()).thenReturn(columnIndex);
    tableCellFactory.updateItem(item, false);
    verify(tableCellFactory).setText(expectedText);
    verify(styleClass).remove("null-value");
    verify(styleClass).remove("element-source");
    verify(styleClass).remove("element-destination");
    verify(styleClass).remove("element-transaction");
    expectedStyles.forEach(expectedStyle -> verify(styleClass).add(expectedStyle));
    assertEquals(FXCollections.observableList(expectedStyles), styleClass);
}
Also used : TableColumn(javafx.scene.control.TableColumn) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 5 with Column

use of au.gov.asd.tac.constellation.views.tableview.api.Column 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

Column (au.gov.asd.tac.constellation.views.tableview.api.Column)18 TableColumn (javafx.scene.control.TableColumn)17 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)13 ObservableList (javafx.collections.ObservableList)11 Test (org.testng.annotations.Test)11 Attribute (au.gov.asd.tac.constellation.graph.Attribute)9 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)9 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)8 ActiveTableReference (au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference)5 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)5 TableViewTopComponent (au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent)4 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)4 List (java.util.List)4 ListChangeListener (javafx.collections.ListChangeListener)4 CustomMenuItem (javafx.scene.control.CustomMenuItem)4 Graph (au.gov.asd.tac.constellation.graph.Graph)3 UpdateColumnsTask (au.gov.asd.tac.constellation.views.tableview.tasks.UpdateColumnsTask)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 Platform (javafx.application.Platform)3