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 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Copyright 2000-2016 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.ContentMode;
  18. import com.vaadin.shared.ui.ErrorLevel;
  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 ContentMode contentMode;
  27. private String errorMessageHtml;
  28. private ErrorLevel errorLevel;
  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. this(tooltip, ContentMode.PREFORMATTED);
  46. }
  47. /**
  48. * Constructs a new instance using the {@code tooltip} for the title and
  49. * {@code errorMessage} as a description.
  50. *
  51. * @param tooltip
  52. * tooltip title
  53. * @param errorMessage
  54. * error description
  55. *
  56. * @deprecated use {@link #TooltipInfo(String, ContentMode, String)} instead
  57. */
  58. @Deprecated
  59. public TooltipInfo(String tooltip, String errorMessage) {
  60. this(tooltip, ContentMode.HTML, errorMessage, null);
  61. }
  62. /**
  63. * Constructs a new instance using the {@code tooltip} for the title,
  64. * {@code errorMessage} as a description and {@code identifier} as its id.
  65. *
  66. * @param tooltip
  67. * tooltip title
  68. * @param errorMessage
  69. * error description
  70. * @param identifier
  71. * the tooltip's identifier
  72. *
  73. * @deprecated use {@link #TooltipInfo(String, ContentMode, String, Object)}
  74. * instead
  75. */
  76. @Deprecated
  77. public TooltipInfo(String tooltip, String errorMessage, Object identifier) {
  78. this(tooltip, ContentMode.HTML, errorMessage, identifier);
  79. }
  80. /**
  81. * Constructs a new instance using the {@code tooltip} for the title,
  82. * {@code errorMessage} as a description, {@code identifier} as its id and
  83. * {@code errorLevel} as the error level.
  84. *
  85. * @param tooltip
  86. * tooltip title
  87. * @param errorMessage
  88. * error description
  89. * @param identifier
  90. * the tooltip's identifier
  91. * @param errorLevel
  92. * error level
  93. *
  94. * @deprecated use {@link #TooltipInfo(String, ContentMode, String, Object,
  95. * ErrorLevel)} instead
  96. * @since 8.2
  97. */
  98. @Deprecated
  99. public TooltipInfo(String tooltip, String errorMessage, Object identifier,
  100. ErrorLevel errorLevel) {
  101. this(tooltip, ContentMode.HTML, errorMessage, identifier, errorLevel);
  102. }
  103. /**
  104. * Constructs a new tooltip info instance.
  105. *
  106. * @param tooltip
  107. * tooltip title
  108. * @param mode
  109. * content mode
  110. */
  111. public TooltipInfo(String tooltip, ContentMode mode) {
  112. setTitle(tooltip);
  113. setContentMode(mode);
  114. }
  115. /**
  116. * Constructs a new tooltip info instance.
  117. *
  118. * @param tooltip
  119. * tooltip title
  120. * @param mode
  121. * content mode
  122. * @param errorMessage
  123. * error message
  124. */
  125. public TooltipInfo(String tooltip, ContentMode mode, String errorMessage) {
  126. this(tooltip, mode, errorMessage, null);
  127. }
  128. /**
  129. * Constructs a new tooltip info instance.
  130. *
  131. * @param tooltip
  132. * tooltip title
  133. * @param mode
  134. * content mode
  135. * @param errorMessage
  136. * error message
  137. * @param identifier
  138. * the tooltip's identifier
  139. */
  140. public TooltipInfo(String tooltip, ContentMode mode, String errorMessage,
  141. Object identifier) {
  142. this(tooltip, mode, errorMessage, identifier, null);
  143. }
  144. /**
  145. * Constructs a new tooltip info instance.
  146. *
  147. * @param tooltip
  148. * tooltip title
  149. * @param mode
  150. * content mode
  151. * @param errorMessage
  152. * error message
  153. * @param identifier
  154. * the tooltip's identifier
  155. * @param errorLevel
  156. * error level
  157. */
  158. public TooltipInfo(String tooltip, ContentMode mode, String errorMessage,
  159. Object identifier, ErrorLevel errorLevel) {
  160. setIdentifier(identifier);
  161. setTitle(tooltip);
  162. setContentMode(mode);
  163. setErrorMessage(errorMessage);
  164. setErrorLevel(errorLevel);
  165. }
  166. /**
  167. * Sets the tooltip's identifier.
  168. *
  169. * @param identifier
  170. * the identifier to set
  171. */
  172. public void setIdentifier(Object identifier) {
  173. this.identifier = identifier;
  174. }
  175. /**
  176. * Gets the tooltip's identifier.
  177. *
  178. * @return the identifier
  179. */
  180. public Object getIdentifier() {
  181. return identifier;
  182. }
  183. /**
  184. * Gets the tooltip title.
  185. *
  186. * @return the title
  187. */
  188. public String getTitle() {
  189. return title;
  190. }
  191. /**
  192. * Sets the tooltip title.
  193. *
  194. * @param title
  195. * the title to set
  196. */
  197. public void setTitle(String title) {
  198. this.title = title;
  199. }
  200. /**
  201. * Gets the error message.
  202. *
  203. * @return the error message
  204. */
  205. public String getErrorMessage() {
  206. return errorMessageHtml;
  207. }
  208. /**
  209. * Sets the error message.
  210. *
  211. * @param errorMessage
  212. * the error message to set
  213. */
  214. public void setErrorMessage(String errorMessage) {
  215. errorMessageHtml = errorMessage;
  216. }
  217. /**
  218. * Gets the tooltip title's content mode.
  219. *
  220. * @return the content mode
  221. */
  222. public ContentMode getContentMode() {
  223. return contentMode;
  224. }
  225. /**
  226. * Sets the tooltip title's content mode.
  227. *
  228. * @param contentMode
  229. * the content mode to set
  230. */
  231. public void setContentMode(ContentMode contentMode) {
  232. this.contentMode = contentMode;
  233. }
  234. /**
  235. * Gets the error level.
  236. *
  237. * @return the error level
  238. * @since
  239. */
  240. public ErrorLevel getErrorLevel() {
  241. return errorLevel;
  242. }
  243. /**
  244. * Sets the error level.
  245. *
  246. * @param errorLevel
  247. * the error level to set
  248. * @since
  249. */
  250. public void setErrorLevel(ErrorLevel errorLevel) {
  251. this.errorLevel = errorLevel;
  252. }
  253. /**
  254. * Checks is a message has been defined for the tooltip.
  255. *
  256. * @return true if title or error message is present, false if both are
  257. * empty
  258. */
  259. public boolean hasMessage() {
  260. return (title != null && !title.isEmpty())
  261. || (errorMessageHtml != null && !errorMessageHtml.isEmpty());
  262. }
  263. /**
  264. * Indicates whether another tooltip info instance is equal to this one. Two
  265. * instances are equal if their title, error message, error level and
  266. * identifier are equal.
  267. *
  268. * @param other
  269. * the reference tooltip info instance with which to compare
  270. * @return {@code true} if the instances are equal, {@code false} otherwise
  271. */
  272. public boolean equals(TooltipInfo other) {
  273. return (other != null && SharedUtil.equals(other.title, title)
  274. && SharedUtil.equals(other.errorMessageHtml, errorMessageHtml)
  275. && SharedUtil.equals(other.errorLevel, errorLevel)
  276. && other.identifier == identifier);
  277. }
  278. }