Search in sources :

Example 6 with Element

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

the class LocationControlImpl method handleArrowKeys.

private void handleArrowKeys(final KeyboardEvent.Key... keys) {
    final int selectedIDsCount = selectedIDs.size();
    if (selectedIDsCount == 0) {
        return;
    }
    double movementDistance = NORMAL_DISTANCE;
    if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.CONTROL)) {
        movementDistance = LARGE_DISTANCE;
    } else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.SHIFT)) {
        movementDistance = SHORT_DISTANCE;
    }
    double horizontalDistance = 0d;
    double verticalDistance = 0d;
    if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_LEFT)) {
        horizontalDistance = -movementDistance;
    } else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_RIGHT)) {
        horizontalDistance = movementDistance;
    }
    if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_UP)) {
        verticalDistance = -movementDistance;
    } else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_DOWN)) {
        verticalDistance = movementDistance;
    }
    if (verticalDistance == 0 && horizontalDistance == 0) {
        return;
    }
    List<Element> moveNodes = new ArrayList<>();
    List<Point2D> movePositions = new ArrayList<>();
    for (String uuid : selectedIDs) {
        final Node<View<?>, Edge> node = canvasHandler.getGraphIndex().getNode(uuid);
        if (node != null) {
            final Point2D nodePosition = GraphUtils.getPosition(node.getContent());
            final Point2D movePosition = new Point2D(nodePosition.getX() + horizontalDistance, nodePosition.getY() + verticalDistance);
            moveNodes.add(node);
            movePositions.add(movePosition);
        }
    }
    move(moveNodes.toArray(new Element[] {}), movePositions.toArray(new Point2D[] {}));
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Element(org.kie.workbench.common.stunner.core.graph.Element) ArrayList(java.util.ArrayList) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 7 with Element

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

the class ConnectionAcceptorControlImplTest method testCreateConnections.

@Test
public void testCreateConnections() {
    // New default connection for a graph element.
    Element element = mock(Element.class);
    View<?> content = mock(View.class);
    BoundsImpl bounds = new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(10d, 20d));
    when(element.getContent()).thenReturn(content);
    when(content.getBounds()).thenReturn(bounds);
    MagnetConnection c1 = ConnectionAcceptorControlImpl.createConnection(element);
    assertEquals(5, c1.getLocation().getX(), 0);
    assertEquals(10, c1.getLocation().getY(), 0);
    assertEquals(MagnetConnection.MAGNET_CENTER, c1.getMagnetIndex().getAsInt());
    assertFalse(c1.isAuto());
    // New default connection for wires.
    WiresConnection wiresConnection = mock(WiresConnection.class);
    when(wiresConnection.isAutoConnection()).thenReturn(true);
    WiresMagnet wiresMagnet = mock(WiresMagnet.class);
    when(wiresMagnet.getX()).thenReturn(122d);
    when(wiresMagnet.getY()).thenReturn(543d);
    when(wiresMagnet.getIndex()).thenReturn(7);
    MagnetConnection c2 = ConnectionAcceptorControlImpl.createConnection(wiresConnection, wiresMagnet);
    assertEquals(122, c2.getLocation().getX(), 0);
    assertEquals(543, c2.getLocation().getY(), 0);
    assertEquals(7, c2.getMagnetIndex().getAsInt());
    assertTrue(c2.isAuto());
    // Connections (view magnets) can be nullified.
    assertNull(ConnectionAcceptorControlImpl.createConnection(null));
    assertNull(ConnectionAcceptorControlImpl.createConnection(wiresConnection, null));
    assertNull(ConnectionAcceptorControlImpl.createConnection(null, null));
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) Element(org.kie.workbench.common.stunner.core.graph.Element) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) WiresMagnet(com.ait.lienzo.client.core.shape.wires.WiresMagnet) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Test(org.junit.Test)

Example 8 with Element

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

the class DiagramPresenterFactoryImpl method newViewer.

@Override
@SuppressWarnings("unchecked")
public DiagramViewer<Diagram, ?> newViewer(final Diagram diagram) {
    final CanvasFactory<AbstractCanvas, AbstractCanvasHandler> canvasFactory = shapeManager.getCanvasFactory(diagram);
    final AbstractCanvas canvas = canvasFactory.newCanvas();
    final AbstractCanvasHandler canvasHandler = canvasFactory.newCanvasHandler();
    final ZoomControl<AbstractCanvas> zoomControl = canvasFactory.newControl(ZoomControl.class);
    final SelectionControl<AbstractCanvasHandler, Element> selectionControl = canvasFactory.newControl(SelectionControl.class);
    return new DiagramViewerImpl<>(canvas, canvasHandler, viewInstances.get(), zoomControl, selectionControl, canvasControlDisposer);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) Element(org.kie.workbench.common.stunner.core.graph.Element)

Example 9 with Element

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

the class TextEditorBoxImplTest method init.

@Before
@SuppressWarnings("unchecked")
public void init() {
    this.textPropertyProvider = new DefaultTextPropertyProviderImpl(definitionUtils, canvasCommandFactory);
    when(element.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(objectDefinition);
    when(definitionUtils.getName(objectDefinition)).thenReturn(NAME);
    when(definitionUtils.getNameIdentifier(objectDefinition)).thenReturn(ID);
    when(commandProvider.getCommandManager()).thenReturn(canvasCommandManager);
    when(canvasHandler.getTextPropertyProviderFactory()).thenReturn(textPropertyProviderFactory);
    when(textPropertyProviderFactory.getProvider(any(Element.class))).thenReturn(textPropertyProvider);
    presenter = new TextEditorBoxImpl(view);
    presenter.setup();
    verify(view).init(presenter);
    presenter.initialize(canvasHandler, closeCallback);
    presenter.setCommandManagerProvider(commandProvider);
    presenter.getElement();
    verify(view).getElement();
    presenter.show(element);
    verify(view).show(NAME);
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) DefaultTextPropertyProviderImpl(org.kie.workbench.common.stunner.core.client.canvas.controls.actions.DefaultTextPropertyProviderImpl) Before(org.junit.Before)

Example 10 with Element

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

the class SessionPreviewCanvasHandlerProxyTest method checkAddChildDelegatesToWrapped.

@Test
public void checkAddChildDelegatesToWrapped() {
    final Element parent = mock(Element.class);
    final Element child = mock(Element.class);
    proxy.addChild(parent, child);
    verify(wrapped).addChild(eq(parent), eq(child));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Test(org.junit.Test)

Aggregations

Element (org.kie.workbench.common.stunner.core.graph.Element)85 Test (org.junit.Test)55 View (org.kie.workbench.common.stunner.core.graph.content.view.View)34 Graph (org.kie.workbench.common.stunner.core.graph.Graph)27 FlowElement (org.eclipse.bpmn2.FlowElement)24 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)24 RootElement (org.eclipse.bpmn2.RootElement)24 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)24 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Map (java.util.Map)7 Optional (java.util.Optional)6 Before (org.junit.Before)6 Collection (java.util.Collection)5 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)5 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)5 Matchers.anyString (org.mockito.Matchers.anyString)5 Logger (java.util.logging.Logger)4 BPMNDiagram (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram)4