use of au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu in project constellation by constellation-app.
the class TableCellFactory method getRightClickContextMenu.
/**
* Gets a initialized {@link RightClickContextMenu}. If the context menu has
* already been initialized it will use that otherwise it will create and
* initialize the menu.
*
* @return the right click context menu for this cell
*/
protected final RightClickContextMenu getRightClickContextMenu() {
if (rightClickContextMenuInstance == null) {
rightClickContextMenuInstance = new RightClickContextMenu(table);
rightClickContextMenuInstance.init(this);
}
return rightClickContextMenuInstance;
}
use of au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu 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);
}
use of au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu in project constellation by constellation-app.
the class TableCellFactoryNGTest method getRightClickContextMenu.
@Test
public void getRightClickContextMenu() {
final RightClickContextMenu menu = tableCellFactory.getRightClickContextMenu();
assertNotNull(menu);
assertNotNull(menu.getContextMenu());
assertSame(menu, tableCellFactory.getRightClickContextMenu());
}
use of au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu in project constellation by constellation-app.
the class TableCellFactory method updateItem.
/**
* Sets the cells text to the passed item and then updates the cells style
* classes based on the cells column attributes.
*
* @param item the string to set the cells text to
* @param empty true and the item will not be set to the cells text, false
* and it will
*/
@Override
public void updateItem(final String item, final boolean empty) {
super.updateItem(item, empty);
if (!empty) {
// set text in cell and style if it is null
this.getStyleClass().remove(NULL_VALUE_CLASS);
if (item != null) {
this.setText(item);
} else {
this.setText(NO_VALUE_TEXT);
this.getStyleClass().add(NULL_VALUE_CLASS);
}
// color cell based on the attribute it represents
this.getStyleClass().remove(ELEMENT_SOURCE_CLASS);
this.getStyleClass().remove(ELEMENT_TRANSACTION_CLASS);
this.getStyleClass().remove(ELEMENT_DESTINATION_CLASS);
// based on the column name prefixes ".source", ".destination" and
// ".transaction" set the appropriate style class
final String columnPrefix = table.getColumnIndex().stream().filter(column -> column.getTableColumn().equals(cellColumn)).map(column -> column.getAttributeNamePrefix()).findFirst().orElse("");
switch(columnPrefix) {
case GraphRecordStoreUtilities.SOURCE:
this.getStyleClass().add(ELEMENT_SOURCE_CLASS);
break;
case GraphRecordStoreUtilities.TRANSACTION:
this.getStyleClass().add(ELEMENT_TRANSACTION_CLASS);
break;
case GraphRecordStoreUtilities.DESTINATION:
this.getStyleClass().add(ELEMENT_DESTINATION_CLASS);
break;
default:
// Code can't make it to here
break;
}
// enable context menu on right-click
this.setOnMouseClicked(me -> {
if (me.getButton() == MouseButton.SECONDARY) {
final RightClickContextMenu rightClickContextMenu = getRightClickContextMenu();
// open the context menu at the mouses current location
rightClickContextMenu.getContextMenu().show(table.getTableView(), me.getScreenX(), me.getScreenY());
}
});
}
}
Aggregations