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

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