Search in sources :

Example 56 with Element

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

the class ClientFactoryServicesTest method testNewElementLocal.

@Test
@SuppressWarnings("unchecked")
public void testNewElementLocal() {
    String id = "id1";
    String defSetId = "defSet1";
    ServiceCallback<Element> callback = mock(ServiceCallback.class);
    Element def = mock(Element.class);
    when(clientFactoryManager.newElement(eq(id), eq(defSetId))).thenReturn(def);
    tested.newElement(id, defSetId, callback);
    verify(callback, times(1)).onSuccess(eq(def));
    verify(clientFactoryManager, times(1)).newElement(eq(id), eq(defSetId));
    verify(clientFactoryManager, times(0)).newElement(anyString(), any(Class.class));
    verify(factoryService, times(0)).newElement(anyString(), anyString());
    verify(factoryService, times(0)).newElement(anyString(), any(Class.class));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 57 with Element

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

the class AddChildNodeCommand method allow.

@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> allow(final GraphCommandExecutionContext context) {
    ensureInitialized(context);
    // Check if rules are present.
    if (null == context.getRuleManager()) {
        return GraphCommandResultBuilder.SUCCESS;
    }
    final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
    final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), parent, candidate));
    final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(getGraph(context), Optional.of(candidate), Optional.of(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 58 with Element

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

the class CanvasControlRegistrationHandler method initializeListeners.

private void initializeListeners() {
    // Canvas listeners.
    final C canvas = getCanvas();
    this.shapeListener = new CanvasShapeListener() {

        @Override
        public void register(final Shape item) {
            onRegisterShape(item);
        }

        @Override
        public void deregister(final Shape item) {
            onDeregisterShape(item);
        }

        @Override
        public void clear() {
            onClear();
        }
    };
    canvas.addRegistrationListener(shapeListener);
    // Canvas handler listeners.
    this.elementListener = new CanvasElementListener() {

        @Override
        public void update(final Element item) {
            onElementRegistration(item, false, true);
        }

        @Override
        public void register(final Element item) {
            onRegisterElement(item);
        }

        @Override
        public void deregister(final Element item) {
            onDeregisterElement(item);
        }

        @Override
        public void clear() {
            onClear();
        }
    };
    getCanvasHandler().addRegistrationListener(elementListener);
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) CanvasElementListener(org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasElementListener) Element(org.kie.workbench.common.stunner.core.graph.Element) CanvasShapeListener(org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasShapeListener)

Example 59 with Element

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

the class CanvasLayoutUtils method getNext.

public Point2D getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final double rootNodeWidth, final double rootNodeHeight, final double newNodeWidth, final double newNodeHeight, Point2D offset, Point2D rootNodeCoordinates) {
    checkNotNull("canvasHandler", canvasHandler);
    checkNotNull("root", root);
    final int canvasHeight = canvasHandler.getCanvas().getHeight();
    final int canvasWidth = canvasHandler.getCanvas().getWidth();
    Point2D newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
    graphBoundsIndexer.build(canvasHandler.getDiagram().getGraph());
    Element parentNode = GraphUtils.getParent(root.asNode());
    boolean checkParent = false;
    if (parentNode != null) {
        if (!(isCanvasRoot(canvasHandler.getDiagram(), parentNode.getUUID()))) {
            checkParent = true;
        }
    }
    Node targetNodeContainer = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
    boolean canContain = false;
    if (targetNodeContainer != null) {
        canContain = canContain(canvasHandler, targetNodeContainer, root);
    }
    if ((!canContain) || isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight) || checkParent) {
        if (checkParent) {
            newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
        }
        while (((!isCanvasPositionAvailable(graphBoundsIndexer, newPositionUL, newNodeWidth, newNodeHeight, parentNode)) && !canContain) && (newPositionUL.getY() < canvasHeight) && (newPositionUL.getX() < canvasWidth) || isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight)) {
            parentNode = GraphUtils.getParent(root.asNode());
            checkParent = false;
            if (parentNode != null) {
                if (!(isCanvasRoot(canvasHandler.getDiagram(), parentNode.getUUID()))) {
                    checkParent = true;
                }
            }
            double[] nodeAtPositionSize;
            nodeAtPositionSize = getNodeSizeAt(graphBoundsIndexer, newPositionUL, newNodeWidth, newNodeHeight, parentNode);
            if (checkParent) {
                final Node targetNodeNewPos = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
                if (parentNode != targetNodeNewPos) {
                    offset.setY(offset.getY() + PADDING_Y);
                }
            } else {
                if (nodeAtPositionSize == null) {
                    nodeAtPositionSize = new double[] { 0.0d };
                    offset.setY(offset.getY() + PADDING_Y);
                } else {
                    offset.setY(offset.getY() + nodeAtPositionSize[1] + PADDING_Y);
                }
            }
            newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
            if (isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight)) {
                rootNodeCoordinates.setY(0);
                offset.setY(PADDING_Y);
                offset.setX(offset.getX() + nodeAtPositionSize[0] + PADDING_X);
                newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
            }
            if (checkParent) {
                newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
            }
            targetNodeContainer = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
            canContain = targetNodeContainer == null || canContain(canvasHandler, targetNodeContainer, root);
        }
    } else {
        if (checkParent) {
            newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
        } else {
            newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
        }
    }
    return newPositionUL;
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node)

Example 60 with Element

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

the class CreateNodeAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Obtain the connector and source node instances for proxying.
    final Element<View<?>> element = (Element<View<?>>) getElement(canvasHandler, uuid);
    final Node<View<?>, Edge> sourceNode = element.asNode();
    final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager.newElement(UUID.uuid(), edgeId).asEdge();
    final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager.newElement(UUID.uuid(), nodeId).asNode();
    final DeferredCompositeCommand.Builder builder = new DeferredCompositeCommand.Builder().deferCommand(() -> addNode(canvasHandler, sourceNode, targetNode)).deferCommand(() -> updateNodeLocation(canvasHandler, sourceNode, targetNode)).deferCommand(() -> addEdge(canvasHandler, sourceNode, connector)).deferCommand(() -> setEdgeTarget(canvasHandler, connector, targetNode));
    final CommandResult result = sessionCommandManager.execute(canvasHandler, builder.build());
    if (!CommandUtils.isError(result)) {
        fireElementSelectedEvent(selectionEvent, canvasHandler, targetNode.getUUID());
    }
    return this;
}
Also used : DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult)

Aggregations

Element (org.kie.workbench.common.stunner.core.graph.Element)85 Test (org.junit.Test)55 View (org.kie.workbench.common.stunner.core.graph.content.view.View)34 Graph (org.kie.workbench.common.stunner.core.graph.Graph)27 FlowElement (org.eclipse.bpmn2.FlowElement)24 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)24 RootElement (org.eclipse.bpmn2.RootElement)24 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)24 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Map (java.util.Map)7 Optional (java.util.Optional)6 Before (org.junit.Before)6 Collection (java.util.Collection)5 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)5 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)5 Matchers.anyString (org.mockito.Matchers.anyString)5 Logger (java.util.logging.Logger)4 BPMNDiagram (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram)4