Search in sources :

Example 1 with MouseEvent

use of elemental.events.MouseEvent in project che by eclipse.

the class Tooltip method attachToTargetElement.

/**
     * Adds event handlers to the target element for the tooltip to show it on
     * hover, and update position on mouse move.
     */
private List<EventRemover> attachToTargetElement() {
    List<EventRemover> removers = new ArrayList<>();
    for (int i = 0; i < targetElements.size(); i++) {
        final Element targetElement = targetElements.get(i);
        addPartner(targetElement);
        removers.add(targetElement.addEventListener(Event.MOUSEOUT, new EventListener() {

            @Override
            public void handleEvent(Event evt) {
                MouseEvent mouseEvt = (MouseEvent) evt;
                EventTarget relatedTarget = mouseEvt.getRelatedTarget();
                // Ignore the event unless we mouse completely out of the target element.
                if (relatedTarget == null || !targetElement.contains((Node) relatedTarget)) {
                    cancelPendingShow();
                }
            }
        }, false));
        removers.add(targetElement.addEventListener(Event.MOUSEDOWN, new EventListener() {

            @Override
            public void handleEvent(Event evt) {
                cancelPendingShow();
                hide();
            }
        }, false));
    }
    return removers;
}
Also used : MouseEvent(elemental.events.MouseEvent) EventRemover(elemental.events.EventRemover) Element(elemental.dom.Element) ArrayList(java.util.ArrayList) Event(elemental.events.Event) MouseEvent(elemental.events.MouseEvent) EventListener(elemental.events.EventListener) EventTarget(elemental.events.EventTarget)

Example 2 with MouseEvent

use of elemental.events.MouseEvent in project che by eclipse.

the class MouseCaptureListener method handleEvent.

@Override
public void handleEvent(Event evt) {
    MouseEvent mouseEvent = (MouseEvent) evt;
    updateXYState(mouseEvent);
    if (evt.getType().equals(Event.MOUSEMOVE)) {
        onMouseMove(mouseEvent);
    } else if (evt.getType().equals(Event.MOUSEUP)) {
        release();
        onMouseUp(mouseEvent);
    } else if (evt.getType().equals(Event.MOUSEDOWN)) {
        if (onMouseDown(mouseEvent)) {
            // Start the capture
            MouseEventCapture.capture(this);
            mouseEvent.preventDefault();
        }
    }
}
Also used : MouseEvent(elemental.events.MouseEvent)

Example 3 with MouseEvent

use of elemental.events.MouseEvent in project flow by vaadin.

the class GwtTemplateBinderTest method testEventHandler.

public void testEventHandler() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    templateNode.addEventHandler("click", "$element.id='foo'");
    Element element = createElement(templateNode);
    MouseEvent event = (MouseEvent) Browser.getDocument().createEvent(Events.MOUSE);
    event.initMouseEvent("click", true, true, Browser.getWindow(), 0, 0, 0, 0, 0, false, false, false, false, 0, element);
    Browser.getDocument().getBody().appendChild(element);
    element.dispatchEvent(event);
    assertEquals("foo", element.getAttribute("id"));
}
Also used : MouseEvent(elemental.events.MouseEvent) Element(elemental.dom.Element)

Example 4 with MouseEvent

use of elemental.events.MouseEvent in project flow by vaadin.

the class GwtTemplateBinderTest method testServerEventHandlerInNgFor.

public void testServerEventHandlerInNgFor() {
    TestElementTemplateNode parent = TestElementTemplateNode.create("div");
    String operation = "operation";
    // ============= create <li *ngFor> ===============================
    String collectionVar = "items";
    TestForTemplateNode templateNode = TestTemplateNode.create(ForTemplateNode.TYPE);
    int templateId = 42;
    registry.getTemplateRegistry().register(templateId, templateNode);
    TestElementTemplateNode forChild = TestElementTemplateNode.create("li");
    templateNode.setCollectionVariable(collectionVar);
    forChild.addEventHandler("click", "$server." + operation + "()");
    int forChildId = 11;
    registry.getTemplateRegistry().register(forChildId, forChild);
    templateNode.setChildrenIds(new double[] { forChildId });
    parent.setChildrenIds(new double[] { templateId });
    NodeMap model = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    MapProperty property = model.getProperty(collectionVar);
    StateNode modelNode = new StateNode(1, tree);
    property.setValue(modelNode);
    // ================== now modelNode is NG FOR model node ==========
    StateNode varNode = new StateNode(2, tree);
    com.vaadin.client.flow.nodefeature.NodeList modelList = modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST);
    // add one item to the "collection" model
    modelList.add(0, varNode);
    stateNode.getList(NodeFeatures.CLIENT_DELEGATE_HANDLERS).set(0, operation);
    Element element = createElement(parent);
    Reactive.flush();
    MouseEvent event = (MouseEvent) Browser.getDocument().createEvent(Events.MOUSE);
    event.initMouseEvent("click", true, true, Browser.getWindow(), 0, 0, 0, 0, 0, false, false, false, false, 0, element);
    Browser.getDocument().getBody().appendChild(element);
    element.getElementsByTagName("li").item(0).dispatchEvent(event);
    assertEquals(1, serverMethods.size());
    assertNotNull(serverMethods.get(operation));
    assertEquals(stateNode.getId(), serverRpcNodes.get(operation).getId());
}
Also used : MouseEvent(elemental.events.MouseEvent) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 5 with MouseEvent

use of elemental.events.MouseEvent in project flow by vaadin.

the class GwtTemplateBinderTest method testClientDelegateHandler_noArgs.

public void testClientDelegateHandler_noArgs() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    String operation = "operation";
    templateNode.addEventHandler("click", "$server." + operation + "()");
    stateNode.getList(NodeFeatures.CLIENT_DELEGATE_HANDLERS).set(0, operation);
    Element element = createElement(templateNode);
    MouseEvent event = (MouseEvent) Browser.getDocument().createEvent(Events.MOUSE);
    event.initMouseEvent("click", true, true, Browser.getWindow(), 0, 0, 0, 0, 0, false, false, false, false, 0, element);
    Browser.getDocument().getBody().appendChild(element);
    element.dispatchEvent(event);
    assertEquals(1, serverMethods.size());
    JsArray<?> args = serverMethods.get(operation);
    assertNotNull(args);
    assertEquals(0, args.length());
}
Also used : MouseEvent(elemental.events.MouseEvent) Element(elemental.dom.Element)

Aggregations

MouseEvent (elemental.events.MouseEvent)6 Element (elemental.dom.Element)5 StateNode (com.vaadin.client.flow.StateNode)1 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)1 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 EventRemover (elemental.events.EventRemover)1 EventTarget (elemental.events.EventTarget)1 JsonObject (elemental.json.JsonObject)1 ArrayList (java.util.ArrayList)1