Search in sources :

Example 26 with BoundsImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.

the class UpdateElementPositionCommandTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    super.setUp();
    when(candidate.getUUID()).thenReturn("uuid1");
    when(candidate.getContent()).thenReturn(content);
    when(content.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(3d, 27d), new BoundImpl(50d, 50d)));
    this.tested = new UpdateElementPositionCommand(candidate, new Point2D(100d, 200d));
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Before(org.junit.Before)

Example 27 with BoundsImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.

the class UpdateElementPositionCommand method checkBounds.

@SuppressWarnings("unchecked")
private CommandResult<RuleViolation> checkBounds(final GraphCommandExecutionContext context) {
    final Element<? extends View<?>> element = getNodeNotNull(context);
    final Graph<DefinitionSet, Node> graph = (Graph<DefinitionSet, Node>) getGraph(context);
    final BoundsImpl newBounds = getTargetBounds(element);
    final GraphCommandResultBuilder result = new GraphCommandResultBuilder();
    final Bounds parentBounds = getParentBounds(element, graph);
    if (GraphUtils.checkBoundsExceeded(parentBounds, newBounds)) {
        ((View) element.getContent()).setBounds(newBounds);
    } else {
        result.addViolation(new BoundsExceededViolation(parentBounds).setUUID(element.getUUID()));
    }
    return result.build();
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 28 with BoundsImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.

the class UpdateElementPositionCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
    final BoundsImpl newBounds = getTargetBounds(getNodeNotNull(context));
    LOGGER.log(Level.FINE, "Moving element bounds to " + "[" + newBounds.getX() + "," + newBounds.getY() + "] " + "[" + newBounds.getWidth() + "," + newBounds.getHeight() + "]");
    return checkBounds(context);
}
Also used : BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)

Example 29 with BoundsImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.

the class TestingGraphMockHandler method newViewNode.

public Node newViewNode(String uuid, Optional<Object> def, final double x, final double y, final double w, final double h) {
    final Object definition = def.isPresent() ? def.get() : newDef("def-" + uuid, Optional.empty());
    when(definitionUtils.buildBounds(eq(definition), anyDouble(), anyDouble())).thenReturn(new BoundsImpl(new BoundImpl(x, y), new BoundImpl(x + w, y + h)));
    final Node<Definition<Object>, Edge> result = nodeFactory.build(uuid, definition);
    execute(commandFactory.addNode(result));
    when(graphIndex.getNode(eq(uuid))).thenReturn(result);
    when(graphIndex.get(eq(uuid))).thenReturn(result);
    return result;
}
Also used : BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 30 with BoundsImpl

use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl 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

BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)31 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)28 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Test (org.junit.Test)11 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)9 Before (org.junit.Before)7 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)6 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)6 Ignore (org.junit.Ignore)4 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)4 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)4 Command (org.kie.workbench.common.stunner.core.command.Command)3 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)3 Consumer (java.util.function.Consumer)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)2 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)2 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)2