View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.krad.uif.widget;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
21  import org.kuali.rice.krad.uif.component.Component;
22  import org.kuali.rice.krad.uif.view.View;
23  
24  /**
25   * Widget that renders a Tooltip on a component
26   *
27   * <p>
28   * Tooltips can display extra information about an element. The content can be plain text or rich HTML. Tooltips
29   * can be triggered by focus or mouse hover events.
30   * </p>
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  @BeanTags(
35          {@BeanTag(name = "tooltip-bean", parent = "Uif-Tooltip"), @BeanTag(name = "tooltipHelp-bean", parent = "Uif-TooltipHelp"),
36                  @BeanTag(name = "tooltipFocus-bean", parent = "Uif-TooltipFocus")})
37  public class Tooltip extends WidgetBase {
38  
39      private String tooltipContent;
40  
41      private boolean onFocus;
42      private boolean onMouseHover;
43  
44      public Tooltip() {
45          super();
46      }
47  
48      /**
49       * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View,
50       *      Object, org.kuali.rice.krad.uif.component.Component)
51       */
52      @Override
53      public void performFinalize(View view, Object model, Component parent) {
54          super.performFinalize(view, model, parent);
55      }
56  
57      /**
58       * Plain text or HTML string that will be used to render the tooltip div
59       *
60       * @return String
61       */
62      @BeanTagAttribute(name = "tooltipContent")
63      public String getTooltipContent() {
64          return tooltipContent;
65      }
66  
67      /**
68       * Setter for the tooltip content text
69       *
70       * @param tooltipContent
71       */
72      public void setTooltipContent(String tooltipContent) {
73          if (tooltipContent != null) {
74              this.tooltipContent = tooltipContent.replace("\"", "&quot;").replace("'", "&apos;");
75          } else {
76              this.tooltipContent = null;
77          }
78      }
79  
80      /**
81       * Indicates the tooltip should be triggered by focus/blur
82       *
83       * @return boolean
84       */
85      @BeanTagAttribute(name = "onFocus")
86      public boolean isOnFocus() {
87          return onFocus;
88      }
89  
90      /**
91       * Setter for the onFocus
92       *
93       * @param onFocus
94       */
95      public void setOnFocus(boolean onFocus) {
96          this.onFocus = onFocus;
97      }
98  
99      /**
100      * Indicates the tooltip should be triggered by mouse hover
101      *
102      * @return boolean
103      */
104     @BeanTagAttribute(name = "onMouseHover")
105     public boolean isOnMouseHover() {
106         return onMouseHover;
107     }
108 
109     /**
110      * Setter for onMouseHover
111      *
112      * @param onMouseHover
113      */
114     public void setOnMouseHover(boolean onMouseHover) {
115         this.onMouseHover = onMouseHover;
116     }
117 
118     /**
119      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
120      */
121     @Override
122     protected <T> void copyProperties(T component) {
123         super.copyProperties(component);
124         Tooltip tooltipCopy = (Tooltip) component;
125         tooltipCopy.setTooltipContent(this.getTooltipContent());
126         tooltipCopy.setOnFocus(this.isOnFocus());
127         tooltipCopy.setOnMouseHover(this.isOnMouseHover());
128     }
129 }