use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class AbstractElementBuilderControl method getChildCoordinates.
public Point2D getChildCoordinates(final Node<View<?>, Edge> parent, final double _x, final double _y) {
if (null != parent) {
final Point2D parentCoords = GraphUtils.getPosition(parent.getContent());
final double x = _x - parentCoords.getX();
final double y = _y - parentCoords.getY();
return new Point2D(x, y);
}
return new Point2D(_x, _y);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class AbstractElementBuilderControl method getElementCommands.
@SuppressWarnings("unchecked")
public void getElementCommands(final Element element, final Node<View<?>, Edge> parent, final double x, final double y, final CommandsCallback commandsCallback) {
Command<AbstractCanvasHandler, CanvasViolation> command = null;
if (element instanceof Node) {
if (null != parent) {
command = canvasCommandFactory.addChildNode(parent, (Node) element, getShapeSetId());
} else {
command = canvasCommandFactory.addNode((Node) element, getShapeSetId());
}
} else if (element instanceof Edge && null != parent) {
command = canvasCommandFactory.addConnector(parent, (Edge) element, MagnetConnection.Builder.forElement(parent), getShapeSetId());
} else {
throw new RuntimeException("Unrecognized element type for " + element);
}
// Execute both add element and move commands in batch, so undo will be done in batch as well.
Command<AbstractCanvasHandler, CanvasViolation> moveCanvasElementCommand = canvasCommandFactory.updatePosition((Node<View<?>, Edge>) element, new Point2D(x, y));
final List<Command<AbstractCanvasHandler, CanvasViolation>> commandList = new LinkedList<Command<AbstractCanvasHandler, CanvasViolation>>();
commandList.add(command);
commandList.add(moveCanvasElementCommand);
commandsCallback.onComplete(element.getUUID(), commandList);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class NodeBuilderControlImpl method build.
@Override
@SuppressWarnings("unchecked")
public void build(final NodeBuildRequest request, final BuildCallback buildCallback) {
final double x = request.getX();
final double y = request.getY();
final Node<? extends View<?>, Edge> node = request.getNode();
final Edge<? extends ViewConnector<?>, Node> inEdge = request.getInEdge();
final Connection sourceConnection = request.getSourceConnection();
final Connection targetConnection = request.getTargetConnection();
if (null != node) {
final Object nodeDef = node.getContent().getDefinition();
final String nodeId = clientDefinitionManager.adapters().forDefinition().getId(nodeDef);
final ElementBuilderControlImpl ebc = getElementBuilderControl();
final Node<View<?>, Edge> parent = ebc.getParent(x, y);
final Point2D childCoordinates = ebc.getChildCoordinates(parent, x, y);
final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
ebc.getElementCommands(node, parent, childCoordinates.getX(), childCoordinates.getY(), new AbstractElementBuilderControl.CommandsCallback() {
@Override
public void onComplete(final String uuid, final List<Command<AbstractCanvasHandler, CanvasViolation>> commands) {
final CompositeCommand.Builder commandBuilder = new CompositeCommand.Builder().addCommands(commands);
if (inEdge != null) {
final Object edgeDef = inEdge.getContent().getDefinition();
final String edgeId = clientDefinitionManager.adapters().forDefinition().getId(edgeDef);
// The commands to batch for the edge that connects both nodes.
commandBuilder.addCommand(commandFactory.addConnector(inEdge.getSourceNode(), inEdge, sourceConnection, ssid));
commandBuilder.addCommand(commandFactory.setTargetNode(node, inEdge, targetConnection));
}
final CommandResult<CanvasViolation> results = elementBuilderControl.getCommandManager().execute(canvasHandler, commandBuilder.build());
if (!CommandUtils.isError(results)) {
updateConnectorShape(inEdge, node, sourceConnection, targetConnection);
}
buildCallback.onSuccess(uuid);
}
@Override
public void onError(final ClientRuntimeError error) {
buildCallback.onError(error);
}
});
}
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class CanvasLayoutUtils method getNext.
public Point2D getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final double rootNodeWidth, final double rootNodeHeight, final double newNodeWidth, final double newNodeHeight, Point2D offset, Point2D rootNodeCoordinates) {
checkNotNull("canvasHandler", canvasHandler);
checkNotNull("root", root);
final int canvasHeight = canvasHandler.getCanvas().getHeight();
final int canvasWidth = canvasHandler.getCanvas().getWidth();
Point2D newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
graphBoundsIndexer.build(canvasHandler.getDiagram().getGraph());
Element parentNode = GraphUtils.getParent(root.asNode());
boolean checkParent = false;
if (parentNode != null) {
if (!(isCanvasRoot(canvasHandler.getDiagram(), parentNode.getUUID()))) {
checkParent = true;
}
}
Node targetNodeContainer = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
boolean canContain = false;
if (targetNodeContainer != null) {
canContain = canContain(canvasHandler, targetNodeContainer, root);
}
if ((!canContain) || isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight) || checkParent) {
if (checkParent) {
newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
}
while (((!isCanvasPositionAvailable(graphBoundsIndexer, newPositionUL, newNodeWidth, newNodeHeight, parentNode)) && !canContain) && (newPositionUL.getY() < canvasHeight) && (newPositionUL.getX() < canvasWidth) || isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight)) {
parentNode = GraphUtils.getParent(root.asNode());
checkParent = false;
if (parentNode != null) {
if (!(isCanvasRoot(canvasHandler.getDiagram(), parentNode.getUUID()))) {
checkParent = true;
}
}
double[] nodeAtPositionSize;
nodeAtPositionSize = getNodeSizeAt(graphBoundsIndexer, newPositionUL, newNodeWidth, newNodeHeight, parentNode);
if (checkParent) {
final Node targetNodeNewPos = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
if (parentNode != targetNodeNewPos) {
offset.setY(offset.getY() + PADDING_Y);
}
} else {
if (nodeAtPositionSize == null) {
nodeAtPositionSize = new double[] { 0.0d };
offset.setY(offset.getY() + PADDING_Y);
} else {
offset.setY(offset.getY() + nodeAtPositionSize[1] + PADDING_Y);
}
}
newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
if (isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight)) {
rootNodeCoordinates.setY(0);
offset.setY(PADDING_Y);
offset.setX(offset.getX() + nodeAtPositionSize[0] + PADDING_X);
newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
}
if (checkParent) {
newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
}
targetNodeContainer = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
canContain = targetNodeContainer == null || canContain(canvasHandler, targetNodeContainer, root);
}
} else {
if (checkParent) {
newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
} else {
newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
}
}
return newPositionUL;
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class AbstractCanvasTooltip method show.
@Override
public void show(final T content, final Point2D location) {
final Point2D computedLocation = getComputedLocation(location);
showAt(content, computedLocation);
}
Aggregations