Search in sources :

Example 1 with ElementBuildRequestImpl

use of org.kie.workbench.common.stunner.core.client.canvas.controls.builder.request.ElementBuildRequestImpl 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

AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)1 ElementBuildRequestImpl (org.kie.workbench.common.stunner.core.client.canvas.controls.builder.request.ElementBuildRequestImpl)1 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)1 ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)1