Search in sources :

Example 26 with Edge

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

the class TaskConverter method scriptTask.

private BpmnNode scriptTask(org.eclipse.bpmn2.ScriptTask task) {
    Node<View<ScriptTask>, Edge> node = factoryManager.newNode(task.getId(), ScriptTask.class);
    ScriptTask definition = node.getContent().getDefinition();
    ScriptTaskPropertyReader p = propertyReaderFactory.of(task);
    definition.setGeneral(new TaskGeneralSet(new Name(p.getName()), new Documentation(p.getDocumentation())));
    definition.setExecutionSet(new ScriptTaskExecutionSet(new Script(p.getScript()), new IsAsync(p.isAsync())));
    node.getContent().setBounds(p.getBounds());
    definition.setDimensionsSet(p.getRectangleDimensionsSet());
    definition.setBackgroundSet(p.getBackgroundSet());
    definition.setFontSet(p.getFontSet());
    definition.setSimulationSet(p.getSimulationSet());
    return BpmnNode.of(node);
}
Also used : Script(org.kie.workbench.common.stunner.bpmn.definition.property.task.Script) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) Documentation(org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation) TaskGeneralSet(org.kie.workbench.common.stunner.bpmn.definition.property.general.TaskGeneralSet) IsAsync(org.kie.workbench.common.stunner.bpmn.definition.property.task.IsAsync) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ScriptTaskPropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.ScriptTaskPropertyReader) Name(org.kie.workbench.common.stunner.bpmn.definition.property.general.Name) TaskName(org.kie.workbench.common.stunner.bpmn.definition.property.task.TaskName) ScriptTaskExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTaskExecutionSet)

Example 27 with Edge

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

the class NodeDragProxyImpl method show.

@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, NodeDragProxyCallback> show(final Item item, final int x, final int y, final NodeDragProxyCallback callback) {
    final AbstractCanvas canvas = canvasHandler.getAbstractCanvas();
    final Node<View<?>, Edge> node = item.getNode();
    final ShapeFactory<Object, ?> nodeShapeFactory = item.getNodeShapeFactory();
    final Edge<View<?>, Node> inEdge = item.getInEdge();
    final Node<View<?>, Edge> inEdgeSourceNode = item.getInEdgeSourceNode();
    final ShapeFactory<Object, ?> edgeShapeFactory = item.getInEdgeShapeFactory();
    final Shape nodeShape = nodeShapeFactory.newShape(node.getContent().getDefinition());
    if (nodeShape instanceof ElementShape) {
        ((ElementShape) nodeShape).applyProperties(node, MutationContext.STATIC);
    }
    this.transientEdgeShape = (EdgeShape) edgeShapeFactory.newShape(inEdge.getContent().getDefinition());
    canvas.addTransientShape(this.transientEdgeShape);
    this.transientEdgeShape.applyProperties(inEdge, MutationContext.STATIC);
    final Shape<?> edgeSourceNodeShape = canvasHandler.getCanvas().getShape(inEdgeSourceNode.getUUID());
    shapeDragProxyFactory.show(nodeShape, x, y, new DragProxyCallback() {

        @Override
        public void onStart(final int x, final int y) {
            callback.onStart(x, y);
            drawEdge();
        }

        @Override
        public void onMove(final int x, final int y) {
            callback.onMove(x, y);
            drawEdge();
        }

        @Override
        public void onComplete(final int x, final int y) {
            final MagnetConnection[] connections = createShapeConnections();
            callback.onComplete(x, y);
            callback.onComplete(x, y, connections[0], connections[1]);
            deleteTransientEdgeShape();
            canvas.draw();
        }

        private void drawEdge() {
            if (inEdge.getContent() instanceof ViewConnector) {
                final ViewConnector viewConnector = (ViewConnector) inEdge.getContent();
                final MagnetConnection[] connections = createShapeConnections();
                viewConnector.setSourceConnection(connections[0]);
                viewConnector.setTargetConnection(connections[1]);
            }
            NodeDragProxyImpl.this.transientEdgeShape.applyConnections(inEdge, edgeSourceNodeShape.getShapeView(), nodeShape.getShapeView(), MutationContext.STATIC);
            canvas.draw();
        }

        private MagnetConnection[] createShapeConnections() {
            return new MagnetConnection[] { MagnetConnection.Builder.forElement(inEdgeSourceNode), MagnetConnection.Builder.forElement(node) };
        }
    });
    return this;
}
Also used : ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 28 with Edge

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

the class CreateConnectorAction method showDragProxy.

@SuppressWarnings("unchecked")
private DragProxy<AbstractCanvasHandler, ConnectorDragProxy.Item, DragProxyCallback> showDragProxy(final AbstractCanvasHandler canvasHandler, final Edge<? extends ViewConnector<?>, Node> connector, final Node<? extends View<?>, Edge> sourceNode, final int x, final int y) {
    // Built and show the drag proxy.
    final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
    final ShapeFactory shapeFactory = canvasHandler.getShapeFactory(ssid);
    final ConnectorDragProxy.Item connectorDragItem = new ConnectorDragProxy.Item() {

        @Override
        public Edge<? extends ViewConnector<?>, Node> getEdge() {
            return connector;
        }

        @Override
        public Node<? extends View<?>, Edge> getSourceNode() {
            return sourceNode;
        }

        @Override
        public ShapeFactory<?, ?> getShapeFactory() {
            return shapeFactory;
        }
    };
    return connectorDragProxyFactory.proxyFor(canvasHandler).show(connectorDragItem, x, y, new DragProxyCallback() {

        @Override
        public void onStart(final int x, final int y) {
            start(canvasHandler);
        }

        @Override
        public void onMove(final int x, final int y) {
            final Node targetNode = graphBoundsIndexer.getAt(x, y);
            final boolean allow = allow(x, y, connector, sourceNode, targetNode);
            canvasHighlight.unhighLight();
            if (null != targetNode && allow) {
                canvasHighlight.highLight(targetNode);
            } else if (null != targetNode) {
                canvasHighlight.invalid(targetNode);
            }
        }

        @Override
        public void onComplete(final int x, final int y) {
            final Node targetNode = graphBoundsIndexer.getAt(x, y);
            accept(x, y, connector, sourceNode, targetNode);
        }
    });
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) DragProxyCallback(org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ConnectorDragProxy(org.kie.workbench.common.stunner.core.client.components.drag.ConnectorDragProxy)

Example 29 with Edge

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

the class FlowActionsToolboxFactory method getActions.

@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> element) {
    final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
    final Node<Definition<Object>, Edge> node = (Node<Definition<Object>, Edge>) element;
    final Diagram diagram = canvasHandler.getDiagram();
    final String defSetId = diagram.getMetadata().getDefinitionSetId();
    // Look for the default connector type and create a button for it.
    commonLookups.getAllowedConnectors(defSetId, node, 0, 10).forEach(connectorDefId -> actions.add(createConnectorActions.get().setEdgeId(connectorDefId)));
    // It uses the default connector's identifier, for the actual definition set,
    // to check the resulting nodes that can be created.
    // It also groups the resuling nodes to be created by it's morph base type, and just
    // create an action for each morph target.
    final String defaultConnectorId = definitionUtils.getDefaultConnectorId(defSetId);
    if (null != defaultConnectorId) {
        commonLookups.getAllowedMorphDefaultDefinitions(defSetId, diagram.getGraph(), node, defaultConnectorId, 0, 10).forEach(defId -> actions.add(createNodeActions.get().setEdgeId(defaultConnectorId).setNodeId(defId.toString())));
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 30 with Edge

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

the class ShapeUtils method moveViewConnectorsToTop.

@SuppressWarnings("unchecked")
public static void moveViewConnectorsToTop(final AbstractCanvasHandler canvasHandler, final Node<?, Edge> node) {
    final Set<String> connectorIds = new HashSet<>();
    // Obtain all view connectors for the node and its children.
    appendViewConnectorIds(connectorIds, node);
    new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()).setRootUUID(node.getUUID()).traverse(canvasHandler.getGraphIndex().getGraph(), new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {

        @Override
        public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> childNode) {
            appendViewConnectorIds(connectorIds, childNode);
            return true;
        }
    });
    // Update connector's view.
    connectorIds.forEach(id -> moveShapeToTop(canvasHandler, id));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) HashSet(java.util.HashSet)

Aggregations

Edge (org.kie.workbench.common.stunner.core.graph.Edge)154 View (org.kie.workbench.common.stunner.core.graph.content.view.View)101 Node (org.kie.workbench.common.stunner.core.graph.Node)84 Test (org.junit.Test)45 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)30 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)30 Graph (org.kie.workbench.common.stunner.core.graph.Graph)28 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)19 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)19 List (java.util.List)17 EventPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EventPropertyReader)16 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)16 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)13 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 ArrayList (java.util.ArrayList)11