Search in sources :

Example 1 with ElementOutOfBoundsException

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

the class AbstractElementBuilderControl method build.

@Override
@SuppressWarnings("unchecked")
public void build(final ElementBuildRequest<AbstractCanvasHandler> request, final BuildCallback buildCallback) {
    if (null == canvasHandler) {
        buildCallback.onSuccess(null);
        return;
    }
    double x = request.getX();
    ;
    double y = request.getY();
    ;
    if (checkOutOfBoundsCanvas(x, y)) {
        buildCallback.onError(new ClientRuntimeError(new ElementOutOfBoundsException("Element is placed outside canvas bounds")));
        return;
    }
    final Object definition = request.getDefinition();
    // Notify processing starts.
    fireProcessingStarted();
    final Node<View<?>, Edge> parent = getParent(x, y);
    final Point2D childCoordinates = getChildCoordinates(parent, x, y);
    getCommands(definition, parent, childCoordinates.getX(), childCoordinates.getY(), new CommandsCallback() {

        @Override
        public void onComplete(final String uuid, final List<Command<AbstractCanvasHandler, CanvasViolation>> commands) {
            getCommandManager().execute(canvasHandler, new CompositeCommand.Builder().addCommands(commands).build());
            buildCallback.onSuccess(uuid);
            // Notify processing ends.
            fireProcessingCompleted();
        }

        @Override
        public void onError(final ClientRuntimeError error) {
            buildCallback.onError(error);
            // Notify processing ends.
            fireProcessingCompleted();
        }
    });
}
Also used : ElementOutOfBoundsException(org.kie.workbench.common.stunner.core.client.canvas.controls.exceptions.ElementOutOfBoundsException) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

ElementOutOfBoundsException (org.kie.workbench.common.stunner.core.client.canvas.controls.exceptions.ElementOutOfBoundsException)1 ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1 RuleContextBuilder (org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder)1