use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AddControlPointCommand method execute.
@Override
public CommandResult<RuleViolation> execute(GraphCommandExecutionContext context) {
if (checkExistingControlPoints(getEdgeContent().getControlPoints())) {
// skipping in case adding already existing control points
return GraphCommandResultBuilder.SUCCESS;
}
CommandResult<RuleViolation> allowResult = allow(context);
if (CommandUtils.isError(allowResult)) {
return allowResult;
}
HasControlPoints edgeContent = getEdgeContent();
if (Objects.isNull(edgeContent.getControlPoints())) {
edgeContent.setControlPoints(new LinkedList<>());
}
// add on the right index position on the list
getControlPointList().stream().forEach(cp -> {
// the effective index should not consider the head point that is a control point on the connector
int effectiveIndex = cp.getIndex() - 1;
if (edgeContent.getControlPoints().size() > effectiveIndex) {
edgeContent.getControlPoints().add(effectiveIndex, cp);
} else {
edgeContent.getControlPoints().add(cp);
}
});
// update index control points
updateControlPointsIndex(edgeContent.getControlPoints());
return GraphCommandResultBuilder.SUCCESS;
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class DeregisterNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
// And check it really exist on the graph storage as well.
final org.kie.workbench.common.stunner.core.graph.Graph graph = getGraph(context);
final Node<View<?>, Edge> candidate = (Node<View<?>, Edge>) checkCandidateNotNull(context);
final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(graph, Optional.of(candidate), Optional.of(CardinalityContext.Operation.DELETE)));
builder.addViolations(cardinalityRuleViolations);
return builder.build();
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class DockNodeCommand method execute.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> results = allow(context);
if (!results.getType().equals(CommandResult.Type.ERROR)) {
final Node<?, Edge> parent = getParent(context);
final Node<?, Edge> candidate = getCandidate(context);
final String uuid = UUID.uuid();
final Edge<Dock, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Dock());
edge.setSourceNode(parent);
edge.setTargetNode(candidate);
parent.getOutEdges().add(edge);
candidate.getInEdges().add(edge);
getMutableIndex(context).addEdge(edge);
}
return results;
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class DockNodeCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
final Node<Definition<?>, Edge> candidate = (Node<Definition<?>, Edge>) getCandidate(context);
final Collection<RuleViolation> dockingRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.docking(getGraph(context), parent, candidate));
return new GraphCommandResultBuilder(dockingRuleViolations).build();
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class MorphNodeCommand method execute.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> results = allow(context);
if (!results.getType().equals(CommandResult.Type.ERROR)) {
final DefinitionManager definitionManager = context.getDefinitionManager();
final Object currentDef = candidate.getContent().getDefinition();
final String currentDefId = definitionManager.adapters().forDefinition().getId(currentDef);
this.oldMorphTarget = currentDefId;
final MorphAdapter<Object> morphAdapter = context.getDefinitionManager().adapters().registry().getMorphAdapter(currentDef.getClass());
if (null == morphAdapter) {
throw new RuntimeException("No morph adapter found for definition [" + currentDef.toString() + "] " + "and target morph [" + morphTarget + "]");
}
final Object newDef = morphAdapter.morph(currentDef, morphDefinition, morphTarget);
if (null == newDef) {
throw new RuntimeException("No morph resulting Definition. [ morphSource=" + currentDefId + ", " + "morphTarget=" + morphTarget + "]");
}
// Morph the node definition to the new one.
candidate.getContent().setDefinition(newDef);
// Update candidate roles.
final Set<String> newLabels = definitionManager.adapters().forDefinition().getLabels(newDef);
candidate.getLabels().clear();
if (null != newLabels) {
candidate.getLabels().addAll(newLabels);
}
}
return results;
}
Aggregations