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