use of au.gov.asd.tac.constellation.views.tableview.api.Column in project constellation by constellation-app.
the class ColumnVisibilityContextMenuNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
tableViewTopComponent = mock(TableViewTopComponent.class);
tablePane = mock(TablePane.class);
table = mock(Table.class);
activeTableReference = mock(ActiveTableReference.class);
graph = mock(Graph.class);
readableGraph = mock(ReadableGraph.class);
tableViewState = new TableViewState();
when(graph.getReadableGraph()).thenReturn(readableGraph);
// These two will define which columns are shown when the "Key Columns" button is pressed
when(readableGraph.getPrimaryKey(GraphElementType.VERTEX)).thenReturn(new int[] { 2, 3 });
when(readableGraph.getPrimaryKey(GraphElementType.TRANSACTION)).thenReturn(new int[] { 5 });
// Define the columns available in the table
// I think typically the value for Attribut.getAttribute and
// TableColumn.getText will be the same. But for the purpose of these
// tests they are different so it can be differentiated in the assertions
columnType1 = "source.";
when(readableGraph.getAttributeName(1)).thenReturn("Location Name");
attribute1 = new GraphAttribute(readableGraph, 1);
column1 = mock(TableColumn.class);
when(column1.getText()).thenReturn("Text from Column 1");
columnType2 = "destination.";
when(readableGraph.getAttributeName(2)).thenReturn("Number of Visitors");
attribute2 = new GraphAttribute(readableGraph, 2);
column2 = mock(TableColumn.class);
when(column2.getText()).thenReturn("Text from Column 2");
columnType3 = "source.";
when(readableGraph.getAttributeName(3)).thenReturn("personal notes");
attribute3 = new GraphAttribute(readableGraph, 3);
column3 = mock(TableColumn.class);
when(column3.getText()).thenReturn("Text from Column 3");
columnType4 = "transaction.";
when(readableGraph.getAttributeName(4)).thenReturn("Related To");
attribute4 = new GraphAttribute(readableGraph, 4);
column4 = mock(TableColumn.class);
when(column4.getText()).thenReturn("Text from Column 4");
columnType5 = "transaction.";
when(readableGraph.getAttributeName(5)).thenReturn("personal notes");
attribute5 = new GraphAttribute(readableGraph, 5);
column5 = mock(TableColumn.class);
when(column5.getText()).thenReturn("Text from Column 5");
final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
columnIndex.add(new Column(columnType1, attribute1, column1));
columnIndex.add(new Column(columnType2, attribute2, column2));
columnIndex.add(new Column(columnType3, attribute3, column3));
columnIndex.add(new Column(columnType4, attribute4, column4));
columnIndex.add(new Column(columnType5, attribute5, column5));
when(table.getColumnIndex()).thenReturn(columnIndex);
when(table.getParentComponent()).thenReturn(tablePane);
when(tablePane.getActiveTableReference()).thenReturn(activeTableReference);
when(tablePane.getParentComponent()).thenReturn(tableViewTopComponent);
when(tableViewTopComponent.getCurrentGraph()).thenReturn(graph);
when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
columnVisibilityContextMenu = spy(new ColumnVisibilityContextMenu(table));
}
use of au.gov.asd.tac.constellation.views.tableview.api.Column in project constellation by constellation-app.
the class ColumnVisibilityContextMenuNGTest method createColumnVisibilityMenuItemSelected.
@Test
public void createColumnVisibilityMenuItemSelected() {
final String columnText = "Some Column Text";
final boolean isSelected = true;
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.ADD);
}
use of au.gov.asd.tac.constellation.views.tableview.api.Column in project constellation by constellation-app.
the class ColumnVisibilityContextMenuNGTest method createExportButtons.
@Test
public void createExportButtons() {
// To remove extra complexity from this test it will stub the createColumnVisibilityMenuItem
// method and test it separately
final CustomMenuItem columnVisibilityMenuItemColumn1 = mock(CustomMenuItem.class);
final CustomMenuItem columnVisibilityMenuItemColumn2 = mock(CustomMenuItem.class);
final CustomMenuItem columnVisibilityMenuItemColumn3 = mock(CustomMenuItem.class);
final CustomMenuItem columnVisibilityMenuItemColumn4 = mock(CustomMenuItem.class);
final CustomMenuItem columnVisibilityMenuItemColumn5 = mock(CustomMenuItem.class);
doReturn(columnVisibilityMenuItemColumn1).when(columnVisibilityContextMenu).createColumnVisibilityMenu(new Column(columnType1, attribute1, column1));
doReturn(columnVisibilityMenuItemColumn2).when(columnVisibilityContextMenu).createColumnVisibilityMenu(new Column(columnType2, attribute2, column2));
doReturn(columnVisibilityMenuItemColumn3).when(columnVisibilityContextMenu).createColumnVisibilityMenu(new Column(columnType3, attribute3, column3));
doReturn(columnVisibilityMenuItemColumn4).when(columnVisibilityContextMenu).createColumnVisibilityMenu(new Column(columnType4, attribute4, column4));
doReturn(columnVisibilityMenuItemColumn5).when(columnVisibilityContextMenu).createColumnVisibilityMenu(new Column(columnType5, attribute5, column5));
columnVisibilityContextMenu.init();
assertNotNull(columnVisibilityContextMenu.getContextMenu());
assertNotNull(columnVisibilityContextMenu.getShowAllColumnsMenu());
assertNotNull(columnVisibilityContextMenu.getShowDefaultColumnsMenu());
assertNotNull(columnVisibilityContextMenu.getShowPrimaryColumnsMenu());
assertNotNull(columnVisibilityContextMenu.getHideAllColumnsMenu());
assertNotNull(columnVisibilityContextMenu.getSourceVertexColumnsMenu());
assertNotNull(columnVisibilityContextMenu.getDestinationVertexColumnMenu());
assertNotNull(columnVisibilityContextMenu.getTransactionColumnMenu());
// No equality in separator so we have to pull it out and place it back in
final Optional<MenuItem> separator = columnVisibilityContextMenu.getContextMenu().getItems().stream().filter(SeparatorMenuItem.class::isInstance).findFirst();
assertTrue(separator.isPresent());
assertEquals(FXCollections.observableList(List.of(columnVisibilityContextMenu.getShowAllColumnsMenu(), columnVisibilityContextMenu.getShowDefaultColumnsMenu(), columnVisibilityContextMenu.getShowPrimaryColumnsMenu(), columnVisibilityContextMenu.getHideAllColumnsMenu(), separator.get(), columnVisibilityContextMenu.getSourceVertexColumnsMenu(), columnVisibilityContextMenu.getDestinationVertexColumnMenu(), columnVisibilityContextMenu.getTransactionColumnMenu())), columnVisibilityContextMenu.getContextMenu().getItems());
// ///////////////
// ALL COLUMNS
// ///////////////
verifyCustomMenu(columnVisibilityContextMenu.getShowAllColumnsMenu(), "Show All Columns", false);
// All columns are passed
verifyAllColumnsMenuClicked(columnVisibilityContextMenu.getShowAllColumnsMenu(), List.of(Tuple.create(columnType1, attribute1), Tuple.create(columnType2, attribute2), Tuple.create(columnType3, attribute3), Tuple.create(columnType4, attribute4), Tuple.create(columnType5, attribute5)));
// ///////////////
// DEFAULT COLUMNS
// ///////////////
verifyCustomMenu(columnVisibilityContextMenu.getShowDefaultColumnsMenu(), "Show Default Columns", false);
// Only column 3 has a name starting with a lower case character, so it is excluded
verifyAllColumnsMenuClicked(columnVisibilityContextMenu.getShowDefaultColumnsMenu(), List.of(Tuple.create(columnType1, attribute1), Tuple.create(columnType2, attribute2), Tuple.create(columnType4, attribute4)));
// ///////////////
// KEY COLUMNS
// ///////////////
verifyCustomMenu(columnVisibilityContextMenu.getShowPrimaryColumnsMenu(), "Show Key Columns", false);
// Only pass the key or primary columns as defined by readableGraph#getPrimaryKey(GraphElement)
verifyProvidedColumnVisibilityActions(columnVisibilityContextMenu.getShowPrimaryColumnsMenu(), List.of(Tuple.create(columnType2, attribute2), Tuple.create(columnType3, attribute3), Tuple.create(columnType5, attribute5)), () -> verify(readableGraph).release());
// ///////////////
// NO COLUMNS
// ///////////////
verifyCustomMenu(columnVisibilityContextMenu.getHideAllColumnsMenu(), "Show No Columns", false);
// No columns are passed and the actual table columns visibility is set to false
verifyProvidedColumnVisibilityActions(columnVisibilityContextMenu.getHideAllColumnsMenu(), Collections.emptyList(), () -> {
verify(column1).setVisible(false);
verify(column2).setVisible(false);
verify(column3).setVisible(false);
verify(column4).setVisible(false);
verify(column5).setVisible(false);
});
// ///////////////
// SPLIT SOURCE
// ///////////////
verifyDynamicColumnMenu(columnVisibilityContextMenu.getSourceVertexColumnsMenu(), List.of(columnVisibilityMenuItemColumn1, columnVisibilityMenuItemColumn3));
// ////////////////////
// SPLIT DESTINATION
// ////////////////////
verifyDynamicColumnMenu(columnVisibilityContextMenu.getDestinationVertexColumnMenu(), List.of(columnVisibilityMenuItemColumn2));
// ////////////////////
// SPLIT TRANSACTION
// ////////////////////
verifyDynamicColumnMenu(columnVisibilityContextMenu.getTransactionColumnMenu(), List.of(columnVisibilityMenuItemColumn4, columnVisibilityMenuItemColumn5));
}
use of au.gov.asd.tac.constellation.views.tableview.api.Column 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));
}
use of au.gov.asd.tac.constellation.views.tableview.api.Column 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));
}
Aggregations