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;
}
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();
}
}
}
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"));
}
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());
}
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());
}
Aggregations