Search in sources :

Example 61 with Edge

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());
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Node(org.kie.workbench.common.stunner.core.graph.Node) Canvas(org.kie.workbench.common.stunner.core.client.canvas.Canvas) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 62 with Edge

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);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Violation(org.kie.workbench.common.stunner.core.validation.Violation) GraphBoundsIndexer(org.kie.workbench.common.stunner.core.graph.processing.index.bounds.GraphBoundsIndexer) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) NodeContainmentContext(org.kie.workbench.common.stunner.core.rule.context.NodeContainmentContext) Graph(org.kie.workbench.common.stunner.core.graph.Graph) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Dependent(javax.enterprise.context.Dependent) Element(org.kie.workbench.common.stunner.core.graph.Element) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 63 with Edge

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);
    }
}
Also used : IsElement(org.jboss.errai.common.client.api.IsElement) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 64 with Edge

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));
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) ActionsToolbox(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolbox) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ActionsToolboxView(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolboxView) Consumer(java.util.function.Consumer) ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) ActionsToolbox(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolbox) Toolbox(org.kie.workbench.common.stunner.core.client.components.toolbox.Toolbox) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 65 with Edge

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;
}
Also used : View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) List(java.util.List) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)

Aggregations

Edge (org.kie.workbench.common.stunner.core.graph.Edge)154 View (org.kie.workbench.common.stunner.core.graph.content.view.View)101 Node (org.kie.workbench.common.stunner.core.graph.Node)84 Test (org.junit.Test)45 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)30 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)30 Graph (org.kie.workbench.common.stunner.core.graph.Graph)28 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)19 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)19 List (java.util.List)17 EventPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EventPropertyReader)16 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)16 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)13 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 ArrayList (java.util.ArrayList)11