View Javadoc

1   /*
2    * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }