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

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