I have potentially several click handlers on a widget. The first one is
used to capture click events on an image (then the event is fired on the
image) within the widget and created at creation time. The other ones are
added "outside" of the widget's code.
I would like to cancel (not remove) the other handlers if it's the image
that is being clicked but I just can't find a way to do so. Any help would
be appreciated.
Here's the code I use... for some reason if I don't capture teh click and
fire the event on the image (in the constructor) it just doesn't trigger
the event. May be if I can solve that problem another way to start with? I
have the feeling the issue comes form the DOM.appendChild.
public class IconAnchorActions extends IconAnchor {
private List<Image> actions = new ArrayList<Image>();
public IconAnchorActions(){
super();
addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
for(Image image : actions) {
if(event.getNativeEvent().getEventTarget().equals(image.getElement())) {
image.fireEvent(new GwtEvent<ClickHandler>() {
@Override
public
com.google.gwt.event.shared.GwtEvent.Type<ClickHandler> getAssociatedType()
{
return ClickEvent.getType();
}
@Override
protected void dispatch(ClickHandler handler) {
handler.onClick(null);
}
});
event.stopPropagation();
return;
}
}
}
});
}
public void addClickAction(ImageResource imageResource, ClickHandler
clickHandler, boolean left) {
Image image = new Image(imageResource);
actions.add(image);
image.getElement().getStyle().setVerticalAlign(VerticalAlign.MIDDLE);
if(left) {
image.getElement().getStyle().setFloat(Float.LEFT);
span.getStyle().setMarginLeft(5, Unit.PX);
} else {
image.getElement().getStyle().setFloat(Float.RIGHT);
span.getStyle().setMarginRight(5, Unit.PX);
}
image.getElement().getStyle().setCursor(Cursor.POINTER);
image.addClickHandler(clickHandler);
DOM.appendChild(getElement(), image.getElement());
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/4VLv8cqG9Y8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.