Search in sources :

Example 1 with SelectionChangedEvent

use of com.gwtmobile.ui.client.event.SelectionChangedEvent in project GwtMobile by dennisjzh.

the class CheckBoxGroup method onClick.

@Override
public void onClick(ClickEvent e) {
    final EventTarget target = e.getNativeEvent().getEventTarget();
    String targetTagName = ((Element) target.cast()).getTagName().toUpperCase();
    Utils.Console("onClick target " + targetTagName);
    if (targetTagName.equals("LABEL")) {
        // if check box label is click, another (simulated) click event with
        return;
    // check box INPUT as target will fire after this one. So this click event
    // can be safely ignored.
    }
    Element div = Element.as(target);
    while (!div.getNodeName().toUpperCase().equals("SPAN") || div.getParentElement() != this.getElement()) {
        div = div.getParentElement();
        if (div == null) {
            Utils.Console("CheckBoxGroup onClick: span not found");
            return;
        }
    }
    final int index = DOM.getChildIndex(this.getElement(), (com.google.gwt.user.client.Element) div);
    com.google.gwt.user.client.ui.CheckBox checkbox = (com.google.gwt.user.client.ui.CheckBox) _panel.getWidget(index);
    Utils.Console("onClick " + checkbox.getValue());
    if (targetTagName.equals("INPUT")) {
        Utils.Console("onClick value changed");
        // if target is check box INPUT, check box value is 
        checkbox.setValue(checkbox.getValue());
    // already changed when click event is fired.
    // just need to set its current value back to the check box
    // to update style.
    } else {
        checkbox.setValue(!checkbox.getValue());
    }
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(index, target);
            fireEvent(selectionChangedEvent);
        }
    });
}
Also used : Element(com.google.gwt.dom.client.Element) SelectionChangedEvent(com.gwtmobile.ui.client.event.SelectionChangedEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) EventTarget(com.google.gwt.dom.client.EventTarget)

Example 2 with SelectionChangedEvent

use of com.gwtmobile.ui.client.event.SelectionChangedEvent in project GwtMobile by dennisjzh.

the class ListPanel method onClick.

@Override
public void onClick(ClickEvent e) {
    if (_selected >= 0) {
        ListItem item = (ListItem) getWidget(_selected);
        if (!item.getDisabled()) {
            SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(_selected, e.getNativeEvent().getEventTarget());
            this.fireEvent(selectionChangedEvent);
            item.removeStyleName("Pressed");
        }
        _selected = -1;
    }
}
Also used : SelectionChangedEvent(com.gwtmobile.ui.client.event.SelectionChangedEvent)

Aggregations

SelectionChangedEvent (com.gwtmobile.ui.client.event.SelectionChangedEvent)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Element (com.google.gwt.dom.client.Element)1 EventTarget (com.google.gwt.dom.client.EventTarget)1