Example usage for org.w3c.dom.events Event getEventPhase

List of usage examples for org.w3c.dom.events Event getEventPhase

Introduction

In this page you can find the example usage for org.w3c.dom.events Event getEventPhase.

Prototype

public short getEventPhase();

Source Link

Document

Used to indicate which phase of event flow is currently being evaluated.

Usage

From source file:de.betterform.xml.xforms.action.AbstractAction.java

/**
 * This method is called whenever an event occurs of the type for which the
 * <code>EventListener</code> interface was registered.
 *
 * @param event The <code>Event</code> contains contextual information about
 *              the event. It also contains the <code>stopPropagation</code> and
 *              <code>preventDefault</code> methods which are used in determining the
 *              event's flow and default action.
 *///  w w w .  j  av  a 2  s.c  o m
public final void handleEvent(Event event) {
    try {
        if (event.getType().equals(this.eventType)) {
            boolean doPerform = false;

            if (this.propagate.equals("stop")) {
                event.stopPropagation();
            }
            if (this.defaultAction.equals("cancel")) {
                event.preventDefault();
            }

            if (getLogger().isTraceEnabled()) {
                String currentEventId = (((Element) event.getCurrentTarget()).getAttribute("id"));
                String targetEventId = (((Element) event.getTarget()).getAttribute("id"));
                LOGGER.trace(
                        "currentEventTargetId: '" + currentEventId + "' eventTargetId:'" + targetEventId + "'");

                getLogger().trace("handling event '" + this.eventType + "' target: "
                        + DOMUtil.getCanonicalPath(this.element) + "' Event Phase: (" + event.getEventPhase()
                        + ")");
            }

            if (getLogger().isDebugEnabled()) {
                switch (event.getEventPhase()) {
                case Event.CAPTURING_PHASE:
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("CAPTURING PHASE");
                    }

                    break;
                case Event.AT_TARGET:
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("AT_TARGET");
                    }

                    break;
                case Event.BUBBLING_PHASE:
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("BUBBLING");
                    }
                    break;
                }
            }

            if (event.getEventPhase() == Event.CAPTURING_PHASE && this.phase.equals("capture")) {
                doPerform = true;
            } else if (event.getEventPhase() == Event.AT_TARGET) {
                doPerform = true;
            } else if (event.getEventPhase() == Event.BUBBLING_PHASE) {
                doPerform = true;
            }

            String targetEventId = (((Element) event.getTarget()).getAttribute("id"));
            if (!(this.eventTargetId.equals(""))) {
                if (event.getType().equals(this.eventType) && targetEventId.equals(this.eventTargetId)) {
                    doPerform = true;
                } else {
                    doPerform = false;
                }
            }

            if (doPerform) {
                performConditional(this.element);
            }
        }
    } catch (Exception e) {
        // handle exception, prevent default action and stop event propagation
        this.container.handleEventException(e);
        event.preventDefault();
        event.stopPropagation();
    }
}

From source file:org.chiba.xml.xforms.action.AbstractAction.java

/**
 * This method is called whenever an event occurs of the type for which the
 * <code>EventListener</code> interface was registered.
 *
 * @param event The <code>Event</code> contains contextual information about
 * the event. It also contains the <code>stopPropagation</code> and
 * <code>preventDefault</code> methods which are used in determining the
 * event's flow and default action.//from   ww w .  ja  va  2s .c om
 */
public final void handleEvent(Event event) {
    try {
        if (event.getType().equals(this.eventType)) {
            if (getLogger().isDebugEnabled()) {
                String phase = "";
                switch (event.getEventPhase()) {
                case Event.CAPTURING_PHASE:
                    phase = "capturing phase";
                    break;
                case Event.AT_TARGET:
                    phase = "at target";
                    break;
                case Event.BUBBLING_PHASE:
                    phase = "bubbling phase";
                    break;
                }
                getLogger().debug(this + " handling event '" + this.eventType + "' (" + phase + ")");
            }

            setEvent(event);

            if (event instanceof XMLEvent)
                eventContextInfo = ((XMLEvent) event).getContextInfo();

            performWhileAndIf(this.element);

        }
    } catch (Exception e) {
        // handle exception, prevent default action and stop event propagation
        this.container.handleEventException(e);
        event.preventDefault();
        event.stopPropagation();
    }
}