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();
}
}
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();
}
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;
}
}
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);
}
}
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);
}
Aggregations