Search in sources :

Example 6 with IPrimitive

use of com.ait.lienzo.client.core.shape.IPrimitive in project lienzo-core by ahome-it.

the class LienzoHandlerManager method findPrimitiveForPredicate.

private final IPrimitive<?> findPrimitiveForPredicate(final INodeXYEvent event, final Predicate<IPrimitive<?>> pred) {
    NFastArrayList<IPrimitive<?>> list = null;
    EventPropagationMode stop = EventPropagationMode.LAST_ANCESTOR;
    Node<?> node = findShapeAtPoint(event.getX(), event.getY());
    while ((null != node) && (null != node.asPrimitive())) {
        final IPrimitive<?> prim = node.asPrimitive();
        if (pred.test(prim)) {
            final EventPropagationMode mode = prim.getEventPropagationMode();
            if (null == list) {
                list = new NFastArrayList<>();
            }
            list.add(prim);
            if (mode == EventPropagationMode.NO_ANCESTORS) {
                return prim;
            }
            if (mode.getOrder() < stop.getOrder()) {
                stop = mode;
                break;
            }
        }
        node = node.getParent();
    }
    if ((list != null) && (list.isEmpty() == false)) {
        final int size = list.size();
        if (stop == EventPropagationMode.FIRST_ANCESTOR) {
            if (size > 1) {
                return list.get(1);
            }
        } else {
            if (size > 1) {
                return list.get(size - 1);
            }
        }
        return list.get(0);
    }
    return null;
}
Also used : IPrimitive(com.ait.lienzo.client.core.shape.IPrimitive) EventPropagationMode(com.ait.lienzo.shared.core.types.EventPropagationMode) TouchPoint(com.ait.lienzo.client.core.event.TouchPoint)

Aggregations

IPrimitive (com.ait.lienzo.client.core.shape.IPrimitive)6 Test (org.junit.Test)2 TouchPoint (com.ait.lienzo.client.core.event.TouchPoint)1 Group (com.ait.lienzo.client.core.shape.Group)1 Shape (com.ait.lienzo.client.core.shape.Shape)1 ControlHandleList (com.ait.lienzo.client.core.shape.wires.ControlHandleList)1 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)1 MagnetManager (com.ait.lienzo.client.core.shape.wires.MagnetManager)1 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)1 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)1 AlignAndDistributeControl (com.ait.lienzo.client.core.shape.wires.handlers.AlignAndDistributeControl)1 AlignAndDistributeControlImpl (com.ait.lienzo.client.core.shape.wires.handlers.impl.AlignAndDistributeControlImpl)1 Point2D (com.ait.lienzo.client.core.types.Point2D)1 EventPropagationMode (com.ait.lienzo.shared.core.types.EventPropagationMode)1 HandlerRegistrationManager (com.ait.tooling.nativetools.client.event.HandlerRegistrationManager)1 Iterator (java.util.Iterator)1 CanvasControlPointDoubleClickEvent (org.kie.workbench.common.stunner.core.client.canvas.event.controlpoint.CanvasControlPointDoubleClickEvent)1 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)1 Decorator (org.kie.workbench.common.stunner.lienzo.Decorator)1 ItemCallback (org.kie.workbench.common.stunner.lienzo.Decorator.ItemCallback)1