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);
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations