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