use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class NamedSelectionManager method performUnion.
/**
* Requests a union operation to be performed for the named selections that
* match an array of named selection IDs.
* <p>
* This private method takes into account the display settings as per the
* current named selection state.
* <p>
* Member and non-member elements of 'unioned' named selections will be
* shown as per the display settings (ie, if dim others has been set, then
* non-member elements will be dimmed on the graph).
*
* @param graph The graph that is to have the union operation performed
* upon.
* @param useCurrentlySelected <code>true</code> to include the currently
* selected graph elements in the union operation.
* @param isSelectResults <code>true</code> to set member elements
* 'selected' attribute.
* @param isDimOthers <code>true</code> to dim non-member elements.
* @param ids The array of ids of the named selections that are to be
* 'unioned'.
*/
private void performUnion(final Graph graph, final boolean useCurrentlySelected, final boolean isSelectResults, final boolean isDimOthers, final int... ids) {
final Plugin namedSelectionEdit = new NamedSelectionEditorPlugin(NamedSelectionEditorPlugin.Operation.UNION, useCurrentlySelected, isSelectResults, isDimOthers, ids);
final Future<?> f = PluginExecution.withPlugin(namedSelectionEdit).executeLater(graph);
try {
f.get();
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, "Named Selection Union was interrupted", ex);
Thread.currentThread().interrupt();
} catch (final ExecutionException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class PluginsNodeProvider method exportPluginsToCsv.
private static void exportPluginsToCsv(final Window window) {
final DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Select a location to save the CSV file");
final File dir = directoryChooser.showDialog(window);
if (dir != null) {
final StringBuilder sb = new StringBuilder();
// heading
sb.append("Plugin class path").append(SeparatorConstants.COMMA).append("Plugin Alias").append(SeparatorConstants.COMMA).append("Parameter Name").append(SeparatorConstants.COMMA).append("Parameter Type").append(SeparatorConstants.COMMA).append("Parameter Label").append(SeparatorConstants.COMMA).append("Parameter Description").append(SeparatorConstants.COMMA).append("Parameter Default Value").append(SeparatorConstants.NEWLINE);
// details
PluginRegistry.getPluginClassNames().stream().forEach((final String pname) -> {
final Plugin plugin = PluginRegistry.get(pname);
final String name = plugin.getName();
final Map<String, List<PluginParameter<?>>> params = new HashMap<>();
try {
final PluginParameters pp = plugin.createParameters();
if (pp != null) {
final List<PluginParameter<?>> paramList = new ArrayList<>();
pp.getParameters().entrySet().stream().forEach(entry -> {
final PluginParameter<?> param = entry.getValue();
paramList.add(param);
});
Collections.sort(paramList, (a, b) -> a.getId().compareToIgnoreCase(b.getId()));
paramList.stream().forEach(p -> sb.append(plugin.getClass().getName()).append(SeparatorConstants.COMMA).append(PluginRegistry.getAlias(pname)).append(SeparatorConstants.COMMA).append(p.getId()).append(SeparatorConstants.COMMA).append(p.getType().getId()).append(SeparatorConstants.COMMA).append(p.getName()).append(SeparatorConstants.COMMA).append("\"").append(p.getDescription()).append("\"").append(SeparatorConstants.COMMA).append("\"").append(p.getStringValue()).append("\"").append(SeparatorConstants.NEWLINE));
} else {
sb.append(plugin.getClass().getName()).append(SeparatorConstants.COMMA).append(PluginRegistry.getAlias(pname)).append(SeparatorConstants.COMMA).append(SeparatorConstants.NEWLINE);
}
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, "plugin " + pname + " created an exception", ex);
}
final DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
final File file = new File(dir, String.format("Plugin Details - %s.csv", dateFormatter.format(new Date())));
try (final FileOutputStream fileOutputStream = new FileOutputStream(file)) {
fileOutputStream.write(sb.toString().getBytes(StandardCharsets.UTF_8.name()));
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Error during export of plugin details to csv", ex);
}
});
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class ScriptingUtilities method executePlugin.
/**
* Lookup a plugin by name and execute it with custom parameter values.
*
* @param graph The graph on which to execute the plugin.
* @param pluginName The name of the plugin you wish to execute.
* @param pluginParameters A map of parameters to their values for use with
* the plugin you wish to execute.
*/
public void executePlugin(final SGraph graph, final String pluginName, final Map<String, String> pluginParameters) {
final Plugin plugin = PluginRegistry.get(pluginName);
final PluginParameters parameters = new PluginParameters();
parameters.appendParameters(plugin.createParameters());
try {
pluginParameters.forEach((parameterName, parameterValue) -> {
if (parameters.hasParameter(parameterName)) {
parameters.getParameters().get(parameterName).setStringValue(parameterValue);
}
});
PluginExecution.withPlugin(plugin).withParameters(parameters).executeNow(graph.getGraph());
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, ex, () -> pluginName + " was interrupted");
Thread.currentThread().interrupt();
} catch (final PluginException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class ExportMenuNGTest method verifyExportExcelAction.
/**
* Verify that the passed event handler exports to Excel either the whole
* table or just the selected rows.
*
* @param eventHandler the handler to test
* @param expectedCopyOnlySelectedRows true if only the selected rows are
* expected to be exported, false otherwise
* @param userCancelsRequest true if the user is meant to cancel the export when
* picking a file in the file chooser
*/
private void verifyExportExcelAction(final EventHandler<ActionEvent> eventHandler, final boolean userCancelsRequest, final boolean expectedExportOnlySelectedRows) throws InterruptedException, PluginException, ExecutionException {
final ExportMenuItemActionHandler exportActionHandler = (ExportMenuItemActionHandler) eventHandler;
final ExportMenuItemActionHandler spiedExportActionHandler = spy(exportActionHandler);
final FileChooserBuilder exportFileChooser = mock(FileChooserBuilder.class);
final File exportFile = userCancelsRequest ? null : new File("test.xlsx");
final Optional<File> optionalExportFile = Optional.ofNullable(exportFile);
doReturn(exportFileChooser).when(spiedExportActionHandler).getExportFileChooser();
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class);
final MockedStatic<FileChooser> fileChooserMockedStatic = Mockito.mockStatic(FileChooser.class);
final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
// This is added so that the mocked static that we would otherwise be
// trying to run in the fx thread is actually invoked properly
platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).thenAnswer(iom -> {
((Runnable) iom.getArgument(0)).run();
return null;
});
fileChooserMockedStatic.when(() -> FileChooser.openSaveDialog(exportFileChooser)).thenReturn(CompletableFuture.completedFuture(optionalExportFile));
final ActionEvent actionEvent = mock(ActionEvent.class);
final Pagination pagination = mock(Pagination.class);
final TableView<ObservableList<String>> tableView = mock(TableView.class);
final int maxRowsPerPage = 42;
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(maxRowsPerPage);
when(activeTableReference.getPagination()).thenReturn(pagination);
when(table.getTableView()).thenReturn(tableView);
when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
final PluginExecution pluginExecution = mock(PluginExecution.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(mockitoInvocation -> {
final ExportToExcelFilePlugin plugin = (ExportToExcelFilePlugin) mockitoInvocation.getArgument(0);
if (exportFile != null) {
assertEquals(exportFile.getAbsolutePath(), plugin.getFile().getAbsolutePath());
} else {
assertEquals(exportFile, plugin.getFile());
}
assertEquals(pagination, plugin.getPagination());
assertEquals(tableView, plugin.getTable());
assertEquals(42, plugin.getRowsPerPage());
assertEquals(GRAPH_ID, plugin.getSheetName());
assertEquals(expectedExportOnlySelectedRows, plugin.isSelectedOnly());
return pluginExecution;
});
spiedExportActionHandler.handle(actionEvent);
// Wait for the export job to complete
spiedExportActionHandler.getLastExport().get();
fileChooserMockedStatic.verify(() -> FileChooser.openSaveDialog(exportFileChooser));
if (userCancelsRequest) {
verifyNoInteractions(pluginExecution);
} else {
verify(pluginExecution).executeNow((Graph) null);
}
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class TestNotificationsAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
// plugin notifications
final Plugin plugin = new TestNotificationsPlugin();
final PluginParameters pp = plugin.createParameters();
final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_TestNotificationsAction(), pp);
dialog.showAndWait();
if (PluginParametersDialog.OK.equals(dialog.getResult())) {
PluginExecution.withPlugin(plugin).withParameters(pp).executeLater(context.getGraph());
}
// NetBeans NotifyDisplayer options
NotifyDisplayer.display(PLAIN_MESSAGE, NotifyDescriptor.PLAIN_MESSAGE);
NotifyDisplayer.display(QUESTION_MESSAGE, NotifyDescriptor.QUESTION_MESSAGE);
NotifyDisplayer.display(INFORMATION_MESSAGE, NotifyDescriptor.INFORMATION_MESSAGE);
NotifyDisplayer.display(WARNING_MESSAGE, NotifyDescriptor.WARNING_MESSAGE);
NotifyDisplayer.display(ERROR_MESSAGE, NotifyDescriptor.ERROR_MESSAGE);
// Constellation Utility options
Platform.runLater(() -> {
NotifyDisplayer.displayAlert(DISPLAY_ALERT, PLAIN, PLAIN_MESSAGE, Alert.AlertType.NONE);
NotifyDisplayer.displayAlert(DISPLAY_ALERT, INFORMATION, INFORMATION_MESSAGE, Alert.AlertType.INFORMATION);
NotifyDisplayer.displayAlert(DISPLAY_ALERT, WARNING, WARNING_MESSAGE, Alert.AlertType.WARNING);
NotifyDisplayer.displayAlert(DISPLAY_ALERT, ERROR, ERROR_MESSAGE, Alert.AlertType.ERROR);
NotifyDisplayer.displayLargeAlert(DISPLAY_LARGE_ALERT, PLAIN, PLAIN_MESSAGE, Alert.AlertType.NONE);
NotifyDisplayer.displayLargeAlert(DISPLAY_LARGE_ALERT, INFORMATION, INFORMATION_MESSAGE, Alert.AlertType.INFORMATION);
NotifyDisplayer.displayLargeAlert(DISPLAY_LARGE_ALERT, WARNING, WARNING_MESSAGE, Alert.AlertType.WARNING);
NotifyDisplayer.displayLargeAlert(DISPLAY_LARGE_ALERT, ERROR, ERROR_MESSAGE, Alert.AlertType.ERROR);
});
}
Aggregations