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.

ComponentState.java 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client;
  5. import com.vaadin.terminal.gwt.client.communication.SharedState;
  6. /**
  7. * Default shared state implementation for UI components.
  8. *
  9. * State classes of concrete components should extend this class.
  10. *
  11. * @since 7.0
  12. */
  13. public class ComponentState extends SharedState {
  14. private String height = "";
  15. private String width = "";
  16. private boolean readOnly = false;
  17. private boolean immediate = false;
  18. private String style = "";
  19. private boolean disabled = false;
  20. private String description = "";
  21. // Note: for the caption, there is a difference between null and an empty
  22. // string!
  23. private String caption = null;
  24. /**
  25. * Returns the component height as set by the server.
  26. *
  27. * Can be relative (containing the percent sign) or absolute, or empty
  28. * string for undefined height.
  29. *
  30. * @return component height as defined by the server, not null
  31. */
  32. public String getHeight() {
  33. if (height == null) {
  34. return "";
  35. }
  36. return height;
  37. }
  38. /**
  39. * Sets the height of the component in the server format.
  40. *
  41. * Can be relative (containing the percent sign) or absolute, or null or
  42. * empty string for undefined height.
  43. *
  44. * @param height
  45. * component height
  46. */
  47. public void setHeight(String height) {
  48. this.height = height;
  49. }
  50. /**
  51. * Returns true if the component height is undefined, false if defined
  52. * (absolute or relative).
  53. *
  54. * @return true if component height is undefined
  55. */
  56. public boolean isUndefinedHeight() {
  57. return "".equals(getHeight());
  58. }
  59. /**
  60. * Returns the component width as set by the server.
  61. *
  62. * Can be relative (containing the percent sign) or absolute, or empty
  63. * string for undefined height.
  64. *
  65. * @return component width as defined by the server, not null
  66. */
  67. public String getWidth() {
  68. if (width == null) {
  69. return "";
  70. }
  71. return width;
  72. }
  73. /**
  74. * Sets the width of the component in the server format.
  75. *
  76. * Can be relative (containing the percent sign) or absolute, or null or
  77. * empty string for undefined width.
  78. *
  79. * @param width
  80. * component width
  81. */
  82. public void setWidth(String width) {
  83. this.width = width;
  84. }
  85. /**
  86. * Returns true if the component width is undefined, false if defined
  87. * (absolute or relative).
  88. *
  89. * @return true if component width is undefined
  90. */
  91. public boolean isUndefinedWidth() {
  92. return "".equals(getWidth());
  93. }
  94. /**
  95. * Returns true if the component is in read-only mode.
  96. *
  97. * @see com.vaadin.ui.Component#isReadOnly()
  98. *
  99. * @return true if the component is in read-only mode
  100. */
  101. public boolean isReadOnly() {
  102. return readOnly;
  103. }
  104. /**
  105. * Sets or resets the read-only mode for a component.
  106. *
  107. * @see com.vaadin.ui.Component#setReadOnly()
  108. *
  109. * @param readOnly
  110. * new mode for the component
  111. */
  112. public void setReadOnly(boolean readOnly) {
  113. this.readOnly = readOnly;
  114. }
  115. /**
  116. * Returns true if the component is in immediate mode.
  117. *
  118. * @see com.vaadin.terminal.VariableOwner#isImmediate()
  119. *
  120. * @return true if the component is in immediate mode
  121. */
  122. public boolean isImmediate() {
  123. return immediate;
  124. }
  125. /**
  126. * Sets or resets the immediate mode for a component.
  127. *
  128. * @see com.vaadin.terminal.VariableOwner#setImmediate()
  129. *
  130. * @param immediate
  131. * new mode for the component
  132. */
  133. public void setImmediate(boolean immediate) {
  134. this.immediate = immediate;
  135. }
  136. /**
  137. * Returns the component styles as set by the server, as a space separated
  138. * string.
  139. *
  140. * @return component styles as defined by the server, not null
  141. */
  142. public String getStyle() {
  143. if (style == null) {
  144. return "";
  145. }
  146. return style;
  147. }
  148. /**
  149. * Sets the component styles as a space separated string.
  150. *
  151. * @param style
  152. * component styles as a space separated string, not null
  153. */
  154. public void setStyle(String style) {
  155. this.style = style;
  156. }
  157. /**
  158. * Returns true if the component has user-defined styles.
  159. *
  160. * @return true if the component has user-defined styles
  161. */
  162. public boolean hasStyles() {
  163. return !"".equals(getStyle());
  164. }
  165. /**
  166. * Returns true if the component is disabled.
  167. *
  168. * @see com.vaadin.ui.Component#isEnabled()
  169. *
  170. * @return true if the component is disabled
  171. */
  172. public boolean isDisabled() {
  173. return disabled;
  174. }
  175. /**
  176. * Disables or enables the component.
  177. *
  178. * @see com.vaadin.ui.Component#setEnabled(boolean)
  179. *
  180. * @param disabled
  181. * new mode for the component
  182. */
  183. public void setDisabled(boolean disabled) {
  184. this.disabled = disabled;
  185. }
  186. /**
  187. * Gets the description of the component (typically shown as tooltip).
  188. *
  189. * @see com.vaadin.ui.AbstractComponent#getDescription()
  190. *
  191. * @return component description (not null, can be empty string)
  192. */
  193. public String getDescription() {
  194. if (description == null) {
  195. return "";
  196. }
  197. return description;
  198. }
  199. /**
  200. * Sets the description of the component (typically shown as tooltip).
  201. *
  202. * @see com.vaadin.ui.AbstractComponent#setDescription(String)
  203. *
  204. * @param description
  205. * new component description (can be null)
  206. */
  207. public void setDescription(String description) {
  208. this.description = description;
  209. }
  210. /**
  211. * Returns true if the component has a description.
  212. *
  213. * @return true if the component has a description
  214. */
  215. public boolean hasDescription() {
  216. return !"".equals(getDescription());
  217. }
  218. /**
  219. * Gets the caption of the component (typically shown by the containing
  220. * layout).
  221. *
  222. * @see com.vaadin.ui.Component#getCaption()
  223. *
  224. * @return component caption - can be null (no caption) or empty string
  225. * (reserve space for an empty caption)
  226. */
  227. public String getCaption() {
  228. return caption;
  229. }
  230. /**
  231. * Sets the caption of the component (typically shown by the containing
  232. * layout).
  233. *
  234. * @see com.vaadin.ui.Component#setCaption(String)
  235. *
  236. * @param caption
  237. * new component caption - can be null (no caption) or empty
  238. * string (reserve space for an empty caption)
  239. */
  240. public void setCaption(String caption) {
  241. this.caption = caption;
  242. }
  243. }