Search in sources :

Example 36 with Plugin

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

the class TestParameterBuildingAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final Plugin plugin = new TestParameterBuildingPlugin();
    final PluginParameters pp = plugin.createParameters();
    final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_TestParameterBuildingAction(), pp);
    dialog.showAndWait();
    if (PluginParametersDialog.OK.equals(dialog.getResult())) {
        PluginExecution.withPlugin(plugin).withParameters(pp).executeLater(context.getGraph());
    }
}
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)

Example 37 with Plugin

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

the class TimelinePanel method initExclusionState.

protected void initExclusionState(final Graph graph, final String datetimeAttr, final long lowerTimeExtent, final long upperTimeExtent, final int exclusionState) {
    final Plugin initPlugin = clusteringManager.new InitDimOrHidePlugin(datetimeAttr, lowerTimeExtent, upperTimeExtent, exclusionState, (vxMod, txMod) -> {
        expectedvxMod = vxMod;
        expectedtxMod = txMod;
    });
    PluginExecution.withPlugin(initPlugin).executeLater(graph);
}
Also used : Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 38 with Plugin

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

the class BlazeActions method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final String command = e.getActionCommand();
    final Plugin plugin;
    final PluginParameters parameters;
    final Pair<BitSet, ConstellationColor> selectionResult = BlazeUtilities.getSelection(graph, null);
    switch(command) {
        case ADD_CUSTOM_BLAZE_ACTION:
            final Pair<Boolean, ConstellationColor> colorResult = BlazeUtilities.colorDialog(selectionResult.getValue());
            if (colorResult.getKey()) {
                final ConstellationColor color = colorResult.getValue();
                plugin = PluginRegistry.get(VisualGraphPluginRegistry.ADD_CUSTOM_BLAZE);
                parameters = DefaultPluginParameters.getDefaultParameters(plugin);
                parameters.getParameters().get(BlazeUtilities.VERTEX_IDS_PARAMETER_ID).setObjectValue(selectionResult.getKey());
                parameters.getParameters().get(BlazeUtilities.COLOR_PARAMETER_ID).setColorValue(color);
                PluginExecution.withPlugin(plugin).withParameters(parameters).executeLater(graph);
            }
            break;
        case SELECT_BLAZES_ACTION:
            PluginExecution.withPlugin(VisualGraphPluginRegistry.SELECT_BLAZES).executeLater(graph);
            break;
        case DESELECT_BLAZES_ACTION:
            PluginExecution.withPlugin(VisualGraphPluginRegistry.DESELECT_BLAZES).executeLater(graph);
            break;
        case REMOVE_BLAZES_ACTION:
            plugin = PluginRegistry.get(VisualGraphPluginRegistry.REMOVE_BLAZE);
            parameters = DefaultPluginParameters.getDefaultParameters(plugin);
            parameters.getParameters().get(BlazeUtilities.VERTEX_IDS_PARAMETER_ID).setObjectValue(selectionResult.getKey());
            PluginExecution.withPlugin(plugin).withParameters(parameters).executeLater(graph);
            break;
        default:
            // ADD_PRESET_BLAZE_ACTION has the string representation of the color
            if (command.startsWith(ADD_PRESET_BLAZE_ACTION)) {
                final String colorValStr = command.replaceFirst(ADD_PRESET_BLAZE_ACTION, "");
                final ConstellationColor color = ConstellationColor.fromHtmlColor(colorValStr) == null ? ConstellationColor.getColorValue(colorValStr) : ConstellationColor.fromHtmlColor(colorValStr);
                plugin = PluginRegistry.get(VisualGraphPluginRegistry.ADD_CUSTOM_BLAZE);
                parameters = DefaultPluginParameters.getDefaultParameters(plugin);
                parameters.getParameters().get(BlazeUtilities.VERTEX_IDS_PARAMETER_ID).setObjectValue(selectionResult.getKey());
                parameters.getParameters().get(BlazeUtilities.COLOR_PARAMETER_ID).setColorValue(color);
                PluginExecution.withPlugin(plugin).withParameters(parameters).executeLater(graph);
            }
            break;
    }
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) BitSet(java.util.BitSet) DefaultPluginParameters(au.gov.asd.tac.constellation.plugins.parameters.DefaultPluginParameters) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 39 with Plugin

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

the class AddRecordStore method addToGraph.

private static void addToGraph(final Graph graph, final RecordStore recordStore, final boolean completeWithSchema, final String arrange, final boolean resetView) {
    final Plugin p = new ImportFromRestApiPlugin(recordStore, completeWithSchema, arrange);
    PluginExecutor pe = PluginExecutor.startWith(p);
    if (resetView) {
        pe = pe.followedBy(InteractiveGraphPluginRegistry.RESET_VIEW);
    }
    try {
        pe.executeNow(graph);
    } catch (final InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new RestServiceException(ex);
    } catch (final PluginException ex) {
        throw new RestServiceException(ex);
    }
}
Also used : RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) PluginExecutor(au.gov.asd.tac.constellation.plugins.PluginExecutor) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 40 with Plugin

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

the class RunPlugins method callService.

@Override
public void callService(final PluginParameters parameters, InputStream in, OutputStream out) throws IOException {
    final String graphId = parameters.getStringValue(GRAPH_ID_PARAMETER_ID);
    final Graph graph = graphId == null ? RestUtilities.getActiveGraph() : GraphNode.getGraph(graphId);
    if (graph == null) {
        throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, "No graph with id " + graphId);
    }
    final String runStyle = parameters.getStringValue(RUN_IN_PARAMETER_ID);
    if (!RUN_STYLE_SERIES.equals(runStyle) && !RUN_STYLE_PARALLEL.equals(runStyle)) {
        final String msg = String.format("%s must be '%s' or '%s'", RUN_IN_PARAMETER_ID, RUN_STYLE_SERIES, RUN_STYLE_PARALLEL);
        throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, msg);
    }
    // First, collect all the plugins and their optional arguments.
    // 
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode json = mapper.readTree(in);
    if (!json.isArray()) {
        final String msg = String.format("Argument for %s must be a list", NAME);
        throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, msg);
    }
    final ConcurrentLinkedQueue<PluginError> errorQueue = new ConcurrentLinkedQueue<>();
    final ArrayNode pluginList = (ArrayNode) json;
    final List<PluginInstance> pluginInstances = new ArrayList<>();
    pluginList.forEach(pluginItem -> {
        if (!pluginItem.has(PLUGIN_NAME) || !pluginItem.get(PLUGIN_NAME).isTextual()) {
            final String msg = String.format("Each plugin argument must have %s", PLUGIN_NAME);
            throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, msg);
        }
        final String pluginName = pluginItem.get(PLUGIN_NAME).textValue();
        final Plugin plugin = PluginRegistry.get(pluginName);
        final PluginParameters pluginParameters = plugin.createParameters();
        if (pluginParameters != null && pluginItem.has(PLUGIN_ARGS)) {
            final ObjectNode pluginArgs = (ObjectNode) pluginItem.get(PLUGIN_ARGS);
            RestServiceUtilities.parametersFromJson(pluginArgs, pluginParameters);
        }
        pluginInstances.add(new PluginInstance(graph, plugin, pluginParameters, errorQueue));
    });
    // 
    if (runStyle.equals(RUN_STYLE_SERIES)) {
        pluginInstances.forEach(PluginInstance::run);
    } else {
        final List<Thread> pluginThreads = new ArrayList<>();
        pluginInstances.forEach(pi -> {
            final Thread thread = new Thread(pi, pi.plugin.getName());
            pluginThreads.add(thread);
            thread.start();
        });
        pluginThreads.forEach(thread -> {
            try {
                thread.join();
            } catch (final InterruptedException ex) {
                thread.interrupt();
                errorQueue.add(new PluginError(String.format("Thread %s", thread.getName()), ex));
            }
        });
    }
    // The plugins have finished, so look at the error queue to see if anything
    // didn't work. If there are errors, pass them back.
    // 
    final StringBuilder buf = new StringBuilder();
    while (!errorQueue.isEmpty()) {
        buf.append(errorQueue.remove().toString());
    }
    if (buf.length() > 0) {
        throw new RestServiceException(buf.toString());
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) Graph(au.gov.asd.tac.constellation.graph.Graph) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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