Example usage for com.google.gwt.query.client.plugins.events GqEvent getEventTarget

List of usage examples for com.google.gwt.query.client.plugins.events GqEvent getEventTarget

Introduction

In this page you can find the example usage for com.google.gwt.query.client.plugins.events GqEvent getEventTarget.

Prototype

public final EventTarget getEventTarget() 

Source Link

Document

Returns the element that was the actual target of the given event.

Usage

From source file:gwtquery.plugins.draggable.client.Draggable.java

License:Apache License

private boolean isHandleClicked(Element draggable, final GqEvent event) {
    DraggableOptions options = getOptions(draggable);
    // if no handle or if specified handle is not inside the draggable element,
    // continue//from www.  j a v  a 2s.c  om
    if (options.getHandle() == null || $(options.getHandle(), draggable).length() == 0) {
        return true;
    }

    // OK, we have a valid handle, check if we are clicking on the handle object
    // or one of its descendants
    GQuery handleAndDescendant = $(options.getHandle(), draggable).find("*").andSelf();
    for (Element e : handleAndDescendant.elements()) {
        if (e == event.getEventTarget().cast()) {
            return true;
        }
    }
    return false;
}

From source file:gwtquery.plugins.selectable.client.Selectable.java

License:Apache License

protected void onSelectionStart(Element selectable, GqEvent event) {

    trigger(new SelectionStartEvent(selectable), options.getOnStartSelection(), selectable);

    if (isLassoSelectionEnable(event)) {
        opos = new int[] { event.pageX(), event.pageY() };
        lasso.show(opos[0], opos[1], options.getAppendTo());
    }/*from  w w  w  .j a  v a 2 s.  co  m*/

    if (options.isAutoRefresh()) {
        refreshSelectees(selectable);
    }

    GQuery selectedSelectees = $(selectable).data(SELECTEES_KEY, GQuery.class)
            .filter("." + CssClassNames.UI_SELECTED);

    for (Element e : selectedSelectees.elements()) {
        SelectableItem si = $(e).data(SELECTABLE_ITEM_KEY, SelectableItem.class);
        si.setStartSelected(true);
        // if not meta-key or ctrl-keypressed, unselect elements
        if (!isMetaKeyEnabled(event)) {
            si.unselecting();
            trigger(new UnselectingEvent(e), options.getOnUnselecting(), e);
        }
    }

    // remove old selected (case where filter was change before this
    // selection) if no meta-key was pressed
    if (!isMetaKeyEnabled(event)) {
        GQuery oldSelected = $('.' + CssClassNames.UI_SELECTED, selectable);
        for (Element e : oldSelected.elements()) {
            SelectableItem si = $(e).data(SELECTABLE_ITEM_KEY, SelectableItem.class);
            if (si == null) { // old selectee
                e.removeClassName(CssClassNames.UI_SELECTED);
                trigger(new UnselectedEvent(e), options.getOnUnselected(), e);
            }
        }
    }

    // retrieve the element that was the target of the event and its parents
    // (maybe one of the parent is the selectee)
    GQuery eventTarget = $((Element) event.getEventTarget().cast());
    GQuery parentsAndSelf = eventTarget.parents().add(eventTarget);
    for (Element e : parentsAndSelf.elements()) {
        SelectableItem si = $(e).data(SELECTABLE_ITEM_KEY, SelectableItem.class);
        if (si != null) {
            // ok a selectable-item exists on the element...
            // it is a selectable element
            boolean doSelection = !isMetaKeyEnabled(event) || !si.isSelected();
            if (doSelection) {
                si.selecting();
                trigger(new SelectingEvent(e), options.getOnSelecting(), e);
            } else {
                si.unselecting();
                trigger(new UnselectingEvent(e), options.getOnUnselecting(), e);
            }

        }
    }
}