Search in sources :

Example 26 with ViewConnector

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

the class NodeBuilderControlImpl method updateConnectorShape.

@SuppressWarnings("unchecked")
protected void updateConnectorShape(final Edge<? extends ViewConnector<?>, Node> inEdge, final Node targetNode, final Connection sourceConnection, final Connection targetConnection) {
    final ViewConnector connectorContent = (ViewConnector) inEdge.getContent();
    canvasHandler.applyElementMutation(inEdge, MutationContext.STATIC);
    final EdgeShape edgeShape = (EdgeShape) canvasHandler.getCanvas().getShape(inEdge.getUUID());
    final Node source = inEdge.getSourceNode();
    if (null != source && null != targetNode) {
        final Shape<?> sShape = canvasHandler.getCanvas().getShape(source.getUUID());
        final Shape<?> tShape = canvasHandler.getCanvas().getShape(targetNode.getUUID());
        connectorContent.setSourceConnection(sourceConnection);
        connectorContent.setTargetConnection(targetConnection);
        edgeShape.applyConnections(inEdge, sShape.getShapeView(), tShape.getShapeView(), MutationContext.STATIC);
    }
}
Also used : 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)

Example 27 with ViewConnector

use of org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector 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)

Example 28 with ViewConnector

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

the class CloneConnectorCommand method initialize.

@Override
@SuppressWarnings("unchecked")
protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) {
    super.initialize(context);
    this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID);
    this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID);
    if (!(candidate.getContent() instanceof ViewConnector)) {
        throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector");
    }
    // clone candidate
    ViewConnector edgeContent = (ViewConnector) candidate.getContent();
    final Object bean = edgeContent.getDefinition();
    clone = context.getFactoryManager().newElement(UUID.uuid(), bean.getClass()).asEdge();
    // Cloning the candidate content with properties
    Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL);
    ViewConnector clonedContent = (ViewConnector) clone.getContent();
    clonedContent.setDefinition(clonedDefinition);
    // Magnet being moved on node
    ViewConnector connectionContent = (ViewConnector) candidate.getContent();
    this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null);
    this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null);
    commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection));
    commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection));
    // Add the candidate into index, so child commands can find it.
    getMutableIndex(context).addEdge(clone);
    return this;
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 29 with ViewConnector

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

the class SetConnectionTargetNodeCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
    final CommandResult<RuleViolation> results = allow(context);
    if (!results.getType().equals(CommandResult.Type.ERROR)) {
        final Edge<? extends View, Node> edge = getEdge(context);
        final Node<?, Edge> targetNode = getTargetNode(context);
        final Node<? extends View<?>, Edge> lastTargetNode = edge.getTargetNode();
        // New connection being made
        if (null != lastTargetNode) {
            lastTargetNodeUUID = lastTargetNode.getUUID();
            lastTargetNode.getInEdges().remove(edge);
        }
        if (null != targetNode) {
            targetNode.getInEdges().add(edge);
        }
        edge.setTargetNode(targetNode);
        // Magnet being moved on node
        ViewConnector connectionContent = (ViewConnector) edge.getContent();
        lastConnection = (Connection) connectionContent.getTargetConnection().orElse(null);
        connectionContent.setTargetConnection(connection);
    }
    return results;
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 30 with ViewConnector

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

the class ControlPointControlImpl method registerHandlers.

@SuppressWarnings("unchecked")
private void registerHandlers(final Element element, final Shape<?> shape) {
    if (shape.getShapeView() instanceof HasEventHandlers && element instanceof Edge && element.getContent() instanceof ViewConnector) {
        final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
        // Register handler on the Connector to Add a ControlPoint
        MouseDoubleClickHandler eventHandler = new MouseDoubleClickHandler() {

            @Override
            public void handle(MouseDoubleClickEvent event) {
                addControlPoint((Edge) element, new ControlPointImpl(event.getX(), event.getY()));
            }
        };
        hasEventHandlers.addHandler(ViewEventType.MOUSE_DBL_CLICK, eventHandler);
        registerHandler(element.getUUID(), eventHandler);
    }
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) MouseDoubleClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickHandler) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) MouseDoubleClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickEvent) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)30 Node (org.kie.workbench.common.stunner.core.graph.Node)20 Edge (org.kie.workbench.common.stunner.core.graph.Edge)17 Graph (org.kie.workbench.common.stunner.core.graph.Graph)10 Test (org.junit.Test)8 View (org.kie.workbench.common.stunner.core.graph.content.view.View)8 List (java.util.List)7 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)6 ArrayList (java.util.ArrayList)5 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)5 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)5 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)5 ScriptTask (org.kie.workbench.common.stunner.bpmn.definition.ScriptTask)4 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)4 Element (org.kie.workbench.common.stunner.core.graph.Element)3 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)3 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)3 LinkedList (java.util.LinkedList)2 InclusiveGateway (org.kie.workbench.common.stunner.bpmn.definition.InclusiveGateway)2 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)2