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.2KB

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