Search in sources :

Example 31 with Plugin

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);
    }
}
Also used : NamedSelectionEditorPlugin(au.gov.asd.tac.constellation.views.namedselection.utilities.NamedSelectionEditorPlugin) ExecutionException(java.util.concurrent.ExecutionException) NamedSelectionEditorPlugin(au.gov.asd.tac.constellation.views.namedselection.utilities.NamedSelectionEditorPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) NamedSelectionStatePlugin(au.gov.asd.tac.constellation.views.namedselection.state.NamedSelectionStatePlugin)

Example 32 with Plugin

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);
            }
        });
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) Date(java.util.Date) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) FileOutputStream(java.io.FileOutputStream) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) DirectoryChooser(javafx.stage.DirectoryChooser) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 33 with Plugin

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);
    }
}
Also used : PluginException(au.gov.asd.tac.constellation.plugins.PluginException) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 34 with Plugin

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();
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Platform(javafx.application.Platform) ActionEvent(javafx.event.ActionEvent) ExportMenuItemActionHandler(au.gov.asd.tac.constellation.views.tableview.components.ExportMenu.ExportMenuItemActionHandler) ExportToExcelFilePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.ExportToExcelFilePlugin) Pagination(javafx.scene.control.Pagination) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ObservableList(javafx.collections.ObservableList) JFileChooser(javax.swing.JFileChooser) FileChooser(au.gov.asd.tac.constellation.utilities.gui.filechooser.FileChooser) FileChooserBuilder(org.openide.filesystems.FileChooserBuilder) File(java.io.File) ExportToExcelFilePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.ExportToExcelFilePlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) ExportToCsvFilePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.ExportToCsvFilePlugin)

Example 35 with Plugin

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);
    });
}
Also used : PluginParametersSwingDialog(au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Aggregations

Plugin (au.gov.asd.tac.constellation.plugins.Plugin)85 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)52 Test (org.testng.annotations.Test)43 Graph (au.gov.asd.tac.constellation.graph.Graph)24 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)19 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)14 SimplePlugin (au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)10 PluginSynchronizer (au.gov.asd.tac.constellation.plugins.PluginSynchronizer)9 Future (java.util.concurrent.Future)9 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)8 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)8 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)8 PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)8 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 ExecutorService (java.util.concurrent.ExecutorService)7 ArrayList (java.util.ArrayList)6 Callable (java.util.concurrent.Callable)6 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)5 CopyToNewGraphPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin)5