use of au.gov.asd.tac.constellation.plugins.PluginExecutor in project constellation by constellation-app.
the class RecordStoreQueryPlugin method edit.
@Override
protected void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
for (final RecordStoreValidator validator : getValidators()) {
validator.validatePreEdit(this, result, wg, interaction, parameters);
}
if (result != null) {
// TODO: try to see if its worth setting this to init with schema to true - it did cause issues with it sometimes generating vertex # nodes
final List<Integer> newVertices = GraphRecordStoreUtilities.addRecordStoreToGraph(wg, result, false, true, null);
wg.validateKey(GraphElementType.VERTEX, true);
wg.validateKey(GraphElementType.TRANSACTION, true);
// Only arrange if there are new vertices, otherwise everything will be arranged.
if (!newVertices.isEmpty()) {
final PluginExecutor arrangement = completionArrangement();
if (arrangement != null) {
final float[] xOriginal = new float[wg.getVertexCount()];
final float[] yOriginal = new float[wg.getVertexCount()];
final float[] zOriginal = new float[wg.getVertexCount()];
// save original positions
if (wg.isRecordingEdit()) {
saveOriginalPositionCoordinates(wg, xOriginal, yOriginal, zOriginal);
}
// run the arrangement
final VertexListInclusionGraph vlGraph = new VertexListInclusionGraph(wg, Connections.NONE, newVertices);
arrangement.executeNow(vlGraph.getInclusionGraph());
vlGraph.retrieveCoords();
// restore the original positions
if (wg.isRecordingEdit()) {
restoreOriginalPositionCoordinates(wg, xOriginal, yOriginal, zOriginal);
}
}
}
// Reset the view
PluginExecutor.startWith(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(wg);
}
}
use of au.gov.asd.tac.constellation.plugins.PluginExecutor 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.PluginExecutor in project constellation by constellation-app.
the class PluginSequenceEditOperation method performEdit.
@Override
public void performEdit(final Object value) {
PluginExecutor executor = preEdit == null ? PluginExecutor.startWith(mainEdit(value)) : PluginExecutor.startWith(preEdit).followedBy(mainEdit(value));
if (postEdit != null) {
executor = executor.followedBy(postEdit);
}
executor.executeWriteLater(GraphManager.getDefault().getActiveGraph());
}
use of au.gov.asd.tac.constellation.plugins.PluginExecutor in project constellation by constellation-app.
the class SplitNodesPlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final Map<String, PluginParameter<?>> splitParameters = parameters.getParameters();
final String character = splitParameters.get(SPLIT_PARAMETER_ID) != null && splitParameters.get(SPLIT_PARAMETER_ID).getStringValue() != null ? splitParameters.get(SPLIT_PARAMETER_ID).getStringValue() : "";
final ParameterValue transactionTypeChoice = splitParameters.get(TRANSACTION_TYPE_PARAMETER_ID).getSingleChoice();
final String linkType = transactionTypeChoice != null ? transactionTypeChoice.toString() : AnalyticConcept.TransactionType.CORRELATION.getName();
final boolean allOccurrences = splitParameters.get(ALL_OCCURRENCES_PARAMETER_ID).getBooleanValue();
final boolean splitIntoSameLevel = splitParameters.get(DUPLICATE_TRANSACTIONS_PARAMETER_ID).getBooleanValue();
final int vertexSelectedAttributeId = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
final List<Integer> newVertices = new ArrayList<>();
final int graphVertexCount = graph.getVertexCount();
for (int position = 0; position < graphVertexCount; position++) {
final int currentVertexId = graph.getVertex(position);
if (graph.getBooleanValue(vertexSelectedAttributeId, currentVertexId)) {
final String identifier = graph.getStringValue(vertexIdentifierAttributeId, currentVertexId);
if (identifier != null && identifier.contains(character) && identifier.indexOf(character) < identifier.length() - character.length()) {
String leftNodeIdentifier = "";
if (allOccurrences) {
final String[] substrings = Arrays.stream(identifier.split(character)).filter(value -> value != null && value.length() > 0).toArray(size -> new String[size]);
if (substrings.length <= 0) {
continue;
}
leftNodeIdentifier = substrings[0];
for (int i = 1; i < substrings.length; i++) {
newVertices.add(createNewNode(graph, position, substrings[i], linkType, splitIntoSameLevel));
}
} else {
final int i = identifier.indexOf(character);
leftNodeIdentifier = identifier.substring(0, i);
if (StringUtils.isNotBlank(leftNodeIdentifier)) {
newVertices.add(createNewNode(graph, position, identifier.substring(i + 1), linkType, splitIntoSameLevel));
} else {
leftNodeIdentifier = identifier.substring(i + 1);
}
}
// Rename the selected node
if (StringUtils.isNotBlank(leftNodeIdentifier)) {
graph.setStringValue(vertexIdentifierAttributeId, currentVertexId, leftNodeIdentifier);
newVertices.add(currentVertexId);
}
}
}
}
if (!newVertices.isEmpty()) {
// Reset the view
graph.validateKey(GraphElementType.VERTEX, true);
graph.validateKey(GraphElementType.TRANSACTION, true);
final PluginExecutor arrangement = completionArrangement();
if (arrangement != null) {
// run the arrangement
final VertexListInclusionGraph vlGraph = new VertexListInclusionGraph(graph, AbstractInclusionGraph.Connections.NONE, newVertices);
arrangement.executeNow(vlGraph.getInclusionGraph());
vlGraph.retrieveCoords();
}
if (splitParameters.get(COMPLETE_WITH_SCHEMA_OPTION_ID).getBooleanValue()) {
PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
}
PluginExecutor.startWith(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
}
}
Aggregations