use of au.gov.asd.tac.constellation.views.dataaccess.panes.PluginFinder in project constellation by constellation-app.
the class TabContextMenuNGTest method verifyFindPluginMenuItemAction.
/**
* Verify the find plugin is run when the menu item is clicked.
*
* @param findPluginMenuItem the find plugin menu item
*/
private void verifyFindPluginMenuItemAction(final MenuItem findPluginMenuItem) {
try (final MockedStatic<DataAccessTabPane> tabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class);
final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
when(dataAccessTabPane.getDataAccessPane()).thenReturn(dataAccessPane);
final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
tabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(tab)).thenReturn(queryPhasePane);
platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).thenAnswer(iom -> {
// The code is run in the JavaFX thread, so intercept it and run locally
final Runnable action = iom.getArgument(0);
// The code constructs a plugin finder and then calls find. Need to inject
// a mock into that construction
final MockedConstruction<PluginFinder> mockedPluginFinders = Mockito.mockConstruction(PluginFinder.class);
action.run();
// Verify the plugin finder was created and used as expected
assertEquals(mockedPluginFinders.constructed().size(), 1);
verify(mockedPluginFinders.constructed().get(0)).find(queryPhasePane);
return null;
});
final ActionEvent actionEvent = mock(ActionEvent.class);
findPluginMenuItem.getOnAction().handle(actionEvent);
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.views.dataaccess.panes.PluginFinder in project constellation by constellation-app.
the class TabContextMenu method init.
/**
* Initializes the context menu. Until this method is called, all context menu
* UI components will be null.
*/
public void init() {
// /////////////////////////////////////
// De-Activate All Plugins Menu Item
// /////////////////////////////////////
deactivateAllPluginsMenuItem = new MenuItem(DEACTIVATE_ALL_PLUGINS_TEXT);
deactivateAllPluginsMenuItem.setOnAction(event -> {
DataAccessTabPane.getQueryPhasePane(tab).getDataAccessPanes().stream().filter(dataSourceTitledPane -> (dataSourceTitledPane.isQueryEnabled())).forEachOrdered(dataSourceTitledPane -> dataSourceTitledPane.validityChanged(false));
event.consume();
});
// //////////////////////////
// Find Plugin Menu Item
// //////////////////////////
findPluginMenuItem = new MenuItem(FIND_PLUGIN_TEXT);
findPluginMenuItem.setOnAction(event -> {
// Run it later to allow the menu to close.
Platform.runLater(() -> {
final PluginFinder pluginFinder = new PluginFinder();
pluginFinder.find(DataAccessTabPane.getQueryPhasePane(tab));
});
event.consume();
});
// //////////////////////////////
// Open All Sections Menu Item
// //////////////////////////////
openAllSectionsMenuItem = new MenuItem(OPEN_ALL_SECTIONS_TEXT);
openAllSectionsMenuItem.setOnAction(event -> {
DataAccessTabPane.getQueryPhasePane(tab).setHeadingsExpanded(true, false);
event.consume();
});
// //////////////////////////////
// Close All Sections Menu Item
// //////////////////////////////
closeAllSectionsMenuItem = new MenuItem(CLOSE_ALL_SECTIONS_TEXT);
closeAllSectionsMenuItem.setOnAction(event -> {
DataAccessTabPane.getQueryPhasePane(tab).setHeadingsExpanded(false, false);
event.consume();
});
// //////////////////////////////
// Run Single Tab Menu Item
// //////////////////////////////
runMenuItem = new MenuItem(RUN_TEXT);
runMenuItem.setOnAction(event -> {
final int index = dataAccessTabPane.getTabPane().getTabs().indexOf(tab);
dataAccessTabPane.runTabs(index, index);
event.consume();
});
// //////////////////////////////
// Run Tabs From Here Menu Item
// //////////////////////////////
runFromHereMenuItem = new MenuItem(RUN_FROM_HERE_TEXT);
runFromHereMenuItem.setOnAction(event -> {
final int index = dataAccessTabPane.getTabPane().getTabs().indexOf(tab);
dataAccessTabPane.runTabs(index, dataAccessTabPane.getTabPane().getTabs().size() - 1);
event.consume();
});
// //////////////////////////////
// Run Tabs To Here Menu Item
// //////////////////////////////
runToHereMenuItem = new MenuItem(RUN_TO_HERE_TEXT);
runToHereMenuItem.setOnAction(event -> {
final int index = dataAccessTabPane.getTabPane().getTabs().indexOf(tab);
dataAccessTabPane.runTabs(0, index);
event.consume();
});
// //////////////////////////////
// Context Menu
// //////////////////////////////
/**
* The position order of the menu options has been considered carefully
* based on feedback. For instance the "Deactivate all plugins" exists
* as the first entry because it is the most common use case and also
* makes it less likely for one of the run* options to be clicked
* accidentally.
*/
contextMenu = new ContextMenu();
contextMenu.getItems().addAll(deactivateAllPluginsMenuItem, new SeparatorMenuItem(), findPluginMenuItem, openAllSectionsMenuItem, closeAllSectionsMenuItem, new SeparatorMenuItem(), runMenuItem, runFromHereMenuItem, runToHereMenuItem);
}
Aggregations