Is it good there are both Anchor and HyperLink?

369 views
Skip to first unread message

Dapeng

unread,
Nov 4, 2009, 12:20:55 AM11/4/09
to Google Web Toolkit
I notice 2.0M2 deprecates addClickHandler() in HyperLink and suggest
user Anchor instead. But I can't see any benefits that we have two
totally separated widgets for same <a> tag. HyperLink has its
advantage, ie, mouse-right-click open window. However, sometimes,
Hyperlink also needs handle some mouse events.

For example, in my scenario, there is a hyperlink in a popup panel. I
want to hide this pop then load another history token, I use this
code:

Hyperlink tagCloud = new Hyperlink("view tag cloud", "tagcloudToken");
tagCloud.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
TagPopup.this.hide();
}
});


In 2.0M2, whatever Hyperlink or Anchor, it can't fit the use. If I
use Hyperlink, I have to use a deprecated addClickHandler(). If use
Anchor, it becomes impossible to open window in mouse-right-click.

Any comments?

Thomas Broyer

unread,
Nov 4, 2009, 6:16:33 AM11/4/09
to Google Web Toolkit
Right, HyperlinkImpl should be made somehow public so it would be safe
to use it with Anchor (safe meaning here forwards-compatible; it could
be a public static method of Anchor for instance, hiding the use of
HyperlinkImpl). (may I suggest you file an issue ;-) )

Anchor tagCloud = ...;
tagCloud.addClickHandler(new ClickHandler() {
HyperlinkImpl impl = GWT.create(HyperlinkImpl.class);
public void onClick(ClickEvent event) {
if (impl.handleAsClick(event.getNativeEvent().cast())) {
TagPopup.this.hide();
History.newItem("tagcloudToken");
}
}
});

The above works right now, and with a public static method, it would
turn into:
...
if (Anchor.handleAsClick(event)) {
...
which is much more readable ;-)
Reply all
Reply to author
Forward
0 new messages