use of org.kie.workbench.common.stunner.core.graph.Edge 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.Edge 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.Edge 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.Edge in project kie-wb-common by kiegroup.
the class DMNCommonActionsToolboxFactoryTest method testBuildToolboxForBusinessKnowledgeModelType.
@Test
@SuppressWarnings("unchecked")
public void testBuildToolboxForBusinessKnowledgeModelType() {
final Node<View<BusinessKnowledgeModel>, Edge> bkmNode = new NodeImpl<>("bkmNode1");
final BusinessKnowledgeModel bkm = new BusinessKnowledgeModel();
final Bounds bounds = new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(100d, 150d));
final View<BusinessKnowledgeModel> nodeContent = new ViewImpl<>(bkm, bounds);
bkmNode.setContent(nodeContent);
final Optional<Toolbox<?>> _toolbox = tested.build(canvasHandler, bkmNode);
assertTrue(_toolbox.isPresent());
Toolbox<?> toolbox = _toolbox.get();
assertTrue(toolbox instanceof ActionsToolbox);
final ActionsToolbox actionsToolbox = (ActionsToolbox) toolbox;
assertEquals("bkmNode1", actionsToolbox.getElementUUID());
assertEquals(2, actionsToolbox.size());
final Iterator<ToolboxAction> actionsIt = actionsToolbox.iterator();
assertEquals(deleteNodeAction, actionsIt.next());
assertEquals(editBusinessKnowledgeModelToolboxAction, actionsIt.next());
assertFalse(actionsIt.hasNext());
verify(view, times(1)).init(eq(actionsToolbox));
verify(view, times(2)).addButton(any(Glyph.class), anyString(), any(Consumer.class));
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class KnowledgeSourceConverter method dmnFromNode.
@Override
public org.kie.dmn.model.v1_1.KnowledgeSource dmnFromNode(final Node<View<KnowledgeSource>, ?> node) {
KnowledgeSource source = node.getContent().getDefinition();
org.kie.dmn.model.v1_1.KnowledgeSource result = new org.kie.dmn.model.v1_1.KnowledgeSource();
result.setId(source.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
result.setName(source.getName().getValue());
result.setType(source.getType().getValue());
result.setLocationURI(source.getLocationURI().getValue());
// DMN spec table 2: Requirements connection rules
List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof Decision) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredDecision(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof KnowledgeSource) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredAuthority(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof InputData) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredInput(ri);
result.getAuthorityRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
return result;
}
Aggregations