Search in sources :

Example 1 with RightClickContextMenu

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;
}
Also used : RightClickContextMenu(au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu)

Example 2 with RightClickContextMenu

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);
}
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 3 with RightClickContextMenu

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());
}
Also used : RightClickContextMenu(au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu) Test(org.testng.annotations.Test)

Example 4 with RightClickContextMenu

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());
            }
        });
    }
}
Also used : RightClickContextMenu(au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu) TableCell(javafx.scene.control.TableCell) MouseButton(javafx.scene.input.MouseButton) Table(au.gov.asd.tac.constellation.views.tableview.components.Table) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) ObservableList(javafx.collections.ObservableList) TableColumn(javafx.scene.control.TableColumn) RightClickContextMenu(au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu)

Aggregations

RightClickContextMenu (au.gov.asd.tac.constellation.views.tableview.components.RightClickContextMenu)4 ObservableList (javafx.collections.ObservableList)2 TableColumn (javafx.scene.control.TableColumn)2 Test (org.testng.annotations.Test)2 GraphRecordStoreUtilities (au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities)1 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)1 Table (au.gov.asd.tac.constellation.views.tableview.components.Table)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ContextMenu (javafx.scene.control.ContextMenu)1 TableCell (javafx.scene.control.TableCell)1 MouseButton (javafx.scene.input.MouseButton)1 MouseEvent (javafx.scene.input.MouseEvent)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1