Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Component.java 38KB

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