選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TooltipInfo.java 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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
  95. * {@link #TooltipInfo(String, ContentMode, String, Object, ErrorLevel)}
  96. * instead
  97. * @since 8.2
  98. */
  99. @Deprecated
  100. public TooltipInfo(String tooltip, String errorMessage, Object identifier,
  101. ErrorLevel errorLevel) {
  102. this(tooltip, ContentMode.HTML, errorMessage, identifier, errorLevel);
  103. }
  104. /**
  105. * Constructs a new tooltip info instance.
  106. *
  107. * @param tooltip
  108. * tooltip title
  109. * @param mode
  110. * content mode
  111. */
  112. public TooltipInfo(String tooltip, ContentMode mode) {
  113. setTitle(tooltip);
  114. setContentMode(mode);
  115. }
  116. /**
  117. * Constructs a new tooltip info instance.
  118. *
  119. * @param tooltip
  120. * tooltip title
  121. * @param mode
  122. * content mode
  123. * @param errorMessage
  124. * error message
  125. */
  126. public TooltipInfo(String tooltip, ContentMode mode, String errorMessage) {
  127. this(tooltip, mode, errorMessage, null);
  128. }
  129. /**
  130. * Constructs a new tooltip info instance.
  131. *
  132. * @param tooltip
  133. * tooltip title
  134. * @param mode
  135. * content mode
  136. * @param errorMessage
  137. * error message
  138. * @param identifier
  139. * the tooltip's identifier
  140. */
  141. public TooltipInfo(String tooltip, ContentMode mode, String errorMessage,
  142. Object identifier) {
  143. this(tooltip, mode, errorMessage, identifier, null);
  144. }
  145. /**
  146. * Constructs a new tooltip info instance.
  147. *
  148. * @param tooltip
  149. * tooltip title
  150. * @param mode
  151. * content mode
  152. * @param errorMessage
  153. * error message
  154. * @param identifier
  155. * the tooltip's identifier
  156. * @param errorLevel
  157. * error level
  158. * @since 8.2
  159. */
  160. public TooltipInfo(String tooltip, ContentMode mode, String errorMessage,
  161. Object identifier, ErrorLevel errorLevel) {
  162. setIdentifier(identifier);
  163. setTitle(tooltip);
  164. setContentMode(mode);
  165. setErrorMessage(errorMessage);
  166. setErrorLevel(errorLevel);
  167. }
  168. /**
  169. * Sets the tooltip's identifier.
  170. *
  171. * @param identifier
  172. * the identifier to set
  173. */
  174. public void setIdentifier(Object identifier) {
  175. this.identifier = identifier;
  176. }
  177. /**
  178. * Gets the tooltip's identifier.
  179. *
  180. * @return the identifier
  181. */
  182. public Object getIdentifier() {
  183. return identifier;
  184. }
  185. /**
  186. * Gets the tooltip title.
  187. *
  188. * @return the title
  189. */
  190. public String getTitle() {
  191. return title;
  192. }
  193. /**
  194. * Sets the tooltip title.
  195. *
  196. * @param title
  197. * the title to set
  198. */
  199. public void setTitle(String title) {
  200. this.title = title;
  201. }
  202. /**
  203. * Gets the error message.
  204. *
  205. * @return the error message
  206. */
  207. public String getErrorMessage() {
  208. return errorMessageHtml;
  209. }
  210. /**
  211. * Sets the error message.
  212. *
  213. * @param errorMessage
  214. * the error message to set
  215. */
  216. public void setErrorMessage(String errorMessage) {
  217. errorMessageHtml = errorMessage;
  218. }
  219. /**
  220. * Gets the tooltip title's content mode.
  221. *
  222. * @return the content mode
  223. */
  224. public ContentMode getContentMode() {
  225. return contentMode;
  226. }
  227. /**
  228. * Sets the tooltip title's content mode.
  229. *
  230. * @param contentMode
  231. * the content mode to set
  232. */
  233. public void setContentMode(ContentMode contentMode) {
  234. this.contentMode = contentMode;
  235. }
  236. /**
  237. * Gets the error level.
  238. *
  239. * @return the error level
  240. * @since 8.2
  241. */
  242. public ErrorLevel getErrorLevel() {
  243. return errorLevel;
  244. }
  245. /**
  246. * Sets the error level.
  247. *
  248. * @param errorLevel
  249. * the error level to set
  250. * @since 8.2
  251. */
  252. public void setErrorLevel(ErrorLevel errorLevel) {
  253. this.errorLevel = errorLevel;
  254. }
  255. /**
  256. * Checks is a message has been defined for the tooltip.
  257. *
  258. * @return true if title or error message is present, false if both are
  259. * empty
  260. */
  261. public boolean hasMessage() {
  262. return (title != null && !title.isEmpty())
  263. || (errorMessageHtml != null && !errorMessageHtml.isEmpty());
  264. }
  265. /**
  266. * Indicates whether another tooltip info instance is equal to this one. Two
  267. * instances are equal if their title, error message, error level and
  268. * identifier are equal.
  269. *
  270. * @param other
  271. * the reference tooltip info instance with which to compare
  272. * @return {@code true} if the instances are equal, {@code false} otherwise
  273. */
  274. public boolean equals(TooltipInfo other) {
  275. return (other != null && SharedUtil.equals(other.title, title)
  276. && SharedUtil.equals(other.errorMessageHtml, errorMessageHtml)
  277. && SharedUtil.equals(other.errorLevel, errorLevel)
  278. && other.identifier == identifier);
  279. }
  280. }