Search in sources :

Example 1 with PluginGraphs

use of au.gov.asd.tac.constellation.plugins.PluginGraphs in project constellation by constellation-app.

the class ExecuteListener method handle.

/**
 * Handles the click of the execute button in the data access view.
 * <p/>
 * If the execute button was in the "Go" state then it will iterate through
 * all the tabs and run the enabled and valid plugins.
 * <p/>
 * If the execute button was in the "Stop" state then cancel any running plugins.
 *
 * @param event the event triggered by clicking the execute button
 */
@Override
public void handle(final ActionEvent event) {
    // When no graph present, create a new one
    if (DataAccessPaneState.getCurrentGraphId() == null && dataAccessPane.getDataAccessTabPane().hasActiveAndValidPlugins()) {
        // Create new graph
        final NewDefaultSchemaGraphAction graphAction = new NewDefaultSchemaGraphAction();
        graphAction.actionPerformed(null);
        Graph newActiveGraph = null;
        // Wait while graph is getting made
        while (newActiveGraph == null) {
            newActiveGraph = GraphManager.getDefault().getActiveGraph();
        }
        // Set the state's current graph ID to the ID of the new graph
        DataAccessPaneState.setCurrentGraphId(newActiveGraph.getId());
    }
    // Run the selected queries
    final ObservableList<Tab> tabs = dataAccessPane.getDataAccessTabPane().getTabPane().getTabs();
    if (CollectionUtils.isNotEmpty(tabs) && DataAccessPaneState.isExecuteButtonIsGo()) {
        // Change the execute button to "Stop" and do not disable because it is now running
        dataAccessPane.setExecuteButtonToStop(false);
        // Set the state for the current graph state to running queries
        DataAccessPaneState.setQueriesRunning(true);
        // Check to see if an output dir exists. Non exisiting dirs do not prevent the
        // plugins running, just triggers a notification
        final File outputDir = DataAccessPreferenceUtilities.getDataAccessResultsDirEx();
        if (outputDir != null && outputDir.isDirectory()) {
            StatusDisplayer.getDefault().setStatusText(String.format(STATUS_MESSAGE_FORMAT, outputDir.getAbsolutePath()));
        } else if (outputDir != null) {
            NotificationDisplayer.getDefault().notify(RESULTS_DIR_NOT_FOUND_TITLE, ERROR_ICON, String.format(RESULTS_DIR_NOT_FOUND_MSG, outputDir.getAbsolutePath()), null);
        }
        // Save the current data access view state
        PluginExecution.withPlugin(new SimplePlugin(SAVE_STATE_PLUGIN_NAME) {

            @Override
            protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
                DataAccessUtilities.saveDataAccessState(dataAccessPane.getDataAccessTabPane().getTabPane(), GraphNode.getGraph(DataAccessPaneState.getCurrentGraphId()));
            }
        }).executeLater(null);
        // Run the plugins from each tab. The barrier is the plugin run futures
        // from the previous tab. When the tab is run, it has the option to
        // wait for the previous tab to complete.
        List<Future<?>> barrier = null;
        for (final Tab tab : tabs) {
            LOGGER.log(Level.INFO, String.format("Running tab: %s", tab.getText()));
            barrier = DataAccessTabPane.getQueryPhasePane(tab).runPlugins(barrier);
        }
        // Asynchronously start the task that waits for all the plugins to complete.
        // Once they are complete this task will perform cleanup.
        CompletableFuture.runAsync(new WaitForQueriesToCompleteTask(dataAccessPane, DataAccessPaneState.getCurrentGraphId()), dataAccessPane.getParentComponent().getExecutorService());
        LOGGER.info("Plugins run.");
    } else {
        // The execute button is in a "Stop" state. So cancel any running plugins.
        DataAccessPaneState.getRunningPlugins().keySet().forEach(running -> running.cancel(true));
        // Nothing is running now, so change the execute button to "Go".
        dataAccessPane.setExecuteButtonToGo(false);
    }
    // Disables all plugins in the plugin pane
    if (DataAccessPreferenceUtilities.isDeselectPluginsOnExecuteEnabled()) {
        deselectAllPlugins();
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) WaitForQueriesToCompleteTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask) Tab(javafx.scene.control.Tab) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) NewDefaultSchemaGraphAction(au.gov.asd.tac.constellation.graph.node.create.NewDefaultSchemaGraphAction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) File(java.io.File)

Example 2 with PluginGraphs

use of au.gov.asd.tac.constellation.plugins.PluginGraphs in project constellation by constellation-app.

the class ExecuteListenerNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    dataAccessViewTopComponent = mock(DataAccessViewTopComponent.class);
    dataAccessPane = mock(DataAccessPane.class);
    dataAccessTabPane = mock(DataAccessTabPane.class);
    tabPane = mock(TabPane.class);
    graphManager = mock(GraphManager.class);
    activeGraph = mock(Graph.class);
    when(dataAccessPane.getParentComponent()).thenReturn(dataAccessViewTopComponent);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
    when(dataAccessViewTopComponent.getExecutorService()).thenReturn(Executors.newSingleThreadExecutor());
    executeListener = new ExecuteListener(dataAccessPane);
    graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
    when(graphManager.getActiveGraph()).thenReturn(activeGraph);
    when(activeGraph.getId()).thenReturn(GRAPH_ID);
    // Intercept the plugin execution run calls and run the plugins manually
    // so that it executes within the same thread and sequentially for the test
    pluginExecution = mock(PluginExecution.class);
    pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(SimplePlugin.class))).thenAnswer(iom -> {
        final SimplePlugin plugin = iom.getArgument(0);
        final PluginGraphs graphs = mock(PluginGraphs.class);
        when(graphs.getGraph()).thenReturn(null);
        final PluginInteraction pluginInteraction = mock(PluginInteraction.class);
        final PluginParameters pluginParameters = mock(PluginParameters.class);
        // This will call the execute method of the simple plugin
        plugin.run(graphs, pluginInteraction, pluginParameters);
        return pluginExecution;
    });
    // Intercept calls to start the wait for tasks so that they don't run
    completableFutureMockedStatic.when(() -> CompletableFuture.runAsync(any(WaitForQueriesToCompleteTask.class), any(ExecutorService.class))).thenReturn(null);
    notificationDisplayer = mock(NotificationDisplayer.class);
    notificationDisplayerMockedStatic.when(NotificationDisplayer::getDefault).thenReturn(notificationDisplayer);
    when(notificationDisplayer.notify(anyString(), any(Icon.class), anyString(), isNull())).thenReturn(null);
    statusDisplayer = mock(StatusDisplayer.class);
    statusDisplayerMockedStatic.when(StatusDisplayer::getDefault).thenReturn(statusDisplayer);
    DataAccessPaneState.clearState();
}
Also used : TabPane(javafx.scene.control.TabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) WaitForQueriesToCompleteTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask) StatusDisplayer(org.openide.awt.StatusDisplayer) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ExecutorService(java.util.concurrent.ExecutorService) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) NotificationDisplayer(org.openide.awt.NotificationDisplayer) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Icon(javax.swing.Icon) DataAccessViewTopComponent(au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with PluginGraphs

use of au.gov.asd.tac.constellation.plugins.PluginGraphs in project constellation by constellation-app.

the class SaveTemplateAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final Plugin plugin = PluginRegistry.get(GraphNodePluginRegistry.SAVE_TEMPLATE);
    final PluginParameters params = plugin.createParameters();
    while (true) {
        final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_SaveTemplateAction(), params);
        dialog.showAndWait();
        if (PluginParametersDialog.OK.equals(dialog.getResult())) {
            if (NewSchemaGraphAction.getTemplateNames().containsKey(params.getStringValue(SaveTemplatePlugin.TEMPLATE_NAME_PARAMETER_ID))) {
                final PluginParameters warningParams = new PluginParameters();
                final PluginParameter<StringParameterValue> warningMessageParam = StringParameterType.build("");
                warningMessageParam.setName("");
                warningMessageParam.setStringValue("Warning template with that name already exists - really overwrite?");
                StringParameterType.setIsLabel(warningMessageParam, true);
                warningParams.addParameter(warningMessageParam);
                final PluginParametersSwingDialog overwrite = new PluginParametersSwingDialog("Overwrite?", warningParams);
                overwrite.showAndWait();
                if (!PluginParametersDialog.OK.equals(overwrite.getResult())) {
                    continue;
                }
            }
            Future<?> f = PluginExecution.withPlugin(plugin).withParameters(params).executeLater(context.getGraph());
            PluginExecution.withPlugin(new SimplePlugin() {

                @Override
                public String getName() {
                    return "Update Template Menu";
                }

                @Override
                protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
                    NewSchemaGraphAction.recreateTemplateMenuItems();
                }
            }).waitingFor(f).executeLater(null);
        }
        break;
    }
}
Also used : PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) PluginParametersSwingDialog(au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)

Example 4 with PluginGraphs

use of au.gov.asd.tac.constellation.plugins.PluginGraphs in project constellation by constellation-app.

the class DefaultPluginEnvironment method executePluginLater.

@Override
public Future<?> executePluginLater(final Graph graph, final Plugin plugin, final PluginParameters parameters, final boolean interactive, final List<Future<?>> async, final PluginSynchronizer synchronizer) {
    if (graph == null) {
        LOGGER.log(Level.INFO, GRAPH_NULL_WARNING_MESSAGE, plugin.getName());
    }
    return getPluginExecutor().submit(() -> {
        Thread.currentThread().setName(THREAD_POOL_NAME);
        // vertices have been relocated is not sensible.
        if (async != null) {
            for (final Future<?> future : async) {
                if (future != null) {
                    try {
                        future.get();
                    } catch (final InterruptedException ex) {
                        LOGGER.log(Level.SEVERE, "Execution interrupted", ex);
                        Thread.currentThread().interrupt();
                    } catch (final ExecutionException ex) {
                        LOGGER.log(Level.SEVERE, "Execution Exception", ex);
                    }
                }
            }
        }
        final ThreadConstraints callingConstraints = ThreadConstraints.getConstraints();
        final boolean alwaysSilent = callingConstraints.isAlwaysSilent() || callingConstraints.getSilentCount() > 0;
        PluginReport currentReport = null;
        final GraphReport graphReport = graph == null ? null : GraphReportManager.getGraphReport(graph.getId());
        if (graphReport != null) {
            currentReport = graphReport.addPluginReport(plugin);
            callingConstraints.setCurrentReport(currentReport);
        }
        try {
            ConstellationLogger.getDefault().pluginStarted(plugin, parameters, graph);
        } catch (final Exception ex) {
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
        }
        final PluginManager manager = new PluginManager(DefaultPluginEnvironment.this, plugin, graph, interactive, synchronizer);
        final PluginGraphs graphs = new DefaultPluginGraphs(manager);
        final PluginInteraction interaction = new DefaultPluginInteraction(manager, currentReport);
        try {
            if (parameters != null) {
                plugin.updateParameters(graph, parameters);
            }
            if (interactive && parameters != null) {
                if (interaction.prompt(plugin.getName(), parameters)) {
                    ThreadConstraints calledConstraints = ThreadConstraints.getConstraints();
                    calledConstraints.setAlwaysSilent(alwaysSilent);
                    try {
                        plugin.run(graphs, interaction, parameters);
                    } finally {
                        calledConstraints.setAlwaysSilent(false);
                        calledConstraints.setSilentCount(0);
                        if (synchronizer != null) {
                            synchronizer.finished();
                        }
                    }
                }
            } else {
                final ThreadConstraints calledConstraints = ThreadConstraints.getConstraints();
                calledConstraints.setAlwaysSilent(alwaysSilent);
                try {
                    plugin.run(graphs, interaction, parameters);
                } finally {
                    calledConstraints.setAlwaysSilent(false);
                    calledConstraints.setSilentCount(0);
                    if (synchronizer != null) {
                        synchronizer.finished();
                    }
                }
            }
        } catch (final InterruptedException ex) {
            auditPluginError(plugin, ex);
            reportException(plugin.getName(), interaction, currentReport, null, ex);
            Thread.currentThread().interrupt();
        } catch (final PluginException ex) {
            auditPluginError(plugin, ex);
            reportException(plugin.getName(), interaction, currentReport, ex.getNotificationLevel(), ex);
        } catch (final Exception ex) {
            auditPluginError(plugin, ex);
            reportException(plugin.getName(), interaction, currentReport, PluginNotificationLevel.ERROR, ex);
        } finally {
            if (currentReport != null) {
                currentReport.stop();
                callingConstraints.setCurrentReport(null);
                currentReport.firePluginReportChangedEvent();
            }
            try {
                ConstellationLogger.getDefault().pluginStopped(plugin, parameters);
            } catch (final Exception ex) {
                LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
            }
        }
        return null;
    });
}
Also used : PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) GraphReport(au.gov.asd.tac.constellation.plugins.reporting.GraphReport) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ExecutionException(java.util.concurrent.ExecutionException) PluginReport(au.gov.asd.tac.constellation.plugins.reporting.PluginReport) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with PluginGraphs

use of au.gov.asd.tac.constellation.plugins.PluginGraphs in project constellation by constellation-app.

the class ManageTemplatesAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final Plugin plugin = PluginRegistry.get(GraphNodePluginRegistry.MANAGE_TEMPLATES);
    final PluginParameters params = plugin.createParameters();
    final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_ManageTemplatesAction(), params);
    dialog.showAndWait();
    if (PluginParametersDialog.OK.equals(dialog.getResult())) {
        Future<?> f = PluginExecution.withPlugin(plugin).withParameters(params).executeLater(null);
        PluginExecution.withPlugin(new SimplePlugin() {

            @Override
            public String getName() {
                return "Update Template Menu";
            }

            @Override
            protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
                NewSchemaGraphAction.recreateTemplateMenuItems();
            }
        }).waitingFor(f).executeLater(null);
    }
}
Also used : PluginParametersSwingDialog(au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)

Aggregations

PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)10 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)10 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)8 SimplePlugin (au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)7 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)6 Graph (au.gov.asd.tac.constellation.graph.Graph)3 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)3 ExecutionException (java.util.concurrent.ExecutionException)3 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)2 PluginNotificationLevel (au.gov.asd.tac.constellation.plugins.PluginNotificationLevel)2 PluginParametersSwingDialog (au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog)2 GraphReport (au.gov.asd.tac.constellation.plugins.reporting.GraphReport)2 PluginReport (au.gov.asd.tac.constellation.plugins.reporting.PluginReport)2 WaitForQueriesToCompleteTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask)2 File (java.io.File)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1