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

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