Search in sources :

Example 1 with DefaultCanvasShapeListener

use of org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasShapeListener in project kie-wb-common by kiegroup.

the class DefaultDiagramViewer method onOpen.

@Override
protected void onOpen(final Diagram diagram) {
    final Annotation qualifier = definitionUtils.getQualifier(diagram.getMetadata().getDefinitionSetId());
    canvasPanel = InstanceUtils.lookup(canvasPanelInstances, qualifier);
    canvas = InstanceUtils.lookup(canvasInstances, qualifier);
    canvasHandler = InstanceUtils.lookup(canvasHandlerInstances, qualifier);
    mediatorsControl = InstanceUtils.lookup(mediatorsControlInstances, qualifier);
    selectionControl = InstanceUtils.lookup(selectionControlInstances, qualifier);
    shapeListener = new DefaultCanvasShapeListener(Collections.singletonList(mediatorsControl));
    canvas.addRegistrationListener(shapeListener);
    elementListener = new DefaultCanvasElementListener(Collections.singletonList(selectionControl));
    canvasHandler.addRegistrationListener(elementListener);
}
Also used : DefaultCanvasElementListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener) DefaultCanvasShapeListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasShapeListener) Annotation(java.lang.annotation.Annotation)

Example 2 with DefaultCanvasShapeListener

use of org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasShapeListener 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

DefaultCanvasElementListener (org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener)2 DefaultCanvasShapeListener (org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasShapeListener)2 Annotation (java.lang.annotation.Annotation)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 SelectionControl (org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl)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 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)1