use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class ResizeNodeCommand method getResizeCommands.
/**
* It provides the necessary canvas commands in order to update the domain model with new values that will met
* the new bounding box size.
* It always updates the element's position, as resize can update it, and it updates as well some of the bean's properties.
*/
private List<Command<AbstractCanvasHandler, CanvasViolation>> getResizeCommands(final AbstractCanvasHandler canvasHandler, final double w, final double h) {
final Definition content = candidate.getContent();
final Object def = content.getDefinition();
final DefinitionAdapter<Object> adapter = canvasHandler.getDefinitionManager().adapters().registry().getDefinitionAdapter(def.getClass());
final List<Command<AbstractCanvasHandler, CanvasViolation>> result = new LinkedList<>();
final String widthField = adapter.getMetaPropertyField(def, PropertyMetaTypes.WIDTH);
if (null != widthField) {
appendCommandForModelProperty(canvasHandler, widthField, w, result);
}
final String heightField = adapter.getMetaPropertyField(def, PropertyMetaTypes.HEIGHT);
if (null != heightField) {
appendCommandForModelProperty(canvasHandler, heightField, h, result);
}
final String radiusField = adapter.getMetaPropertyField(def, PropertyMetaTypes.RADIUS);
if (null != radiusField) {
final double r = w > h ? (h / 2) : (w / 2);
appendCommandForModelProperty(canvasHandler, radiusField, r, result);
}
return result;
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class SetChildrenCommand method check.
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
final Collection candidates = getCandidates(context);
final Collection<RuleViolation> containmentRuleViolations = evaluate(context, contextBuilder -> contextBuilder.containment(parent, candidates));
return new GraphCommandResultBuilder(containmentRuleViolations).build();
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition 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);
// check if the candidate has connections
if (GraphUtils.hasTargetConnections(candidate)) {
return new GraphCommandResultBuilder().addViolation(new DockingRuleViolation(parent.getUUID(), candidate.getUUID())).build();
}
// checking rules
final Collection<RuleViolation> dockingRuleViolations = evaluate(context, contextBuilder -> contextBuilder.docking(parent, candidate));
return new GraphCommandResultBuilder(dockingRuleViolations).build();
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class AddChildNodeCommand method allow.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> allow(final GraphCommandExecutionContext context) {
ensureInitialized(context);
final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
final Collection<RuleViolation> containmentRuleViolations = evaluate(context, contextBuilder -> contextBuilder.containment(parent, candidate));
final Collection<RuleViolation> cardinalityRuleViolations = evaluate(context, contextBuilder -> contextBuilder.cardinality(Collections.singleton(candidate), CardinalityContext.Operation.ADD));
final Collection<RuleViolation> violations = new LinkedList<RuleViolation>();
violations.addAll(containmentRuleViolations);
violations.addAll(cardinalityRuleViolations);
return new GraphCommandResultBuilder(violations).build();
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class SetParentNodeCommand 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> containmentRuleViolations = evaluate(context, contextBuilder -> contextBuilder.containment(parent, candidate));
return new GraphCommandResultBuilder(containmentRuleViolations).build();
}
Aggregations