Search in sources :

Example 1 with Layer

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

the class MapSelectionControlTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    ShapeViewExtStub shapeView = new ShapeViewExtStub(shapeEventHandler, hasControlPoints);
    when(element.getUUID()).thenReturn(ELEMENT_UUID);
    when(element.getContent()).thenReturn(new ViewImpl<>(definition, BoundsImpl.build(0, 0, 10, 10)));
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvas.getLayer()).thenReturn(layer);
    when(canvas.getShape(eq(ELEMENT_UUID))).thenReturn(shape);
    when(canvas.getShapes()).thenReturn(Collections.singletonList(shape));
    when(shape.getUUID()).thenReturn(ELEMENT_UUID);
    when(shape.getShapeView()).thenReturn(shapeView);
    when(shapeEventHandler.supports(eq(ViewEventType.MOUSE_CLICK))).thenReturn(true);
    this.tested = new MapSelectionControl(e -> elementSelectedEvent.fire((CanvasSelectionEvent) e), e -> clearSelectionEvent.fire((CanvasClearSelectionEvent) e));
    this.tested.setReadonly(false);
}
Also used : CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ViewHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewHandler) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HasControlPoints(org.kie.workbench.common.stunner.core.client.shape.view.HasControlPoints) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Layer(org.kie.workbench.common.stunner.core.client.canvas.Layer) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.eq(org.mockito.Matchers.eq) CanvasShapeRemovedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasShapeRemovedEvent) ShapeState(org.kie.workbench.common.stunner.core.client.shape.ShapeState) Element(org.kie.workbench.common.stunner.core.graph.Element) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before) ViewEventType(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEventType) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Assert.assertFalse(org.junit.Assert.assertFalse) ShapeViewExtStub(org.kie.workbench.common.stunner.core.client.shape.ShapeViewExtStub) EventSourceMock(org.uberfire.mocks.EventSourceMock) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ShapeViewExtStub(org.kie.workbench.common.stunner.core.client.shape.ShapeViewExtStub) Before(org.junit.Before)

Example 2 with Layer

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

the class CanvasDefinitionTooltipTest method testConfigure.

@Test
public void testConfigure() {
    final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
    final AbstractCanvas canvas = mock(AbstractCanvas.class);
    final AbstractCanvas.View canvasView = mock(AbstractCanvas.View.class);
    final Layer layer = mock(Layer.class);
    final Transform transform = mock(Transform.class);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvasHandler.getAbstractCanvas()).thenReturn(canvas);
    when(canvas.getLayer()).thenReturn(layer);
    when(layer.getTransform()).thenReturn(transform);
    when(canvas.getView()).thenReturn(canvasView);
    when(canvasView.getAbsoluteX()).thenReturn(220d);
    when(canvasView.getAbsoluteY()).thenReturn(50.5d);
    final CanvasDefinitionTooltip t = tested.configure(canvasHandler);
    assertEquals(tested, t);
    verify(textTooltip, times(1)).setTransform(eq(transform));
    final ArgumentCaptor<Point2D> pointCaptor = ArgumentCaptor.forClass(Point2D.class);
    verify(textTooltip, times(1)).setCanvasLocation(pointCaptor.capture());
    final Point2D point = pointCaptor.getValue();
    assertEquals(220d, point.getX(), 0);
    assertEquals(50.5d, point.getY(), 0);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Transform(org.kie.workbench.common.stunner.core.client.canvas.Transform) Layer(org.kie.workbench.common.stunner.core.client.canvas.Layer) Test(org.junit.Test)

Example 3 with Layer

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

the class MapSelectionControl method enable.

@Override
public void enable(final H canvasHandler) {
    super.enable(canvasHandler);
    final Layer layer = canvasHandler.getCanvas().getLayer();
    // Click handler for the canvas area - cleans current selection, if any.
    final MouseClickHandler clickHandler = new MouseClickHandler() {

        @Override
        public void handle(final MouseClickEvent event) {
            if (event.isButtonLeft() || event.isButtonRight()) {
                clearSelection(false);
                final String canvasRootUUID = getRootUUID();
                fireCanvasClear();
                if (null != canvasRootUUID) {
                    selectionEventConsumer.accept(new CanvasSelectionEvent(canvasHandler, canvasRootUUID));
                }
            }
        }
    };
    layer.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
    this.layerClickHandler = clickHandler;
}
Also used : MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Layer(org.kie.workbench.common.stunner.core.client.canvas.Layer) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 4 with Layer

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

the class BaseNavigateCommand method enableHandlers.

protected void enableHandlers(final boolean enabled) {
    final CanvasHandler handler = getCanvasHandler();
    if (handler == null) {
        return;
    }
    final Layer layer = handler.getCanvas().getLayer();
    if (enabled) {
        layer.enableHandlers();
        ((AbstractClientSession) sessionManager.getCurrentSession()).resume();
    } else {
        layer.disableHandlers();
        ((AbstractClientSession) sessionManager.getCurrentSession()).pause();
    }
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) AbstractClientSession(org.kie.workbench.common.stunner.core.client.session.impl.AbstractClientSession) Layer(org.kie.workbench.common.stunner.core.client.canvas.Layer)

Aggregations

Layer (org.kie.workbench.common.stunner.core.client.canvas.Layer)4 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3 Test (org.junit.Test)2 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)2 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)2 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)2 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)2 Collections (java.util.Collections)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)1 Transform (org.kie.workbench.common.stunner.core.client.canvas.Transform)1 CanvasShapeRemovedEvent (org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasShapeRemovedEvent)1 CanvasClearSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent)1 AbstractClientSession (org.kie.workbench.common.stunner.core.client.session.impl.AbstractClientSession)1 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)1 ShapeState (org.kie.workbench.common.stunner.core.client.shape.ShapeState)1