Search in sources :

Example 1 with DefaultCanvasElementListener

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

the class DefaultDiagramEditor method onOpen.

private void onOpen(final Diagram diagram) {
    final Annotation qualifier = definitionUtils.getQualifier(diagram.getMetadata().getDefinitionSetId());
    commandManager = InstanceUtils.lookup(commandManagers, qualifier);
    locationControl = InstanceUtils.lookup(locationControls, qualifier);
    locationControl.setCommandManagerProvider(() -> commandManager);
    resizeControl = InstanceUtils.lookup(resizeControls, qualifier);
    resizeControl.setCommandManagerProvider(() -> commandManager);
    elementBuilderControl = InstanceUtils.lookup(elementBuilderControls, qualifier);
    elementBuilderControl.setCommandManagerProvider(() -> commandManager);
    nodeBuilderControl = InstanceUtils.lookup(nodeBuilderControls, qualifier);
    nodeBuilderControl.setCommandManagerProvider(() -> commandManager);
    edgeBuilderControl = InstanceUtils.lookup(edgeBuilderControls, qualifier);
    edgeBuilderControl.setCommandManagerProvider(() -> commandManager);
    controlPointControl = InstanceUtils.lookup(controlPointControls, qualifier);
    controlPointControl.setCommandManagerProvider(() -> commandManager);
    connectionAcceptorControl = InstanceUtils.lookup(connectionAcceptorControls, qualifier);
    connectionAcceptorControl.setCommandManagerProvider(() -> commandManager);
    containmentAcceptorControl = InstanceUtils.lookup(containmentAcceptorControls, qualifier);
    containmentAcceptorControl.setCommandManagerProvider(() -> commandManager);
    dockingAcceptorControl = InstanceUtils.lookup(dockingAcceptorControls, qualifier);
    containmentAcceptorControl.setCommandManagerProvider(() -> commandManager);
    elementListener = new DefaultCanvasElementListener(Arrays.asList(locationControl, resizeControl, elementBuilderControl, nodeBuilderControl, edgeBuilderControl, controlPointControl, containmentAcceptorControl, connectionAcceptorControl, dockingAcceptorControl));
    viewer.getHandler().addRegistrationListener(elementListener);
}
Also used : DefaultCanvasElementListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener) Annotation(java.lang.annotation.Annotation)

Example 2 with DefaultCanvasElementListener

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

the class DiagramEditorTest method testOpen.

@Test
@SuppressWarnings("unchecked")
public void testOpen() {
    tested.open(diagram, callback);
    assertEquals(diagram, tested.getInstance());
    verify(viewer, times(1)).open(eq(diagram), any(DiagramViewer.DiagramViewerCallback.class));
    verify(locationControlInstance, times(1)).init(eq(canvasHandler));
    verify(resizeControlInstance, times(1)).init(eq(canvasHandler));
    verify(builderControlInstance, times(1)).init(eq(canvasHandler));
    verify(nodeBuilderControlInstance, times(1)).init(eq(canvasHandler));
    verify(edgeBuilderControlInstance, times(1)).init(eq(canvasHandler));
    verify(cpControlInstance, times(1)).init(eq(canvasHandler));
    verify(connectionAcceptorControlInstance, times(1)).init(eq(canvasHandler));
    verify(containmentAcceptorControlInstance, times(1)).init(eq(canvasHandler));
    verify(dockingAcceptorControlInstance, times(1)).init(eq(canvasHandler));
    ArgumentCaptor<CanvasElementListener> elementListenerArgumentCaptor = ArgumentCaptor.forClass(CanvasElementListener.class);
    verify(canvasHandler, times(1)).addRegistrationListener(elementListenerArgumentCaptor.capture());
    DefaultCanvasElementListener elementListener = (DefaultCanvasElementListener) elementListenerArgumentCaptor.getValue();
    Iterator<CanvasControl<AbstractCanvasHandler>> canvasHandlerControls1 = elementListener.getCanvasControls().iterator();
    assertTrue(canvasHandlerControls1.next() instanceof LocationControl);
    assertTrue(canvasHandlerControls1.next() instanceof ResizeControl);
    assertTrue(canvasHandlerControls1.next() instanceof ElementBuilderControl);
    assertTrue(canvasHandlerControls1.next() instanceof NodeBuilderControl);
    assertTrue(canvasHandlerControls1.next() instanceof EdgeBuilderControl);
    assertTrue(canvasHandlerControls1.next() instanceof ControlPointControl);
    assertTrue(canvasHandlerControls1.next() instanceof ContainmentAcceptorControl);
    assertTrue(canvasHandlerControls1.next() instanceof ConnectionAcceptorControl);
    assertTrue(canvasHandlerControls1.next() instanceof DockingAcceptorControl);
    assertFalse(canvasHandlerControls1.hasNext());
}
Also used : EdgeBuilderControl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.EdgeBuilderControl) ResizeControl(org.kie.workbench.common.stunner.core.client.canvas.controls.ResizeControl) CanvasElementListener(org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasElementListener) DefaultCanvasElementListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener) ControlPointControl(org.kie.workbench.common.stunner.core.client.canvas.controls.connection.ControlPointControl) ConnectionAcceptorControl(org.kie.workbench.common.stunner.core.client.canvas.controls.connection.ConnectionAcceptorControl) ContainmentAcceptorControl(org.kie.workbench.common.stunner.core.client.canvas.controls.ContainmentAcceptorControl) LocationControl(org.kie.workbench.common.stunner.core.client.canvas.controls.LocationControl) DefaultCanvasElementListener(org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener) NodeBuilderControl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.NodeBuilderControl) CanvasControl(org.kie.workbench.common.stunner.core.client.canvas.controls.CanvasControl) ElementBuilderControl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.ElementBuilderControl) DockingAcceptorControl(org.kie.workbench.common.stunner.core.client.canvas.controls.DockingAcceptorControl) AbstractCanvasHandlerViewerTest(org.kie.workbench.common.stunner.client.widgets.presenters.AbstractCanvasHandlerViewerTest) Test(org.junit.Test)

Example 3 with DefaultCanvasElementListener

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

use of org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasElementListener 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)4 Annotation (java.lang.annotation.Annotation)2 Test (org.junit.Test)2 AbstractCanvasHandlerViewerTest (org.kie.workbench.common.stunner.client.widgets.presenters.AbstractCanvasHandlerViewerTest)2 CanvasControl (org.kie.workbench.common.stunner.core.client.canvas.controls.CanvasControl)2 CanvasElementListener (org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasElementListener)2 DefaultCanvasShapeListener (org.kie.workbench.common.stunner.core.client.session.impl.DefaultCanvasShapeListener)2 ContainmentAcceptorControl (org.kie.workbench.common.stunner.core.client.canvas.controls.ContainmentAcceptorControl)1 DockingAcceptorControl (org.kie.workbench.common.stunner.core.client.canvas.controls.DockingAcceptorControl)1 LocationControl (org.kie.workbench.common.stunner.core.client.canvas.controls.LocationControl)1 MediatorsControl (org.kie.workbench.common.stunner.core.client.canvas.controls.MediatorsControl)1 ResizeControl (org.kie.workbench.common.stunner.core.client.canvas.controls.ResizeControl)1 SelectionControl (org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl)1 EdgeBuilderControl (org.kie.workbench.common.stunner.core.client.canvas.controls.builder.EdgeBuilderControl)1 ElementBuilderControl (org.kie.workbench.common.stunner.core.client.canvas.controls.builder.ElementBuilderControl)1 NodeBuilderControl (org.kie.workbench.common.stunner.core.client.canvas.controls.builder.NodeBuilderControl)1 ConnectionAcceptorControl (org.kie.workbench.common.stunner.core.client.canvas.controls.connection.ConnectionAcceptorControl)1 ControlPointControl (org.kie.workbench.common.stunner.core.client.canvas.controls.connection.ControlPointControl)1 CanvasShapeListener (org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasShapeListener)1 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)1