On 27 avr, 22:26, Gavin  Andresen <[email protected]> wrote:
> First, what I'm trying to do:
>
> I've got a page with lots of hyperlinks on it (plain-old <a href=...>
> tags).
>
> When the user shift-clicks on links that match a certain pattern
> (e.g. /author/AUTHOR_IDENTIFIER), I popup a dialog box that lets them
> perform an edit INSTEAD of following the link.
>
> In GWT 1.5, I did this:
>
>     public void onModuleLoad() {
>         ...
>         DOM.addEventPreview
> (this);
>   }
>
>   //
>   // look for shift-clicks on paper/author links, and pops
> up
>   // edit dialog
> boxes:
>   //
>   public boolean onEventPreview(Event event) {
>     if (DOM.eventGetType(event) != Event.ONCLICK) { return true; }
>     if (!event.getShiftKey()) { return true; }
>
>     Element e = event.getTarget();
>     String href = e.getAttribute("href");
>     if (href == null || href.length() == 0){ return true; }
>
>     if (href.contains("/paper/")) {
>       String paperPID = InterfaceUtils.getPIDFromLinkString(href,
> "paper/");
>       fetchPaperInfoThenEdit(paperPID);
>       return false;
>     }
>     else if (href.contains("/author/")) {
>       String authorPID = InterfaceUtils.getPIDFromLinkString(href,
> "author/");
>       Map<String,String> params = InterfaceUtils.parseURLParams(href);
>       fetchAuthorInfoThenEdit(authorPID, params.get("fromPaper"));
>       return false;
>     }
>     return true;
>   }
>
> In 1.6, I've rewritten the code to use onPreviewNativeEvent(), but
> it's not working; if I cancel() or consume() (or both) the
> NativePreviewEvent, the browser STILL follows the link.

If you consume() the event, it'll be propagated to the link and cannot
be canceled by another NativePreviewHandler; so consume() is really
not the method you should be using here.

Re. cancel(), first check if the vent hasn't already been consumed()d
by a preview handler, with pe.isConsumed(), or eventually check that
you are the first handler (pe.isFirstHandler()).

I have no other idea... (apart from a possible bug in GWT...)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to