Search in sources :

Example 11 with GraphCommandResultBuilder

use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder in project kie-wb-common by kiegroup.

the class UpdateElementPositionCommand method checkBounds.

@SuppressWarnings("unchecked")
private CommandResult<RuleViolation> checkBounds(final GraphCommandExecutionContext context) {
    final Element<? extends View<?>> element = getNodeNotNull(context);
    final Graph<DefinitionSet, Node> graph = (Graph<DefinitionSet, Node>) getGraph(context);
    final BoundsImpl newBounds = getTargetBounds(element);
    final GraphCommandResultBuilder result = new GraphCommandResultBuilder();
    final Bounds parentBounds = getParentBounds(element, graph);
    if (GraphUtils.checkBoundsExceeded(parentBounds, newBounds)) {
        ((View) element.getContent()).setBounds(newBounds);
    } else {
        result.addViolation(new BoundsExceededViolation(parentBounds).setUUID(element.getUUID()));
    }
    return result.build();
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)11 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)10 Node (org.kie.workbench.common.stunner.core.graph.Node)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)7 Element (org.kie.workbench.common.stunner.core.graph.Element)5 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)3 LinkedList (java.util.LinkedList)1 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)1 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)1 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)1 BoundsExceededViolation (org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation)1