Search in sources :

Example 71 with Element

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

the class LocationControlImpl method move.

@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations) {
    if (elements.length != locations.length) {
        throw new IllegalArgumentException("The length for the elements to move " + "does not match the locations provided.");
    }
    Command<AbstractCanvasHandler, CanvasViolation> command;
    if (elements.length == 1) {
        command = createMoveCommand(elements[0], locations[0]);
    } else {
        final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward();
        int i = 0;
        for (final Element element : elements) {
            final CanvasCommand<AbstractCanvasHandler> c = createMoveCommand(element, locations[i]);
            builder.addCommand(c);
            i++;
        }
        command = builder.build();
    }
    CommandResult<CanvasViolation> result = getCommandManager().allow(canvasHandler, command);
    if (!CommandUtils.isError(result)) {
        result = getCommandManager().execute(canvasHandler, command);
        if (!CommandUtils.isError(result)) {
            List<String> uuids = Arrays.stream(elements).map(Element::getUUID).collect(Collectors.toList());
            shapeLocationsChangedEvent.fire(new ShapeLocationsChangedEvent(uuids, canvasHandler));
        }
    }
    return result;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Element(org.kie.workbench.common.stunner.core.graph.Element) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) ShapeLocationsChangedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)

Example 72 with Element

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

the class TreeExplorer method onElementAdded.

private void onElementAdded(Element element) {
    if (isValidTreeItem().test(element)) {
        final Element parent = GraphUtils.getParent((Node<?, ? extends Edge>) element);
        addItem(parent, (Node) element, true, true);
    }
}
Also used : IsElement(org.jboss.errai.common.client.api.IsElement) Element(org.kie.workbench.common.stunner.core.graph.Element)

Example 73 with Element

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

the class TreeExplorer method onElementUpdated.

@SuppressWarnings("unchecked")
private void onElementUpdated(Element element, CanvasHandler canvasHandler) {
    if (isValidTreeItem().test(element)) {
        final Element lane = GraphUtils.getParent((Node<?, ? extends Edge>) element);
        if (view.isItemChanged(element.getUUID(), null != lane ? lane.getUUID() : null, getItemName(element))) {
            view.removeItem(element.getUUID());
            addItem(lane, (Node) element, true, true);
            final boolean hasChildren = GraphUtils.hasChildren((Node<?, ? extends Edge>) element);
            if (hasChildren) {
                childrenTraverseProcessor.setRootUUID(element.getUUID()).traverse(canvasHandler.getDiagram().getGraph(), new AbstractChildrenTraverseCallback<Node<org.kie.workbench.common.stunner.core.graph.content.view.View, Edge>, Edge<Child, Node>>() {

                    @Override
                    public boolean startNodeTraversal(final List<Node<org.kie.workbench.common.stunner.core.graph.content.view.View, Edge>> parents, final Node<org.kie.workbench.common.stunner.core.graph.content.view.View, Edge> node) {
                        super.startNodeTraversal(parents, node);
                        addItem(parents.get(parents.size() - 1), node, true, false);
                        return true;
                    }

                    @Override
                    public void startNodeTraversal(final Node<org.kie.workbench.common.stunner.core.graph.content.view.View, Edge> node) {
                        super.startNodeTraversal(node);
                        addItem(node, true, false);
                    }
                });
            }
        }
    }
}
Also used : IsElement(org.jboss.errai.common.client.api.IsElement) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) UberView(org.uberfire.client.mvp.UberView) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 74 with Element

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

the class SessionPreviewCanvasHandlerProxyTest method checkNotifyCanvasElementAddedDelegatesToWrapped.

@Test
public void checkNotifyCanvasElementAddedDelegatesToWrapped() {
    final Element candidate = mock(Element.class);
    proxy.notifyCanvasElementAdded(candidate);
    verify(wrapped).notifyCanvasElementAdded(eq(candidate));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Test(org.junit.Test)

Example 75 with Element

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

the class SessionPreviewCanvasHandlerProxyTest method checkIsCanvasRootDelegatesToWrapped.

@Test
public void checkIsCanvasRootDelegatesToWrapped() {
    final Element parent = mock(Element.class);
    proxy.isCanvasRoot(parent);
    verify(wrapped).isCanvasRoot(eq(parent));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Test(org.junit.Test)

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