use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class EdgeBuilderControlImpl method build.
@Override
@SuppressWarnings("unchecked")
public void build(final EdgeBuildRequest request, final BuildCallback buildCallback) {
final double x = request.getX();
final double y = request.getY();
final Edge<? extends ViewConnector<?>, Node> edge = request.getEdge();
final AbstractCanvasHandler<?, ?> wch = canvasHandler;
final Node<? extends View<?>, Edge> inNode = request.getInNode();
final Node<? extends View<?>, Edge> outNode = request.getOutNode();
final Canvas canvas = canvasHandler.getCanvas();
if (null == inNode) {
throw new RuntimeException(" An edge must be into the outgoing edges list from a node.");
}
final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
final CompositeCommand.Builder commandBuilder = new CompositeCommand.Builder().addCommand(commandFactory.addConnector(inNode, edge, MagnetConnection.Builder.forElement(inNode), ssid));
if (null != outNode) {
commandBuilder.addCommand(commandFactory.setTargetNode(outNode, edge, MagnetConnection.Builder.forElement(outNode)));
}
final CommandResult<CanvasViolation> results = getCommandManager().execute(wch, commandBuilder.build());
if (CommandUtils.isError(results)) {
LOGGER.log(Level.WARNING, results.toString());
}
canvasHandler.applyElementMutation(edge, MutationContext.STATIC);
buildCallback.onSuccess(edge.getUUID());
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class CanvasLayoutUtils method getNext.
@SuppressWarnings("unchecked")
public Point2D getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) {
final double[] rootBounds = getBoundCoordinates(root.getContent());
final double[] rootSize = GraphUtils.getNodeSize(root.getContent());
final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent());
Point2D[] offset = { new Point2D(PADDING_X, 0) };
Point2D[] parentOffset = { new Point2D(0, 0) };
double[] maxNodeY = { 0 };
if (root.getOutEdges().size() > 0) {
root.getOutEdges().stream().filter(e -> e.getContent() instanceof ViewConnector).filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)).forEach(n -> {
final Node<View<?>, Edge> node = n.getTargetNode();
final Point2D nodePos = GraphUtils.getPosition(node.getContent());
final Point2D rootPos = GraphUtils.getPosition(root.getContent());
if (nodePos.getY() > maxNodeY[0]) {
maxNodeY[0] = nodePos.getY();
final double[] nodeSize = GraphUtils.getNodeSize(node.getContent());
offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY());
}
});
offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y);
} else {
offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2);
}
offset[0].setX(offset[0].getX() + PADDING_X);
final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY());
final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]);
return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates);
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class TreeExplorer method addItem.
@SuppressWarnings("unchecked")
private void addItem(final Element parent, final Node element, final boolean expand, final boolean checkParent) {
final boolean isContainer = isContainer().test(element);
final Glyph glyph = getGlyph(getShapeSetId(), element);
final String name = getItemName(element);
final IsElement icon = domGlyphRenderers.render(glyph, icoWidth, icoHeight);
// Check the parent, in case a TreeItem mutates from/to ITEM type to CONTAINER type.
final boolean isValidParentItem = null != parent && isValidTreeItem().test(parent);
if (checkParent && isValidParentItem) {
final boolean isParentContainer = isContainer().test((Node) parent);
final boolean wasParentContainer = view.isContainer(parent.getUUID());
if (isParentContainer != wasParentContainer) {
view.removeItem(parent.getUUID());
addItem(GraphUtils.getParent((Node<?, ? extends Edge>) parent), (Node) parent, expand, false);
}
}
final ElementWrapperWidget<?> widget = wrapIconElement(icon);
// Create and add the tree item.
if (isValidParentItem) {
view.addItem(element.getUUID(), parent.getUUID(), name, widget, isContainer, expand);
} else {
view.addItem(element.getUUID(), name, widget, isContainer, expand);
}
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class LogNodeEdgesDevCommand method log.
private void log(final Edge edge) {
if (null != edge) {
final String uuid = edge.getUUID();
final Object content = edge.getContent();
final Node source = edge.getSourceNode();
final String sId = null != source ? source.getUUID() : "null";
final Node target = edge.getTargetNode();
final String tId = null != target ? target.getUUID() : "null";
log("-- Edge [uuid=" + uuid + ", content=" + content.getClass().getName() + ", source=" + sId + ", target=" + tId + "]");
} else {
log("Edge is null...");
}
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class KnowledgeSourceConverter method nodeFromDMN.
@Override
public Node<View<KnowledgeSource>, ?> nodeFromDMN(final org.kie.dmn.model.v1_1.KnowledgeSource dmn) {
@SuppressWarnings("unchecked") Node<View<KnowledgeSource>, ?> node = (Node<View<KnowledgeSource>, ?>) factoryManager.newElement(dmn.getId(), KnowledgeSource.class).asNode();
Id id = new Id(dmn.getId());
Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
Name name = new Name(dmn.getName());
KnowledgeSourceType ksType = new KnowledgeSourceType(dmn.getType());
LocationURI locationURI = new LocationURI(dmn.getLocationURI());
KnowledgeSource ks = new KnowledgeSource(id, description, name, ksType, locationURI, new BackgroundSet(), new FontSet(), new RectangleDimensionsSet());
node.getContent().setDefinition(ks);
return node;
}
Aggregations