List of usage examples for org.w3c.dom.events EventTarget dispatchEvent
public boolean dispatchEvent(Event evt) throws EventException;
From source file:de.betterform.xml.events.impl.DefaultXMLEventService.java
/** * Dispatches the specified event to the given target. * * @param target the event target./*from ww w . j a va2 s . co m*/ * @param type specifies the event type. * @param bubbles specifies wether the event can bubble. * @param cancelable specifies wether the event's default action can be prevented. * @param context optionally specifies contextual information. * @return <code>true</code> if one of the event listeners called * <code>preventDefault</code>, otherwise <code>false</code>. */ public boolean dispatch(EventTarget target, String type, boolean bubbles, boolean cancelable, Object context) { if (LOGGER.isDebugEnabled()) { if (target instanceof Node) { Node node = (Node) target; Object object = node.getUserData(""); if (object instanceof XFormsElement) { //Note: the cast seems pointless here but makes sure the right toString method is called LOGGER.debug("dispatch event: " + type + " to " + ((XFormsElement) object).toString()); } } else { LOGGER.debug("dispatch event: " + type + " to " + target); } } XMLEvent event = this.eventFactory.createXMLEvent(type); this.eventInitializer.initXMLEvent(event, type, bubbles, cancelable, context); long start; long end; start = System.currentTimeMillis(); boolean preventDefault = target.dispatchEvent(event); end = System.currentTimeMillis(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("dispatch event: " + type + " handling needed " + (end - start) + " ms"); } if (!event.getCancelable() || !preventDefault) { DefaultAction action = lookup(target, type); if (action != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("dispatch event: " + type + " default action at " + action); } // todo: set event phase without downcast ? ((XercesXMLEvent) event).eventPhase = XMLEvent.DEFAULT_ACTION; start = System.currentTimeMillis(); action.performDefault(event); end = System.currentTimeMillis(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("dispatch event: " + type + " default action needed " + (end - start) + " ms"); } } } return preventDefault; }
From source file:org.chiba.xml.events.impl.DefaultXMLEventService.java
/** * Dispatches the specified event to the given target. * * @param target the event target./*from w ww . j a va 2s .c o m*/ * @param type specifies the event type. * @param bubbles specifies wether the event can bubble. * @param cancelable specifies wether the event's default action can be prevented. * @param context optionally specifies contextual information. * @return <code>true</code> if one of the event listeners called * <code>preventDefault</code>, otherwise <code>false</code>. */ public boolean dispatch(EventTarget target, String type, boolean bubbles, boolean cancelable, Object context) { if (LOGGER.isDebugEnabled()) { if (target instanceof NodeImpl) { NodeImpl node = (NodeImpl) target; Object object = node.getUserData(); if (object instanceof XFormsElement) { //Note: the cast seems pointless here but makes sure the right toString method is called LOGGER.debug("dispatch event: " + type + " to " + ((XFormsElement) object).toString()); } } else { LOGGER.debug("dispatch event: " + type + " to " + target); } } XMLEvent event = this.eventFactory.createXMLEvent(type); this.eventInitializer.initXMLEvent(event, type, bubbles, cancelable, context); long start; long end; start = System.currentTimeMillis(); boolean preventDefault = target.dispatchEvent(event); end = System.currentTimeMillis(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("dispatch event: " + type + " handling needed " + (end - start) + " ms"); } if (!event.getCancelable() || !preventDefault) { DefaultAction action = lookup(target, type); if (action != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("dispatch event: " + type + " default action at " + action); } // todo: set event phase without downcast ? ((XercesXMLEvent) event).eventPhase = XMLEvent.DEFAULT_ACTION; start = System.currentTimeMillis(); action.performDefault(event); end = System.currentTimeMillis(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("dispatch event: " + type + " default action needed " + (end - start) + " ms"); } } } return preventDefault; }
From source file:org.chiba.xml.xforms.Container.java
/** * Dispatches an Event of the specified type to the given eventType targetId. * * @param eventTarget the target Node for this Event * @param eventType the type of Event/*from w ww .j a v a 2 s . co m*/ * @param info an additional info object * @return true, if Event was cancelled by an Listener */ public boolean dispatch(EventTarget eventTarget, String eventType, Object info) throws XFormsException { if (this.eventFactory == null) { this.eventFactory = new EventFactory(); } Event event = EventFactory.createEvent(eventType, info); if (LOGGER.isDebugEnabled()) { LOGGER.debug("dispatching '" + event.getType() + "' to " + eventTarget); } boolean result = eventTarget.dispatchEvent(event); // exception during event flow ? if (this.eventException != null) { XFormsException xfe = null; if (this.eventException instanceof XFormsErrorIndication) { if (((XFormsErrorIndication) this.eventException).isFatal()) { // downcast fatal error for rethrowal xfe = (XFormsException) this.eventException; } } else { // wrap exception for rethrowal xfe = new XFormsException(this.eventException); } // remove exception in either case this.eventException = null; if (xfe != null) { throw xfe; } } return result; }