Search in sources :

Example 1 with ToolboxAction

use of org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction 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 2 with ToolboxAction

use of org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction in project kie-wb-common by kiegroup.

the class DMNFlowActionsToolboxFactory 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 allowed connectors present in the Definition Set.
    final Set<String> allowedConnectorIds = commonLookups.getAllowedConnectors(defSetId, node, 0, 10);
    for (final String allowedConnectorId : allowedConnectorIds) {
        // Append a new action for each connector.
        actions.add(createConnectorActions.get().setEdgeId(allowedConnectorId));
        // Append a new action for each candidate target node (as from the current connector).
        commonLookups.getAllowedTargetDefinitions(defSetId, diagram.getGraph(), node, allowedConnectorId, 0, 10).forEach(def -> actions.add(createNodeActions.get().setEdgeId(allowedConnectorId).setNodeId(getDefinitionId(def))));
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 3 with ToolboxAction

use of org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction in project kie-wb-common by kiegroup.

the class DMNCommonActionsToolboxFactoryTest method testBuildToolboxForDecisionType.

@Test
@SuppressWarnings("unchecked")
public void testBuildToolboxForDecisionType() {
    final Node<View<Decision>, Edge> decisionNode = new NodeImpl<>("decisionNode1");
    final Decision decision = new Decision();
    final Bounds bounds = new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(100d, 150d));
    final View<Decision> nodeContent = new ViewImpl<>(decision, bounds);
    decisionNode.setContent(nodeContent);
    final Optional<Toolbox<?>> _toolbox = tested.build(canvasHandler, decisionNode);
    assertTrue(_toolbox.isPresent());
    Toolbox<?> toolbox = _toolbox.get();
    assertTrue(toolbox instanceof ActionsToolbox);
    final ActionsToolbox actionsToolbox = (ActionsToolbox) toolbox;
    assertEquals("decisionNode1", actionsToolbox.getElementUUID());
    assertEquals(2, actionsToolbox.size());
    final Iterator<ToolboxAction> actionsIt = actionsToolbox.iterator();
    assertEquals(deleteNodeAction, actionsIt.next());
    assertEquals(editDecisionToolboxAction, 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) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) Consumer(java.util.function.Consumer) ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) 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)

Aggregations

ToolboxAction (org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction)3 Edge (org.kie.workbench.common.stunner.core.graph.Edge)3 Consumer (java.util.function.Consumer)2 Test (org.junit.Test)2 Toolbox (org.kie.workbench.common.stunner.core.client.components.toolbox.Toolbox)2 ActionsToolbox (org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolbox)2 ActionsToolboxView (org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolboxView)2 Glyph (org.kie.workbench.common.stunner.core.definition.shape.Glyph)2 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)2 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)2 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)2 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)2 LinkedHashSet (java.util.LinkedHashSet)1 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)1 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)1 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)1