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

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