Search in sources :

Example 1 with SimplePlugin

use of au.gov.asd.tac.constellation.plugins.templates.SimplePlugin 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 SimplePlugin

use of au.gov.asd.tac.constellation.plugins.templates.SimplePlugin 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 SimplePlugin

use of au.gov.asd.tac.constellation.plugins.templates.SimplePlugin 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 SimplePlugin

use of au.gov.asd.tac.constellation.plugins.templates.SimplePlugin 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)

Example 5 with SimplePlugin

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

the class PluginReportPane method saveToClipboard.

/**
 * Saves a text representation of this PluginReport to the clipboard.
 */
private void saveToClipboard() {
    CharArrayWriter writer = new CharArrayWriter();
    try (PrintWriter out = new PrintWriter(writer)) {
        out.append("Name: " + pluginReport.getPluginName() + SeparatorConstants.NEWLINE);
        out.append("Description: " + pluginReport.getPluginDescription() + SeparatorConstants.NEWLINE);
        out.append("Message: " + pluginReport.getMessage() + SeparatorConstants.NEWLINE);
        out.append("Tags: " + Arrays.toString(pluginReport.getTags()) + SeparatorConstants.NEWLINE);
        out.append("Start: " + dateFormat.format(new Date(pluginReport.getStartTime())) + SeparatorConstants.NEWLINE);
        out.append("Stop: " + dateFormat.format(new Date(pluginReport.getStopTime())) + SeparatorConstants.NEWLINE);
        if (pluginReport.getError() != null) {
            out.append("Error: " + pluginReport.getError().getMessage() + "\n\n");
            pluginReport.getError().printStackTrace(out);
        }
    }
    final Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.putString(writer.toString());
    clipboard.setContent(content);
    // TODO: can't do this because of circular dependancy
    // ClipboardUtilities.copyToClipboard(writer.toString());
    PluginExecution.withPlugin(new SimplePlugin("Copy To Clipboard") {

        @Override
        protected void execute(PluginGraphs graphs, PluginInteraction interaction, PluginParameters parameters) throws InterruptedException, PluginException {
            ConstellationLoggerHelper.copyPropertyBuilder(this, writer.toString().length(), ConstellationLoggerHelper.SUCCESS);
        }
    }).executeLater(null);
}
Also used : PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) ClipboardContent(javafx.scene.input.ClipboardContent) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) Clipboard(javafx.scene.input.Clipboard) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) CharArrayWriter(java.io.CharArrayWriter) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Aggregations

PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)5 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)5 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)5 SimplePlugin (au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)5 Graph (au.gov.asd.tac.constellation.graph.Graph)2 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)2 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)2 PluginParametersSwingDialog (au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog)2 WaitForQueriesToCompleteTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 NewDefaultSchemaGraphAction (au.gov.asd.tac.constellation.graph.node.create.NewDefaultSchemaGraphAction)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)1 DataAccessViewTopComponent (au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent)1 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)1 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)1 CharArrayWriter (java.io.CharArrayWriter)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 Date (java.util.Date)1