Search in sources :

Example 1 with CanvasSelectionEvent

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

the class AbstractToolboxAction method fireElementSelectedEvent.

// TODO: This is a work around. If enabling canvas handlers just here ( without using the timer )
// the layer receives a click event, so it fires a clear selection event and it results
// on the element just added not being selected.
public static void fireElementSelectedEvent(final Event<CanvasSelectionEvent> selectionEvent, final AbstractCanvasHandler canvasHandler, final String uuid) {
    canvasHandler.getCanvas().getLayer().disableHandlers();
    selectionEvent.fire(new CanvasSelectionEvent(canvasHandler, uuid));
    final Timer t = new Timer() {

        @Override
        public void run() {
            canvasHandler.getCanvas().getLayer().enableHandlers();
        }
    };
    t.schedule(500);
}
Also used : CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Timer(com.google.gwt.user.client.Timer)

Example 2 with CanvasSelectionEvent

use of org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent 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 3 with CanvasSelectionEvent

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

the class AbstractSelectionAwareSessionCommandTest method testOnCanvasSelection.

@Test
public void testOnCanvasSelection() {
    CanvasSelectionEvent event = new CanvasSelectionEvent(canvasHandler, "");
    command.onCanvasSelectionEvent(event);
    verify(command, times(1)).handleCanvasSelectionEvent(event);
    event = new CanvasSelectionEvent(anotherCanvasHandler, "");
    command.onCanvasSelectionEvent(event);
    verify(command, never()).handleCanvasSelectionEvent(event);
}
Also used : CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Test(org.junit.Test)

Example 4 with CanvasSelectionEvent

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

the class CanvasInPlaceTextEditorControlImpl method enable.

@Override
public void enable(final AbstractCanvasHandler canvasHandler) {
    super.enable(canvasHandler);
    textEditorBox.initialize(canvasHandler, () -> {
        final String idToSelect = CanvasInPlaceTextEditorControlImpl.this.uuid;
        CanvasInPlaceTextEditorControlImpl.this.hide();
        canvasSelectionEvent.fire(new CanvasSelectionEvent(canvasHandler, idToSelect));
    });
    // TODO: move folatingView to support IsElement instead of IsWidget
    floatingView.hide().setHideCallback(floatingHideCallback).setTimeOut(FLOATING_VIEW_TIMEOUT).add(ElementWrapperWidget.getWidget(textEditorBox.getElement()));
}
Also used : CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)

Example 5 with CanvasSelectionEvent

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

the class ObserverBuilderControl method onBuildCanvasShape.

@SuppressWarnings("unchecked")
void onBuildCanvasShape(@Observes final BuildCanvasShapeEvent buildCanvasShapeEvent) {
    checkNotNull("buildCanvasShapeEvent", buildCanvasShapeEvent);
    if (null != canvasHandler) {
        final CanvasHandler context = buildCanvasShapeEvent.getCanvasHandler();
        if (null != context && context.equals(canvasHandler)) {
            final Object definition = buildCanvasShapeEvent.getDefinition();
            final double x = buildCanvasShapeEvent.getX();
            final double y = buildCanvasShapeEvent.getY();
            final double _x = x >= 0 ? x - canvasHandler.getAbstractCanvas().getAbsoluteX() : -1;
            final double _y = y >= 0 ? y - canvasHandler.getAbstractCanvas().getAbsoluteY() : -1;
            final ElementBuildRequest<AbstractCanvasHandler> request = new ElementBuildRequestImpl(_x, _y, definition);
            ObserverBuilderControl.this.build(request, new BuildCallback() {

                @Override
                public void onSuccess(final String uuid) {
                    canvasHandler.getCanvas().draw();
                    canvasSelectionEvent.fire(new CanvasSelectionEvent(canvasHandler, uuid));
                }

                @Override
                public void onError(final ClientRuntimeError error) {
                    LOGGER.log(Level.SEVERE, error.toString());
                }
            });
        }
    }
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) ElementBuildRequestImpl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.request.ElementBuildRequestImpl)

Aggregations

CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)15 Test (org.junit.Test)10 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)5 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)4 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)3 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Layer (org.kie.workbench.common.stunner.core.client.canvas.Layer)2 CanvasClearSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent)2 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)2 Timer (com.google.gwt.user.client.Timer)1 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 RunWith (org.junit.runner.RunWith)1 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)1 AddConnectorCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand)1 AddNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand)1