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.  My ported
code looks like this:

  public void onModuleLoad() {
        ...
        Event.addNativePreviewHandler(this);
  }

  //
  // Preview events-- look for shift-clicks on paper/author links, and
pops up
  // edit dialog boxes:
  //
  public void onPreviewNativeEvent(Event.NativePreviewEvent pe) {
    NativeEvent e = pe.getNativeEvent();
    if (Event.getTypeInt(e.getType())  != Event.ONCLICK) { return; }
    if (!e.getShiftKey()) { return; }

    EventTarget target  = e.getEventTarget();
    if (!Element.is(target)) { return; }
    Element elt = Element.as(target);
    String href = elt.getAttribute("href");
    if (href == null || href.length() == 0){ return; }

    if (href.contains("/paper/")) {
      pe.consume();
      pe.cancel();
      String paperPID = InterfaceUtils.getPIDFromLinkString(href,
"paper/");
      fetchPaperInfoThenEdit(paperPID);
    }
    else if (href.contains("/author/")) {
      pe.consume();
      pe.cancel();
      String authorPID = InterfaceUtils.getPIDFromLinkString(href,
"author/");
      Map<String,String> params = InterfaceUtils.parseURLParams(href);
      fetchAuthorInfoThenEdit(authorPID, params.get("fromPaper"));
    }
  }

What am I missing?

--~--~---------~--~----~------------~-------~--~----~
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