You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TooltipInfo.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * 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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client;
  17. import com.vaadin.shared.ui.ErrorLevel;
  18. import com.vaadin.shared.ui.label.ContentMode;
  19. import com.vaadin.shared.util.SharedUtil;
  20. /**
  21. * An object that contains information about a tooltip, such as the tooltip's
  22. * title, error message, error level and an ID.
  23. */
  24. public class TooltipInfo {
  25. private String title;
  26. private String errorMessageHtml;
  27. private ErrorLevel errorLevel;
  28. private ContentMode contentMode = ContentMode.HTML;
  29. // Contains the tooltip's identifier. If a tooltip's contents and this
  30. // identifier haven't changed, the tooltip won't be updated in subsequent
  31. // events.
  32. private Object identifier;
  33. /**
  34. * Constructs a new tooltip info instance.
  35. */
  36. public TooltipInfo() {
  37. }
  38. /**
  39. * Constructs a new tooltip info instance.
  40. *
  41. * @param tooltip
  42. * tooltip title
  43. */
  44. public TooltipInfo(String tooltip) {
  45. setTitle(tooltip);
  46. }
  47. /**
  48. * Constructs a new tooltip info instance.
  49. *
  50. * @param tooltip
  51. * tooltip title
  52. * @param errorMessage
  53. * error message
  54. */
  55. public TooltipInfo(String tooltip, String errorMessage) {
  56. this(tooltip, errorMessage, null);
  57. }
  58. /**
  59. * Constructs a new tooltip info instance.
  60. *
  61. * @param tooltip
  62. * tooltip title
  63. * @param errorMessage
  64. * error message
  65. * @param identifier
  66. * the tooltip's identifier
  67. */
  68. public TooltipInfo(String tooltip, String errorMessage, Object identifier) {
  69. this(tooltip, errorMessage, identifier, null);
  70. }
  71. /**
  72. * Constructs a new tooltip info instance.
  73. *
  74. * @param tooltip
  75. * tooltip title
  76. * @param errorMessage
  77. * error message
  78. * @param identifier
  79. * the tooltip's identifier
  80. * @param errorLevel
  81. * error level
  82. *
  83. * @since 7.7.11
  84. */
  85. public TooltipInfo(String tooltip, String errorMessage, Object identifier,
  86. ErrorLevel errorLevel) {
  87. setIdentifier(identifier);
  88. setTitle(tooltip);
  89. setErrorMessage(errorMessage);
  90. setErrorLevel(errorLevel);
  91. }
  92. /**
  93. * Sets the tooltip's identifier.
  94. *
  95. * @param identifier
  96. * the identifier to set
  97. */
  98. public void setIdentifier(Object identifier) {
  99. this.identifier = identifier;
  100. }
  101. /**
  102. * Gets the tooltip's identifier.
  103. *
  104. * @return the identifier
  105. */
  106. public Object getIdentifier() {
  107. return identifier;
  108. }
  109. /**
  110. * Gets the tooltip title.
  111. *
  112. * @return the title
  113. */
  114. public String getTitle() {
  115. return title;
  116. }
  117. /**
  118. * Sets the tooltip title.
  119. *
  120. * @param title
  121. * the title to set
  122. */
  123. public void setTitle(String title) {
  124. this.title = title;
  125. }
  126. /**
  127. * Gets the error message.
  128. *
  129. * @return the error message
  130. */
  131. public String getErrorMessage() {
  132. return errorMessageHtml;
  133. }
  134. /**
  135. * Sets the error message.
  136. *
  137. * @param errorMessage
  138. * the error message to set
  139. */
  140. public void setErrorMessage(String errorMessage) {
  141. errorMessageHtml = errorMessage;
  142. }
  143. /**
  144. * Gets the error level.
  145. *
  146. * @return the error level
  147. * @since 7.7.11
  148. */
  149. public ErrorLevel getErrorLevel() {
  150. return errorLevel;
  151. }
  152. /**
  153. * Sets the error level.
  154. *
  155. * @param errorLevel
  156. * the error level to set
  157. * @since 7.7.11
  158. */
  159. public void setErrorLevel(ErrorLevel errorLevel) {
  160. this.errorLevel = errorLevel;
  161. }
  162. /**
  163. * Checks is a message has been defined for the tooltip.
  164. *
  165. * @return true if title or error message is present, false if both are
  166. * empty
  167. */
  168. public boolean hasMessage() {
  169. return (title != null && !title.isEmpty())
  170. || (errorMessageHtml != null && !errorMessageHtml.isEmpty());
  171. }
  172. /**
  173. * Indicates whether another tooltip info instance is equal to this one. Two
  174. * instances are equal if their title, error message, error level and
  175. * identifier are equal.
  176. *
  177. * @param other
  178. * the reference tooltip info instance with which to compare
  179. * @return {@code true} if the instances are equal, {@code false} otherwise
  180. */
  181. public boolean equals(TooltipInfo other) {
  182. return (other != null && SharedUtil.equals(other.title, title)
  183. && SharedUtil.equals(other.errorMessageHtml, errorMessageHtml)
  184. && SharedUtil.equals(other.errorLevel, errorLevel)
  185. && other.identifier == identifier);
  186. }
  187. /**
  188. * Gets the tooltip title's content mode.
  189. *
  190. * @since
  191. *
  192. * @return the content mode
  193. */
  194. public ContentMode getContentMode() {
  195. return contentMode;
  196. }
  197. /**
  198. * Sets the tooltip title's content mode.
  199. *
  200. * @since
  201. *
  202. * @param contentMode
  203. * the content mode to set
  204. */
  205. public void setContentMode(ContentMode contentMode) {
  206. this.contentMode = contentMode;
  207. }
  208. }