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.

Component.java 38KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. /*
  2. * Copyright 2011 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.ui;
  17. import java.io.Serializable;
  18. import java.util.EventListener;
  19. import java.util.EventObject;
  20. import java.util.Locale;
  21. import com.vaadin.event.FieldEvents;
  22. import com.vaadin.server.ClientConnector;
  23. import com.vaadin.server.ErrorMessage;
  24. import com.vaadin.server.Resource;
  25. import com.vaadin.server.Sizeable;
  26. import com.vaadin.server.VariableOwner;
  27. /**
  28. * {@code Component} is the top-level interface that is and must be implemented
  29. * by all Vaadin components. {@code Component} is paired with
  30. * {@link AbstractComponent}, which provides a default implementation for all
  31. * the methods defined in this interface.
  32. *
  33. * <p>
  34. * Components are laid out in the user interface hierarchically. The layout is
  35. * managed by layout components, or more generally by components that implement
  36. * the {@link ComponentContainer} interface. Such a container is the
  37. * <i>parent</i> of the contained components.
  38. * </p>
  39. *
  40. * <p>
  41. * The {@link #getParent()} method allows retrieving the parent component of a
  42. * component. While there is a {@link #setParent(Component) setParent()}, you
  43. * rarely need it as you normally add components with the
  44. * {@link ComponentContainer#addComponent(Component) addComponent()} method of
  45. * the layout or other {@code ComponentContainer}, which automatically sets the
  46. * parent.
  47. * </p>
  48. *
  49. * <p>
  50. * A component becomes <i>attached</i> to an application (and the
  51. * {@link #attach()} is called) when it or one of its parents is attached to the
  52. * main window of the application through its containment hierarchy.
  53. * </p>
  54. *
  55. * @author Vaadin Ltd.
  56. * @since 3.0
  57. */
  58. public interface Component extends ClientConnector, Sizeable, Serializable {
  59. /**
  60. * Gets all user-defined CSS style names of a component. If the component
  61. * has multiple style names defined, the return string is a space-separated
  62. * list of style names. Built-in style names defined in Vaadin or GWT are
  63. * not returned.
  64. *
  65. * <p>
  66. * The style names are returned only in the basic form in which they were
  67. * added; each user-defined style name shows as two CSS style class names in
  68. * the rendered HTML: one as it was given and one prefixed with the
  69. * component-specific style name. Only the former is returned.
  70. * </p>
  71. *
  72. * @return the style name or a space-separated list of user-defined style
  73. * names of the component
  74. * @see #setStyleName(String)
  75. * @see #addStyleName(String)
  76. * @see #removeStyleName(String)
  77. */
  78. public String getStyleName();
  79. /**
  80. * Sets one or more user-defined style names of the component, replacing any
  81. * previous user-defined styles. Multiple styles can be specified as a
  82. * space-separated list of style names. The style names must be valid CSS
  83. * class names and should not conflict with any built-in style names in
  84. * Vaadin or GWT.
  85. *
  86. * <pre>
  87. * Label label = new Label(&quot;This text has a lot of style&quot;);
  88. * label.setStyleName(&quot;myonestyle myotherstyle&quot;);
  89. * </pre>
  90. *
  91. * <p>
  92. * Each style name will occur in two versions: one as specified and one that
  93. * is prefixed with the style name of the component. For example, if you
  94. * have a {@code Button} component and give it "{@code mystyle}" style, the
  95. * component will have both "{@code mystyle}" and "{@code v-button-mystyle}"
  96. * styles. You could then style the component either with:
  97. * </p>
  98. *
  99. * <pre>
  100. * .myonestyle {background: blue;}
  101. * </pre>
  102. *
  103. * <p>
  104. * or
  105. * </p>
  106. *
  107. * <pre>
  108. * .v-button-myonestyle {background: blue;}
  109. * </pre>
  110. *
  111. * <p>
  112. * It is normally a good practice to use {@link #addStyleName(String)
  113. * addStyleName()} rather than this setter, as different software
  114. * abstraction layers can then add their own styles without accidentally
  115. * removing those defined in other layers.
  116. * </p>
  117. *
  118. * <p>
  119. * This method will trigger a {@link RepaintRequestEvent}.
  120. * </p>
  121. *
  122. * @param style
  123. * the new style or styles of the component as a space-separated
  124. * list
  125. * @see #getStyleName()
  126. * @see #addStyleName(String)
  127. * @see #removeStyleName(String)
  128. */
  129. public void setStyleName(String style);
  130. /**
  131. * Adds one or more style names to this component. Multiple styles can be
  132. * specified as a space-separated list of style names. The style name will
  133. * be rendered as a HTML class name, which can be used in a CSS definition.
  134. *
  135. * <pre>
  136. * Label label = new Label(&quot;This text has style&quot;);
  137. * label.addStyleName(&quot;mystyle&quot;);
  138. * </pre>
  139. *
  140. * <p>
  141. * Each style name will occur in two versions: one as specified and one that
  142. * is prefixed wil the style name of the component. For example, if you have
  143. * a {@code Button} component and give it "{@code mystyle}" style, the
  144. * component will have both "{@code mystyle}" and "{@code v-button-mystyle}"
  145. * styles. You could then style the component either with:
  146. * </p>
  147. *
  148. * <pre>
  149. * .mystyle {font-style: italic;}
  150. * </pre>
  151. *
  152. * <p>
  153. * or
  154. * </p>
  155. *
  156. * <pre>
  157. * .v-button-mystyle {font-style: italic;}
  158. * </pre>
  159. *
  160. * <p>
  161. * This method will trigger a {@link RepaintRequestEvent}.
  162. * </p>
  163. *
  164. * @param style
  165. * the new style to be added to the component
  166. * @see #getStyleName()
  167. * @see #setStyleName(String)
  168. * @see #removeStyleName(String)
  169. */
  170. public void addStyleName(String style);
  171. /**
  172. * Removes one or more style names from component. Multiple styles can be
  173. * specified as a space-separated list of style names.
  174. *
  175. * <p>
  176. * The parameter must be a valid CSS style name. Only user-defined style
  177. * names added with {@link #addStyleName(String) addStyleName()} or
  178. * {@link #setStyleName(String) setStyleName()} can be removed; built-in
  179. * style names defined in Vaadin or GWT can not be removed.
  180. * </p>
  181. *
  182. * * This method will trigger a {@link RepaintRequestEvent}.
  183. *
  184. * @param style
  185. * the style name or style names to be removed
  186. * @see #getStyleName()
  187. * @see #setStyleName(String)
  188. * @see #addStyleName(String)
  189. */
  190. public void removeStyleName(String style);
  191. /**
  192. * Gets the primary style name of the component. See
  193. * {@link Component#setPrimaryStyleName(String)} for a better description of
  194. * the primary stylename.
  195. */
  196. public String getPrimaryStyleName();
  197. /**
  198. * Changes the primary style name of the component.
  199. *
  200. * <p>
  201. * The primary style name identifies the component when applying the CSS
  202. * theme to the Component. By changing the style name all CSS rules targeted
  203. * for that style name will no longer apply, and might result in the
  204. * component not working as intended.
  205. * </p>
  206. *
  207. * <p>
  208. * To preserve the original style of the component when changing to a new
  209. * primary style you should make your new primary style inherit the old
  210. * primary style using the SASS @include directive. See more in the SASS
  211. * tutorials.
  212. * </p>
  213. *
  214. * @param style
  215. * The new primary style name
  216. */
  217. public void setPrimaryStyleName(String style);
  218. /**
  219. * Tests whether the component is enabled or not. A user can not interact
  220. * with disabled components. Disabled components are rendered in a style
  221. * that indicates the status, usually in gray color. Children of a disabled
  222. * component are also disabled. Components are enabled by default.
  223. *
  224. * <p>
  225. * As a security feature, all updates for disabled components are blocked on
  226. * the server-side.
  227. * </p>
  228. *
  229. * <p>
  230. * Note that this method only returns the status of the component and does
  231. * not take parents into account. Even though this method returns true the
  232. * component can be disabled to the user if a parent is disabled.
  233. * </p>
  234. *
  235. * @return <code>true</code> if the component and its parent are enabled,
  236. * <code>false</code> otherwise.
  237. * @see VariableOwner#isEnabled()
  238. */
  239. public boolean isEnabled();
  240. /**
  241. * Enables or disables the component. The user can not interact disabled
  242. * components, which are shown with a style that indicates the status,
  243. * usually shaded in light gray color. Components are enabled by default.
  244. *
  245. * <pre>
  246. * Button enabled = new Button(&quot;Enabled&quot;);
  247. * enabled.setEnabled(true); // The default
  248. * layout.addComponent(enabled);
  249. *
  250. * Button disabled = new Button(&quot;Disabled&quot;);
  251. * disabled.setEnabled(false);
  252. * layout.addComponent(disabled);
  253. * </pre>
  254. *
  255. * <p>
  256. * This method will trigger a {@link RepaintRequestEvent} for the component
  257. * and, if it is a {@link ComponentContainer}, for all its children
  258. * recursively.
  259. * </p>
  260. *
  261. * @param enabled
  262. * a boolean value specifying if the component should be enabled
  263. * or not
  264. */
  265. public void setEnabled(boolean enabled);
  266. /**
  267. * Tests the <i>visibility</i> property of the component.
  268. *
  269. * <p>
  270. * Visible components are drawn in the user interface, while invisible ones
  271. * are not. The effect is not merely a cosmetic CSS change - no information
  272. * about an invisible component will be sent to the client. The effect is
  273. * thus the same as removing the component from its parent. Making a
  274. * component invisible through this property can alter the positioning of
  275. * other components.
  276. * </p>
  277. *
  278. * <p>
  279. * A component is visible only if all its parents are also visible. This is
  280. * not checked by this method though, so even if this method returns true,
  281. * the component can be hidden from the user because a parent is set to
  282. * invisible.
  283. * </p>
  284. *
  285. * @return <code>true</code> if the component has been set to be visible in
  286. * the user interface, <code>false</code> if not
  287. * @see #setVisible(boolean)
  288. * @see #attach()
  289. */
  290. public boolean isVisible();
  291. /**
  292. * Sets the visibility of the component.
  293. *
  294. * <p>
  295. * Visible components are drawn in the user interface, while invisible ones
  296. * are not. The effect is not merely a cosmetic CSS change - no information
  297. * about an invisible component will be sent to the client. The effect is
  298. * thus the same as removing the component from its parent.
  299. * </p>
  300. *
  301. * <pre>
  302. * TextField readonly = new TextField(&quot;Read-Only&quot;);
  303. * readonly.setValue(&quot;You can't see this!&quot;);
  304. * readonly.setVisible(false);
  305. * layout.addComponent(readonly);
  306. * </pre>
  307. *
  308. * <p>
  309. * A component is visible only if all of its parents are also visible. If a
  310. * component is explicitly set to be invisible, changes in the visibility of
  311. * its parents will not change the visibility of the component.
  312. * </p>
  313. *
  314. * @param visible
  315. * the boolean value specifying if the component should be
  316. * visible after the call or not.
  317. * @see #isVisible()
  318. */
  319. public void setVisible(boolean visible);
  320. /**
  321. * Gets the parent component of the component.
  322. *
  323. * <p>
  324. * Components can be nested but a component can have only one parent. A
  325. * component that contains other components, that is, can be a parent,
  326. * should usually inherit the {@link ComponentContainer} interface.
  327. * </p>
  328. *
  329. * @return the parent component
  330. */
  331. @Override
  332. public HasComponents getParent();
  333. /**
  334. * Tests whether the component is in the read-only mode. The user can not
  335. * change the value of a read-only component. As only {@link Field}
  336. * components normally have a value that can be input or changed by the
  337. * user, this is mostly relevant only to field components, though not
  338. * restricted to them.
  339. *
  340. * <p>
  341. * Notice that the read-only mode only affects whether the user can change
  342. * the <i>value</i> of the component; it is possible to, for example, scroll
  343. * a read-only table.
  344. * </p>
  345. *
  346. * <p>
  347. * The method will return {@code true} if the component or any of its
  348. * parents is in the read-only mode.
  349. * </p>
  350. *
  351. * @return <code>true</code> if the component or any of its parents is in
  352. * read-only mode, <code>false</code> if not.
  353. * @see #setReadOnly(boolean)
  354. */
  355. public boolean isReadOnly();
  356. /**
  357. * Sets the read-only mode of the component to the specified mode. The user
  358. * can not change the value of a read-only component.
  359. *
  360. * <p>
  361. * As only {@link Field} components normally have a value that can be input
  362. * or changed by the user, this is mostly relevant only to field components,
  363. * though not restricted to them.
  364. * </p>
  365. *
  366. * <p>
  367. * Notice that the read-only mode only affects whether the user can change
  368. * the <i>value</i> of the component; it is possible to, for example, scroll
  369. * a read-only table.
  370. * </p>
  371. *
  372. * <p>
  373. * This method will trigger a {@link RepaintRequestEvent}.
  374. * </p>
  375. *
  376. * @param readOnly
  377. * a boolean value specifying whether the component is put
  378. * read-only mode or not
  379. */
  380. public void setReadOnly(boolean readOnly);
  381. /**
  382. * Gets the caption of the component.
  383. *
  384. * <p>
  385. * See {@link #setCaption(String)} for a detailed description of the
  386. * caption.
  387. * </p>
  388. *
  389. * @return the caption of the component or {@code null} if the caption is
  390. * not set.
  391. * @see #setCaption(String)
  392. */
  393. public String getCaption();
  394. /**
  395. * Sets the caption of the component.
  396. *
  397. * <p>
  398. * A <i>caption</i> is an explanatory textual label accompanying a user
  399. * interface component, usually shown above, left of, or inside the
  400. * component. <i>Icon</i> (see {@link #setIcon(Resource) setIcon()} is
  401. * closely related to caption and is usually displayed horizontally before
  402. * or after it, depending on the component and the containing layout.
  403. * </p>
  404. *
  405. * <p>
  406. * The caption can usually also be given as the first parameter to a
  407. * constructor, though some components do not support it.
  408. * </p>
  409. *
  410. * <pre>
  411. * RichTextArea area = new RichTextArea();
  412. * area.setCaption(&quot;You can edit stuff here&quot;);
  413. * area.setValue(&quot;&lt;h1&gt;Helpful Heading&lt;/h1&gt;&quot;
  414. * + &quot;&lt;p&gt;All this is for you to edit.&lt;/p&gt;&quot;);
  415. * </pre>
  416. *
  417. * <p>
  418. * The contents of a caption are automatically quoted, so no raw HTML can be
  419. * rendered in a caption. The validity of the used character encoding,
  420. * usually UTF-8, is not checked.
  421. * </p>
  422. *
  423. * <p>
  424. * The caption of a component is, by default, managed and displayed by the
  425. * layout component or component container in which the component is placed.
  426. * For example, the {@link VerticalLayout} component shows the captions
  427. * left-aligned above the contained components, while the {@link FormLayout}
  428. * component shows the captions on the left side of the vertically laid
  429. * components, with the captions and their associated components
  430. * left-aligned in their own columns. The {@link CustomComponent} does not
  431. * manage the caption of its composition root, so if the root component has
  432. * a caption, it will not be rendered. Some components, such as
  433. * {@link Button} and {@link Panel}, manage the caption themselves and
  434. * display it inside the component.
  435. * </p>
  436. *
  437. * <p>
  438. * This method will trigger a {@link RepaintRequestEvent}. A
  439. * reimplementation should call the superclass implementation.
  440. * </p>
  441. *
  442. * @param caption
  443. * the new caption for the component. If the caption is
  444. * {@code null}, no caption is shown and it does not normally
  445. * take any space
  446. */
  447. public void setCaption(String caption);
  448. /**
  449. * Gets the icon resource of the component.
  450. *
  451. * <p>
  452. * See {@link #setIcon(Resource)} for a detailed description of the icon.
  453. * </p>
  454. *
  455. * @return the icon resource of the component or {@code null} if the
  456. * component has no icon
  457. * @see #setIcon(Resource)
  458. */
  459. public Resource getIcon();
  460. /**
  461. * Sets the icon of the component.
  462. *
  463. * <p>
  464. * An icon is an explanatory graphical label accompanying a user interface
  465. * component, usually shown above, left of, or inside the component. Icon is
  466. * closely related to caption (see {@link #setCaption(String) setCaption()})
  467. * and is usually displayed horizontally before or after it, depending on
  468. * the component and the containing layout.
  469. * </p>
  470. *
  471. * <p>
  472. * The image is loaded by the browser from a resource, typically a
  473. * {@link com.vaadin.server.ThemeResource}.
  474. * </p>
  475. *
  476. * <pre>
  477. * // Component with an icon from a custom theme
  478. * TextField name = new TextField(&quot;Name&quot;);
  479. * name.setIcon(new ThemeResource(&quot;icons/user.png&quot;));
  480. * layout.addComponent(name);
  481. *
  482. * // Component with an icon from another theme ('runo')
  483. * Button ok = new Button(&quot;OK&quot;);
  484. * ok.setIcon(new ThemeResource(&quot;../runo/icons/16/ok.png&quot;));
  485. * layout.addComponent(ok);
  486. * </pre>
  487. *
  488. * <p>
  489. * The icon of a component is, by default, managed and displayed by the
  490. * layout component or component container in which the component is placed.
  491. * For example, the {@link VerticalLayout} component shows the icons
  492. * left-aligned above the contained components, while the {@link FormLayout}
  493. * component shows the icons on the left side of the vertically laid
  494. * components, with the icons and their associated components left-aligned
  495. * in their own columns. The {@link CustomComponent} does not manage the
  496. * icon of its composition root, so if the root component has an icon, it
  497. * will not be rendered.
  498. * </p>
  499. *
  500. * <p>
  501. * An icon will be rendered inside an HTML element that has the
  502. * {@code v-icon} CSS style class. The containing layout may enclose an icon
  503. * and a caption inside elements related to the caption, such as
  504. * {@code v-caption} .
  505. * </p>
  506. *
  507. * This method will trigger a {@link RepaintRequestEvent}.
  508. *
  509. * @param icon
  510. * the icon of the component. If null, no icon is shown and it
  511. * does not normally take any space.
  512. * @see #getIcon()
  513. * @see #setCaption(String)
  514. */
  515. public void setIcon(Resource icon);
  516. /**
  517. * Gets the UI the component is attached to.
  518. *
  519. * <p>
  520. * If the component is not attached to a UI through a component containment
  521. * hierarchy, <code>null</code> is returned.
  522. * </p>
  523. *
  524. * @return the UI of the component or <code>null</code> if it is not
  525. * attached to a UI
  526. */
  527. @Override
  528. public UI getUI();
  529. /**
  530. * {@inheritDoc}
  531. *
  532. * <p>
  533. * Reimplementing the {@code attach()} method is useful for tasks that need
  534. * to get a reference to the parent, window, or application object with the
  535. * {@link #getParent()}, {@link #getUI()}, and {@link #getSession()}
  536. * methods. A component does not yet know these objects in the constructor,
  537. * so in such case, the methods will return {@code null}. For example, the
  538. * following is invalid:
  539. * </p>
  540. *
  541. * <pre>
  542. * public class AttachExample extends CustomComponent {
  543. * public AttachExample() {
  544. * // ERROR: We can't access the application object yet.
  545. * ClassResource r = new ClassResource(&quot;smiley.jpg&quot;, getApplication());
  546. * Embedded image = new Embedded(&quot;Image:&quot;, r);
  547. * setCompositionRoot(image);
  548. * }
  549. * }
  550. * </pre>
  551. *
  552. * <p>
  553. * Adding a component to an application triggers calling the
  554. * {@link #attach()} method for the component. Correspondingly, removing a
  555. * component from a container triggers calling the {@link #detach()} method.
  556. * If the parent of an added component is already connected to the
  557. * application, the {@code attach()} is called immediately from
  558. * {@link #setParent(Component)}.
  559. * </p>
  560. * <p>
  561. * This method must call {@link UI#componentAttached(Component)} to let the
  562. * UI know that a new Component has been attached.
  563. * </p>
  564. *
  565. *
  566. * <pre>
  567. * public class AttachExample extends CustomComponent {
  568. * public AttachExample() {
  569. * }
  570. *
  571. * &#064;Override
  572. * public void attach() {
  573. * super.attach(); // Must call.
  574. *
  575. * // Now we know who ultimately owns us.
  576. * ClassResource r = new ClassResource(&quot;smiley.jpg&quot;, getApplication());
  577. * Embedded image = new Embedded(&quot;Image:&quot;, r);
  578. * setCompositionRoot(image);
  579. * }
  580. * }
  581. * </pre>
  582. */
  583. @Override
  584. public void attach();
  585. /**
  586. * Gets the locale of the component.
  587. *
  588. * <p>
  589. * If a component does not have a locale set, the locale of its parent is
  590. * returned, and so on. Eventually, if no parent has locale set, the locale
  591. * of the application is returned. If the application does not have a locale
  592. * set, it is determined by <code>Locale.getDefault()</code>.
  593. * </p>
  594. *
  595. * <p>
  596. * As the component must be attached before its locale can be acquired,
  597. * using this method in the internationalization of component captions, etc.
  598. * is generally not feasible. For such use case, we recommend using an
  599. * otherwise acquired reference to the application locale.
  600. * </p>
  601. *
  602. * @return Locale of this component or {@code null} if the component and
  603. * none of its parents has a locale set and the component is not yet
  604. * attached to an application.
  605. */
  606. public Locale getLocale();
  607. /**
  608. * Adds an unique id for component that get's transferred to terminal for
  609. * testing purposes. Keeping identifiers unique is the responsibility of the
  610. * programmer.
  611. *
  612. * @param id
  613. * An alphanumeric id
  614. */
  615. public void setId(String id);
  616. /**
  617. * Get's currently set debug identifier
  618. *
  619. * @return current id, null if not set
  620. */
  621. public String getId();
  622. /**
  623. * <p>
  624. * Gets the component's description, used in tooltips and can be displayed
  625. * directly in certain other components such as forms. The description can
  626. * be used to briefly describe the state of the component to the user. The
  627. * description string may contain certain XML tags:
  628. * </p>
  629. *
  630. * <p>
  631. * <table border=1>
  632. * <tr>
  633. * <td width=120><b>Tag</b></td>
  634. * <td width=120><b>Description</b></td>
  635. * <td width=120><b>Example</b></td>
  636. * </tr>
  637. * <tr>
  638. * <td>&lt;b></td>
  639. * <td>bold</td>
  640. * <td><b>bold text</b></td>
  641. * </tr>
  642. * <tr>
  643. * <td>&lt;i></td>
  644. * <td>italic</td>
  645. * <td><i>italic text</i></td>
  646. * </tr>
  647. * <tr>
  648. * <td>&lt;u></td>
  649. * <td>underlined</td>
  650. * <td><u>underlined text</u></td>
  651. * </tr>
  652. * <tr>
  653. * <td>&lt;br></td>
  654. * <td>linebreak</td>
  655. * <td>N/A</td>
  656. * </tr>
  657. * <tr>
  658. * <td>&lt;ul><br>
  659. * &lt;li>item1<br>
  660. * &lt;li>item1<br>
  661. * &lt;/ul></td>
  662. * <td>item list</td>
  663. * <td>
  664. * <ul>
  665. * <li>item1
  666. * <li>item2
  667. * </ul>
  668. * </td>
  669. * </tr>
  670. * </table>
  671. * </p>
  672. *
  673. * <p>
  674. * These tags may be nested.
  675. * </p>
  676. *
  677. * @return component's description <code>String</code>
  678. */
  679. public String getDescription();
  680. /* Component event framework */
  681. /**
  682. * Superclass of all component originated events.
  683. *
  684. * <p>
  685. * Events are the basis of all user interaction handling in Vaadin. To
  686. * handle events, you provide a listener object that receives the events of
  687. * the particular event type.
  688. * </p>
  689. *
  690. * <pre>
  691. * Button button = new Button(&quot;Click Me!&quot;);
  692. * button.addListener(new Button.ClickListener() {
  693. * public void buttonClick(ClickEvent event) {
  694. * getWindow().showNotification(&quot;Thank You!&quot;);
  695. * }
  696. * });
  697. * layout.addComponent(button);
  698. * </pre>
  699. *
  700. * <p>
  701. * Notice that while each of the event types have their corresponding
  702. * listener types; the listener interfaces are not required to inherit the
  703. * {@code Component.Listener} interface.
  704. * </p>
  705. *
  706. * @see Component.Listener
  707. */
  708. @SuppressWarnings("serial")
  709. public static class Event extends EventObject {
  710. /**
  711. * Constructs a new event with the specified source component.
  712. *
  713. * @param source
  714. * the source component of the event
  715. */
  716. public Event(Component source) {
  717. super(source);
  718. }
  719. /**
  720. * Gets the component where the event occurred.
  721. *
  722. * @return the source component of the event
  723. */
  724. public Component getComponent() {
  725. return (Component) getSource();
  726. }
  727. }
  728. /**
  729. * Listener interface for receiving <code>Component.Event</code>s.
  730. *
  731. * <p>
  732. * Listener interfaces are the basis of all user interaction handling in
  733. * Vaadin. You have or create a listener object that receives the events.
  734. * All event types have their corresponding listener types; they are not,
  735. * however, required to inherit the {@code Component.Listener} interface,
  736. * and they rarely do so.
  737. * </p>
  738. *
  739. * <p>
  740. * This generic listener interface is useful typically when you wish to
  741. * handle events from different component types in a single listener method
  742. * ({@code componentEvent()}. If you handle component events in an anonymous
  743. * listener class, you normally use the component specific listener class,
  744. * such as {@link com.vaadin.ui.Button.ClickEvent}.
  745. * </p>
  746. *
  747. * <pre>
  748. * class Listening extends CustomComponent implements Listener {
  749. * Button ok; // Stored for determining the source of an event
  750. *
  751. * Label status; // For displaying info about the event
  752. *
  753. * public Listening() {
  754. * VerticalLayout layout = new VerticalLayout();
  755. *
  756. * // Some miscellaneous component
  757. * TextField name = new TextField(&quot;Say it all here&quot;);
  758. * name.addListener(this);
  759. * name.setImmediate(true);
  760. * layout.addComponent(name);
  761. *
  762. * // Handle button clicks as generic events instead
  763. * // of Button.ClickEvent events
  764. * ok = new Button(&quot;OK&quot;);
  765. * ok.addListener(this);
  766. * layout.addComponent(ok);
  767. *
  768. * // For displaying information about an event
  769. * status = new Label(&quot;&quot;);
  770. * layout.addComponent(status);
  771. *
  772. * setCompositionRoot(layout);
  773. * }
  774. *
  775. * public void componentEvent(Event event) {
  776. * // Act according to the source of the event
  777. * if (event.getSource() == ok
  778. * &amp;&amp; event.getClass() == Button.ClickEvent.class)
  779. * getWindow().showNotification(&quot;Click!&quot;);
  780. *
  781. * // Display source component and event class names
  782. * status.setValue(&quot;Event from &quot; + event.getSource().getClass().getName()
  783. * + &quot;: &quot; + event.getClass().getName());
  784. * }
  785. * }
  786. *
  787. * Listening listening = new Listening();
  788. * layout.addComponent(listening);
  789. * </pre>
  790. *
  791. * @see Component#addListener(Listener)
  792. */
  793. public interface Listener extends EventListener, Serializable {
  794. /**
  795. * Notifies the listener of a component event.
  796. *
  797. * <p>
  798. * As the event can typically come from one of many source components,
  799. * you may need to differentiate between the event source by component
  800. * reference, class, etc.
  801. * </p>
  802. *
  803. * <pre>
  804. * public void componentEvent(Event event) {
  805. * // Act according to the source of the event
  806. * if (event.getSource() == ok &amp;&amp; event.getClass() == Button.ClickEvent.class)
  807. * getWindow().showNotification(&quot;Click!&quot;);
  808. *
  809. * // Display source component and event class names
  810. * status.setValue(&quot;Event from &quot; + event.getSource().getClass().getName()
  811. * + &quot;: &quot; + event.getClass().getName());
  812. * }
  813. * </pre>
  814. *
  815. * @param event
  816. * the event that has occured.
  817. */
  818. public void componentEvent(Component.Event event);
  819. }
  820. /**
  821. * Registers a new (generic) component event listener for the component.
  822. *
  823. * <pre>
  824. * class Listening extends CustomComponent implements Listener {
  825. * // Stored for determining the source of an event
  826. * Button ok;
  827. *
  828. * Label status; // For displaying info about the event
  829. *
  830. * public Listening() {
  831. * VerticalLayout layout = new VerticalLayout();
  832. *
  833. * // Some miscellaneous component
  834. * TextField name = new TextField(&quot;Say it all here&quot;);
  835. * name.addListener(this);
  836. * name.setImmediate(true);
  837. * layout.addComponent(name);
  838. *
  839. * // Handle button clicks as generic events instead
  840. * // of Button.ClickEvent events
  841. * ok = new Button(&quot;OK&quot;);
  842. * ok.addListener(this);
  843. * layout.addComponent(ok);
  844. *
  845. * // For displaying information about an event
  846. * status = new Label(&quot;&quot;);
  847. * layout.addComponent(status);
  848. *
  849. * setCompositionRoot(layout);
  850. * }
  851. *
  852. * public void componentEvent(Event event) {
  853. * // Act according to the source of the event
  854. * if (event.getSource() == ok)
  855. * getWindow().showNotification(&quot;Click!&quot;);
  856. *
  857. * status.setValue(&quot;Event from &quot; + event.getSource().getClass().getName()
  858. * + &quot;: &quot; + event.getClass().getName());
  859. * }
  860. * }
  861. *
  862. * Listening listening = new Listening();
  863. * layout.addComponent(listening);
  864. * </pre>
  865. *
  866. * @param listener
  867. * the new Listener to be registered.
  868. * @see Component.Event
  869. * @see #removeListener(Listener)
  870. */
  871. public void addListener(Component.Listener listener);
  872. /**
  873. * Removes a previously registered component event listener from this
  874. * component.
  875. *
  876. * @param listener
  877. * the listener to be removed.
  878. * @see #addListener(Listener)
  879. */
  880. public void removeListener(Component.Listener listener);
  881. /**
  882. * Class of all component originated error events.
  883. *
  884. * <p>
  885. * The component error event is normally fired by
  886. * {@link AbstractComponent#setComponentError(ErrorMessage)}. The component
  887. * errors are set by the framework in some situations and can be set by user
  888. * code. They are indicated in a component with an error indicator.
  889. * </p>
  890. */
  891. @SuppressWarnings("serial")
  892. public static class ErrorEvent extends Event {
  893. private final ErrorMessage message;
  894. /**
  895. * Constructs a new event with a specified source component.
  896. *
  897. * @param message
  898. * the error message.
  899. * @param component
  900. * the source component.
  901. */
  902. public ErrorEvent(ErrorMessage message, Component component) {
  903. super(component);
  904. this.message = message;
  905. }
  906. /**
  907. * Gets the error message.
  908. *
  909. * @return the error message.
  910. */
  911. public ErrorMessage getErrorMessage() {
  912. return message;
  913. }
  914. }
  915. /**
  916. * Listener interface for receiving <code>Component.Errors</code>s.
  917. */
  918. public interface ErrorListener extends EventListener, Serializable {
  919. /**
  920. * Notifies the listener of a component error.
  921. *
  922. * @param event
  923. * the event that has occured.
  924. */
  925. public void componentError(Component.ErrorEvent event);
  926. }
  927. /**
  928. * A sub-interface implemented by components that can obtain input focus.
  929. * This includes all {@link Field} components as well as some other
  930. * components, such as {@link Upload}.
  931. *
  932. * <p>
  933. * Focus can be set with {@link #focus()}. This interface does not provide
  934. * an accessor that would allow finding out the currently focused component;
  935. * focus information can be acquired for some (but not all) {@link Field}
  936. * components through the {@link com.vaadin.event.FieldEvents.FocusListener}
  937. * and {@link com.vaadin.event.FieldEvents.BlurListener} interfaces.
  938. * </p>
  939. *
  940. * @see FieldEvents
  941. */
  942. public interface Focusable extends Component {
  943. /**
  944. * Sets the focus to this component.
  945. *
  946. * <pre>
  947. * Form loginBox = new Form();
  948. * loginBox.setCaption(&quot;Login&quot;);
  949. * layout.addComponent(loginBox);
  950. *
  951. * // Create the first field which will be focused
  952. * TextField username = new TextField(&quot;User name&quot;);
  953. * loginBox.addField(&quot;username&quot;, username);
  954. *
  955. * // Set focus to the user name
  956. * username.focus();
  957. *
  958. * TextField password = new TextField(&quot;Password&quot;);
  959. * loginBox.addField(&quot;password&quot;, password);
  960. *
  961. * Button login = new Button(&quot;Login&quot;);
  962. * loginBox.getFooter().addComponent(login);
  963. * </pre>
  964. *
  965. * <p>
  966. * Notice that this interface does not provide an accessor that would
  967. * allow finding out the currently focused component. Focus information
  968. * can be acquired for some (but not all) {@link Field} components
  969. * through the {@link com.vaadin.event.FieldEvents.FocusListener} and
  970. * {@link com.vaadin.event.FieldEvents.BlurListener} interfaces.
  971. * </p>
  972. *
  973. * @see com.vaadin.event.FieldEvents
  974. * @see com.vaadin.event.FieldEvents.FocusEvent
  975. * @see com.vaadin.event.FieldEvents.FocusListener
  976. * @see com.vaadin.event.FieldEvents.BlurEvent
  977. * @see com.vaadin.event.FieldEvents.BlurListener
  978. */
  979. public void focus();
  980. /**
  981. * Gets the <i>tabulator index</i> of the {@code Focusable} component.
  982. *
  983. * @return tab index set for the {@code Focusable} component
  984. * @see #setTabIndex(int)
  985. */
  986. public int getTabIndex();
  987. /**
  988. * Sets the <i>tabulator index</i> of the {@code Focusable} component.
  989. * The tab index property is used to specify the order in which the
  990. * fields are focused when the user presses the Tab key. Components with
  991. * a defined tab index are focused sequentially first, and then the
  992. * components with no tab index.
  993. *
  994. * <pre>
  995. * Form loginBox = new Form();
  996. * loginBox.setCaption(&quot;Login&quot;);
  997. * layout.addComponent(loginBox);
  998. *
  999. * // Create the first field which will be focused
  1000. * TextField username = new TextField(&quot;User name&quot;);
  1001. * loginBox.addField(&quot;username&quot;, username);
  1002. *
  1003. * // Set focus to the user name
  1004. * username.focus();
  1005. *
  1006. * TextField password = new TextField(&quot;Password&quot;);
  1007. * loginBox.addField(&quot;password&quot;, password);
  1008. *
  1009. * Button login = new Button(&quot;Login&quot;);
  1010. * loginBox.getFooter().addComponent(login);
  1011. *
  1012. * // An additional component which natural focus order would
  1013. * // be after the button.
  1014. * CheckBox remember = new CheckBox(&quot;Remember me&quot;);
  1015. * loginBox.getFooter().addComponent(remember);
  1016. *
  1017. * username.setTabIndex(1);
  1018. * password.setTabIndex(2);
  1019. * remember.setTabIndex(3); // Different than natural place
  1020. * login.setTabIndex(4);
  1021. * </pre>
  1022. *
  1023. * <p>
  1024. * After all focusable user interface components are done, the browser
  1025. * can begin again from the component with the smallest tab index, or it
  1026. * can take the focus out of the page, for example, to the location bar.
  1027. * </p>
  1028. *
  1029. * <p>
  1030. * If the tab index is not set (is set to zero), the default tab order
  1031. * is used. The order is somewhat browser-dependent, but generally
  1032. * follows the HTML structure of the page.
  1033. * </p>
  1034. *
  1035. * <p>
  1036. * A negative value means that the component is completely removed from
  1037. * the tabulation order and can not be reached by pressing the Tab key
  1038. * at all.
  1039. * </p>
  1040. *
  1041. * @param tabIndex
  1042. * the tab order of this component. Indexes usually start
  1043. * from 1. Zero means that default tab order should be used.
  1044. * A negative value means that the field should not be
  1045. * included in the tabbing sequence.
  1046. * @see #getTabIndex()
  1047. */
  1048. public void setTabIndex(int tabIndex);
  1049. }
  1050. }