Search in sources :

Example 96 with Definition

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;
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) LinkedList(java.util.LinkedList)

Example 97 with Definition

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();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Collection(java.util.Collection) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 98 with Definition

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();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DockingRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.DockingRuleViolation) DockingRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.DockingRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 99 with Definition

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();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) LinkedList(java.util.LinkedList)

Example 100 with Definition

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();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)111 Node (org.kie.workbench.common.stunner.core.graph.Node)61 Test (org.junit.Test)46 Element (org.kie.workbench.common.stunner.core.graph.Element)31 Edge (org.kie.workbench.common.stunner.core.graph.Edge)25 Graph (org.kie.workbench.common.stunner.core.graph.Graph)20 ArrayList (java.util.ArrayList)16 Optional (java.util.Optional)14 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)14 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)11 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)10 List (java.util.List)9 Before (org.junit.Before)9 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)9 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)9 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)9 Stream (java.util.stream.Stream)8