1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwtwidgets.client.wwrapper;
18
19 import com.google.gwt.user.client.DOM;
20 import com.google.gwt.user.client.Element;
21 import com.google.gwt.user.client.Event;
22 import com.google.gwt.user.client.ui.Hyperlink;
23
24
25 public class WHyperlink extends Hyperlink implements WrappedWidget
26 {
27 private static final String WIDGET_TYPE = "hyperlink";
28 private Element anchorElem;
29
30
31 public WHyperlink (String id)
32 throws ElementNotFoundException
33 {
34 super();
35 anchorElem = DOM.getElementById(id);
36
37 if (anchorElem == null) {
38 throw new ElementNotFoundException(id);
39 }
40
41 setElement(anchorElem);
42 sinkEvents(Event.ONCLICK);
43 WBuilder.resetElement(this);
44 }
45
46 public WHyperlink (Element element)
47 {
48 super();
49 anchorElem = element;
50 setElement(anchorElem);
51 sinkEvents(Event.ONCLICK);
52 WBuilder.resetElement(this);
53 }
54
55 public String getHTML ()
56 {
57 return DOM.getInnerHTML(anchorElem);
58 }
59
60 public String getText ()
61 {
62 return DOM.getInnerText(anchorElem);
63 }
64
65 public void setHTML (String html)
66 {
67 DOM.setInnerHTML(anchorElem, html);
68 }
69
70 public void setTargetHistoryToken (String targetHistoryToken)
71 {
72 super.setTargetHistoryToken(targetHistoryToken);
73 DOM.setAttribute(anchorElem, "href", "#" + targetHistoryToken);
74 }
75
76 public void setText (String text)
77 {
78 DOM.setInnerHTML(anchorElem, text);
79 }
80
81 public String getWidgetType ()
82 {
83 return WIDGET_TYPE;
84 }
85
86 public String getHref ()
87 {
88 return DOM.getAttribute(anchorElem, "href");
89 }
90
91 }