Search in sources :

Example 1 with SelectionControl

use of org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl in project kie-wb-common by kiegroup.

the class AbstractCanvasShortcutsControlImplTest method mockSelectedElements.

private List<Element> mockSelectedElements(final String... selectedIds) {
    final Index index = mock(Index.class);
    doReturn(index).when(canvasHandlerMock).getGraphIndex();
    final EditorSession session = mock(EditorSession.class);
    final SelectionControl selectionControl = mock(SelectionControl.class);
    final KeyboardControl keyboardControl = mock(KeyboardControl.class);
    doReturn(selectionControl).when(session).getSelectionControl();
    doReturn(keyboardControl).when(session).getKeyboardControl();
    doReturn(Arrays.asList(selectedIds)).when(selectionControl).getSelectedItems();
    canvasShortcutsControl.bind(session);
    final List<Element> selectedElements = new ArrayList<>();
    for (final String id : selectedIds) {
        final Element element = mock(Element.class);
        doReturn(element).when(index).get(id);
        selectedElements.add(element);
    }
    return selectedElements;
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) ArrayList(java.util.ArrayList) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession) SelectionControl(org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl)

Example 2 with SelectionControl

use of org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl in project kie-wb-common by kiegroup.

the class DiagramViewerTest method testOpen.

@Test
@SuppressWarnings("unchecked")
public void testOpen() {
    tested.open(diagram, callback);
    assertEquals(diagram, tested.getInstance());
    verify(canvasHandler, times(1)).handle(eq(canvas));
    verify(canvasHandler, times(1)).draw(eq(diagram), any(ParameterizedCommand.class));
    verify(callback, times(1)).afterCanvasInitialized();
    verify(mediatorsControlInstance, times(1)).init(eq(canvas));
    verify(selectionControlInstance, times(1)).init(eq(canvasHandler));
    verify(view, times(1)).setWidget(eq(canvasViewWidget));
    ArgumentCaptor<CanvasShapeListener> shapeListenerArgumentCaptor = ArgumentCaptor.forClass(CanvasShapeListener.class);
    ArgumentCaptor<CanvasElementListener> elementListenerArgumentCaptor = ArgumentCaptor.forClass(CanvasElementListener.class);
    verify(canvas, times(1)).addRegistrationListener(shapeListenerArgumentCaptor.capture());
    verify(canvasHandler, times(1)).addRegistrationListener(elementListenerArgumentCaptor.capture());
    DefaultCanvasShapeListener shapeListener = (DefaultCanvasShapeListener) shapeListenerArgumentCaptor.getValue();
    Iterator<CanvasControl<AbstractCanvas>> canvasControls = shapeListener.getCanvasControls().iterator();
    assertTrue(canvasControls.next() instanceof MediatorsControl);
    assertFalse(canvasControls.hasNext());
    DefaultCanvasElementListener elementListener = (DefaultCanvasElementListener) elementListenerArgumentCaptor.getValue();
    Iterator<CanvasControl<AbstractCanvasHandler>> canvasHandlerControls1 = elementListener.getCanvasControls().iterator();
    assertTrue(canvasHandlerControls1.next() instanceof SelectionControl);
    assertFalse(canvasHandlerControls1.hasNext());
}
Also used : CanvasElementListener(org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasElementListener) DefaultCanvasElementListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener) MediatorsControl(org.kie.workbench.common.stunner.core.client.canvas.controls.MediatorsControl) DefaultCanvasElementListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener) CanvasControl(org.kie.workbench.common.stunner.core.client.canvas.controls.CanvasControl) DefaultCanvasShapeListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasShapeListener) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) CanvasShapeListener(org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasShapeListener) DefaultCanvasShapeListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasShapeListener) SelectionControl(org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl) AbstractCanvasHandlerViewerTest(org.kie.workbench.common.stunner.client.widgets.presenters.AbstractCanvasHandlerViewerTest) Test(org.junit.Test)

Aggregations

SelectionControl (org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 AbstractCanvasHandlerViewerTest (org.kie.workbench.common.stunner.client.widgets.presenters.AbstractCanvasHandlerViewerTest)1 CanvasControl (org.kie.workbench.common.stunner.core.client.canvas.controls.CanvasControl)1 MediatorsControl (org.kie.workbench.common.stunner.core.client.canvas.controls.MediatorsControl)1 CanvasElementListener (org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasElementListener)1 CanvasShapeListener (org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasShapeListener)1 DefaultCanvasElementListener (org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener)1 DefaultCanvasShapeListener (org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasShapeListener)1 EditorSession (org.kie.workbench.common.stunner.core.client.session.impl.EditorSession)1 Element (org.kie.workbench.common.stunner.core.graph.Element)1 Index (org.kie.workbench.common.stunner.core.graph.processing.index.Index)1 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)1