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.

AbstractComponent.java 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  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.lang.reflect.Method;
  18. import java.util.ArrayList;
  19. import java.util.Arrays;
  20. import java.util.Collection;
  21. import java.util.HashSet;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import java.util.Locale;
  25. import java.util.Map;
  26. import java.util.Map.Entry;
  27. import java.util.Objects;
  28. import java.util.Set;
  29. import java.util.StringTokenizer;
  30. import org.jsoup.nodes.Attribute;
  31. import org.jsoup.nodes.Attributes;
  32. import org.jsoup.nodes.Element;
  33. import com.vaadin.data.HasValue;
  34. import com.vaadin.event.ActionManager;
  35. import com.vaadin.event.ConnectorActionManager;
  36. import com.vaadin.event.ContextClickEvent;
  37. import com.vaadin.event.ContextClickEvent.ContextClickListener;
  38. import com.vaadin.event.ContextClickEvent.ContextClickNotifier;
  39. import com.vaadin.event.ShortcutListener;
  40. import com.vaadin.server.AbstractClientConnector;
  41. import com.vaadin.server.ClientConnector;
  42. import com.vaadin.server.ComponentSizeValidator;
  43. import com.vaadin.server.ErrorMessage;
  44. import com.vaadin.server.Extension;
  45. import com.vaadin.server.Resource;
  46. import com.vaadin.server.Responsive;
  47. import com.vaadin.server.SizeWithUnit;
  48. import com.vaadin.server.Sizeable;
  49. import com.vaadin.server.UserError;
  50. import com.vaadin.server.VaadinSession;
  51. import com.vaadin.shared.AbstractComponentState;
  52. import com.vaadin.shared.AbstractFieldState;
  53. import com.vaadin.shared.ComponentConstants;
  54. import com.vaadin.shared.ContextClickRpc;
  55. import com.vaadin.shared.EventId;
  56. import com.vaadin.shared.MouseEventDetails;
  57. import com.vaadin.shared.Registration;
  58. import com.vaadin.shared.ui.ComponentStateUtil;
  59. import com.vaadin.shared.ui.ContentMode;
  60. import com.vaadin.shared.ui.ErrorLevel;
  61. import com.vaadin.shared.util.SharedUtil;
  62. import com.vaadin.ui.declarative.DesignAttributeHandler;
  63. import com.vaadin.ui.declarative.DesignContext;
  64. import com.vaadin.util.ReflectTools;
  65. /**
  66. * An abstract class that defines default implementation for the
  67. * {@link Component} interface. Basic UI components that are not derived from an
  68. * external component can inherit this class to easily qualify as Vaadin
  69. * components. Most components in Vaadin do just that.
  70. *
  71. * @author Vaadin Ltd.
  72. * @since 3.0
  73. */
  74. @SuppressWarnings("serial")
  75. public abstract class AbstractComponent extends AbstractClientConnector
  76. implements Component, ContextClickNotifier {
  77. /* Private members */
  78. /**
  79. * Application specific data object. The component does not use or modify
  80. * this.
  81. */
  82. private Object applicationData;
  83. /**
  84. * The internal error message of the component.
  85. */
  86. private ErrorMessage componentError;
  87. /**
  88. * Locale of this component.
  89. */
  90. private Locale locale;
  91. /**
  92. * The component should receive focus (if {@link Focusable}) when attached.
  93. */
  94. private boolean delayedFocus;
  95. /* Sizeable fields */
  96. private float width = SIZE_UNDEFINED;
  97. private float height = SIZE_UNDEFINED;
  98. private Unit widthUnit = Unit.PIXELS;
  99. private Unit heightUnit = Unit.PIXELS;
  100. /**
  101. * Keeps track of the Actions added to this component; the actual
  102. * handling/notifying is delegated, usually to the containing window.
  103. */
  104. private ConnectorActionManager actionManager;
  105. private boolean visible = true;
  106. private HasComponents parent;
  107. protected static final String DESIGN_ATTR_PLAIN_TEXT = "plain-text";
  108. /* Constructor */
  109. /**
  110. * Constructs a new Component.
  111. */
  112. public AbstractComponent() {
  113. // ComponentSizeValidator.setCreationLocation(this);
  114. }
  115. /* Get/Set component properties */
  116. /*
  117. * (non-Javadoc)
  118. *
  119. * @see com.vaadin.ui.Component#setId(java.lang.String)
  120. */
  121. @Override
  122. public void setId(String id) {
  123. getState().id = id;
  124. }
  125. /*
  126. * (non-Javadoc)
  127. *
  128. * @see com.vaadin.ui.Component#getId()
  129. */
  130. @Override
  131. public String getId() {
  132. return getState(false).id;
  133. }
  134. /**
  135. * @deprecated As of 7.0. Use {@link #setId(String)}
  136. */
  137. @Deprecated
  138. public void setDebugId(String id) {
  139. setId(id);
  140. }
  141. /**
  142. * @deprecated As of 7.0. Use {@link #getId()}
  143. */
  144. @Deprecated
  145. public String getDebugId() {
  146. return getId();
  147. }
  148. /*
  149. * Gets the component's style. Don't add a JavaDoc comment here, we use the
  150. * default documentation from implemented interface.
  151. */
  152. @Override
  153. public String getStyleName() {
  154. String s = "";
  155. if (ComponentStateUtil.hasStyles(getState(false))) {
  156. for (final Iterator<String> it = getState(false).styles
  157. .iterator(); it.hasNext();) {
  158. s += it.next();
  159. if (it.hasNext()) {
  160. s += " ";
  161. }
  162. }
  163. }
  164. return s;
  165. }
  166. /*
  167. * Sets the component's style. Don't add a JavaDoc comment here, we use the
  168. * default documentation from implemented interface.
  169. */
  170. @Override
  171. public void setStyleName(String style) {
  172. if (style == null || style.isEmpty()) {
  173. getState().styles = null;
  174. return;
  175. }
  176. if (getState().styles == null) {
  177. getState().styles = new ArrayList<>();
  178. }
  179. List<String> styles = getState().styles;
  180. styles.clear();
  181. StringTokenizer tokenizer = new StringTokenizer(style, " ");
  182. while (tokenizer.hasMoreTokens()) {
  183. styles.add(tokenizer.nextToken());
  184. }
  185. }
  186. @Override
  187. public void setPrimaryStyleName(String style) {
  188. getState().primaryStyleName = style;
  189. }
  190. @Override
  191. public String getPrimaryStyleName() {
  192. return getState(false).primaryStyleName;
  193. }
  194. @Override
  195. public void addStyleName(String style) {
  196. if (style == null || style.isEmpty()) {
  197. return;
  198. }
  199. if (style.contains(" ")) {
  200. // Split space separated style names and add them one by one.
  201. StringTokenizer tokenizer = new StringTokenizer(style, " ");
  202. while (tokenizer.hasMoreTokens()) {
  203. addStyleName(tokenizer.nextToken());
  204. }
  205. return;
  206. }
  207. if (getState().styles == null) {
  208. getState().styles = new ArrayList<>();
  209. }
  210. List<String> styles = getState().styles;
  211. if (!styles.contains(style)) {
  212. styles.add(style);
  213. }
  214. }
  215. @Override
  216. public void removeStyleName(String style) {
  217. if (ComponentStateUtil.hasStyles(getState())) {
  218. StringTokenizer tokenizer = new StringTokenizer(style, " ");
  219. while (tokenizer.hasMoreTokens()) {
  220. getState().styles.remove(tokenizer.nextToken());
  221. }
  222. }
  223. }
  224. /**
  225. * Adds or removes a style name. Multiple styles can be specified as a
  226. * space-separated list of style names.
  227. *
  228. * If the {@code add} parameter is true, the style name is added to the
  229. * component. If the {@code add} parameter is false, the style name is
  230. * removed from the component.
  231. * <p>
  232. * Functionally this is equivalent to using {@link #addStyleName(String)} or
  233. * {@link #removeStyleName(String)}
  234. *
  235. * @since 7.5
  236. * @param style
  237. * the style name to be added or removed
  238. * @param add
  239. * <code>true</code> to add the given style, <code>false</code>
  240. * to remove it
  241. * @see #addStyleName(String)
  242. * @see #removeStyleName(String)
  243. */
  244. public void setStyleName(String style, boolean add) {
  245. if (add) {
  246. addStyleName(style);
  247. } else {
  248. removeStyleName(style);
  249. }
  250. }
  251. /*
  252. * Get's the component's caption. Don't add a JavaDoc comment here, we use
  253. * the default documentation from implemented interface.
  254. */
  255. @Override
  256. public String getCaption() {
  257. return getState(false).caption;
  258. }
  259. @Override
  260. public void setCaption(String caption) {
  261. getState().caption = caption;
  262. }
  263. /**
  264. * Sets whether the caption is rendered as HTML.
  265. * <p>
  266. * If set to true, the captions are rendered in the browser as HTML and the
  267. * developer is responsible for ensuring no harmful HTML is used. If set to
  268. * false, the caption is rendered in the browser as plain text.
  269. * <p>
  270. * The default is false, i.e. to render that caption as plain text.
  271. *
  272. * @param captionAsHtml
  273. * true if the captions are rendered as HTML, false if rendered
  274. * as plain text
  275. */
  276. public void setCaptionAsHtml(boolean captionAsHtml) {
  277. getState().captionAsHtml = captionAsHtml;
  278. }
  279. /**
  280. * Checks whether captions are rendered as HTML
  281. * <p>
  282. * The default is false, i.e. to render that caption as plain text.
  283. *
  284. * @return true if the captions are rendered as HTML, false if rendered as
  285. * plain text
  286. */
  287. public boolean isCaptionAsHtml() {
  288. return getState(false).captionAsHtml;
  289. }
  290. /*
  291. * Don't add a JavaDoc comment here, we use the default documentation from
  292. * implemented interface.
  293. */
  294. @Override
  295. public Locale getLocale() {
  296. if (locale != null) {
  297. return locale;
  298. }
  299. HasComponents parent = getParent();
  300. if (parent != null) {
  301. return parent.getLocale();
  302. }
  303. final VaadinSession session = getSession();
  304. if (session != null) {
  305. return session.getLocale();
  306. }
  307. return null;
  308. }
  309. /**
  310. * Sets the locale of this component.
  311. *
  312. * <pre>
  313. * // Component for which the locale is meaningful
  314. * InlineDateField date = new InlineDateField(&quot;Datum&quot;);
  315. *
  316. * // German language specified with ISO 639-1 language
  317. * // code and ISO 3166-1 alpha-2 country code.
  318. * date.setLocale(new Locale(&quot;de&quot;, &quot;DE&quot;));
  319. *
  320. * date.setResolution(DateField.RESOLUTION_DAY);
  321. * layout.addComponent(date);
  322. * </pre>
  323. *
  324. *
  325. * @param locale
  326. * the locale to become this component's locale.
  327. */
  328. public void setLocale(Locale locale) {
  329. this.locale = locale;
  330. if (locale != null && isAttached()) {
  331. getUI().getLocaleService().addLocale(locale);
  332. }
  333. markAsDirty();
  334. }
  335. /*
  336. * Gets the component's icon resource. Don't add a JavaDoc comment here, we
  337. * use the default documentation from implemented interface.
  338. */
  339. @Override
  340. public Resource getIcon() {
  341. return getResource(ComponentConstants.ICON_RESOURCE);
  342. }
  343. /**
  344. * Sets the component's icon.
  345. *
  346. * @param icon
  347. * the icon to be shown with the component's caption.
  348. */
  349. @Override
  350. public void setIcon(Resource icon) {
  351. setResource(ComponentConstants.ICON_RESOURCE, icon);
  352. }
  353. /*
  354. * (non-Javadoc)
  355. *
  356. * @see com.vaadin.ui.Component#isEnabled()
  357. */
  358. @Override
  359. public boolean isEnabled() {
  360. return getState(false).enabled;
  361. }
  362. /*
  363. * (non-Javadoc)
  364. *
  365. * @see com.vaadin.ui.Component#setEnabled(boolean)
  366. */
  367. @Override
  368. public void setEnabled(boolean enabled) {
  369. getState().enabled = enabled;
  370. }
  371. /*
  372. * (non-Javadoc)
  373. *
  374. * @see com.vaadin.client.Connector#isConnectorEnabled()
  375. */
  376. @Override
  377. public boolean isConnectorEnabled() {
  378. if (!isVisible()) {
  379. return false;
  380. } else if (!isEnabled()) {
  381. return false;
  382. } else if (!super.isConnectorEnabled()) {
  383. return false;
  384. }
  385. return !(getParent() instanceof SelectiveRenderer)
  386. || ((SelectiveRenderer) getParent()).isRendered(this);
  387. }
  388. /*
  389. * (non-Javadoc)
  390. *
  391. * @see com.vaadin.ui.Component#isVisible()
  392. */
  393. @Override
  394. public boolean isVisible() {
  395. return visible;
  396. }
  397. /*
  398. * (non-Javadoc)
  399. *
  400. * @see com.vaadin.ui.Component#setVisible(boolean)
  401. */
  402. @Override
  403. public void setVisible(boolean visible) {
  404. if (isVisible() == visible) {
  405. return;
  406. }
  407. this.visible = visible;
  408. if (visible) {
  409. /*
  410. * If the visibility state is toggled from invisible to visible it
  411. * affects all children (the whole hierarchy) in addition to this
  412. * component.
  413. */
  414. markAsDirtyRecursive();
  415. }
  416. if (getParent() != null) {
  417. // Must always repaint the parent (at least the hierarchy) when
  418. // visibility of a child component changes.
  419. getParent().markAsDirty();
  420. }
  421. }
  422. /*
  423. * (non-Javadoc)
  424. *
  425. * @see com.vaadin.ui.Component#getDescription()
  426. */
  427. @Override
  428. public String getDescription() {
  429. return getState(false).description;
  430. }
  431. /**
  432. * Sets the component's description. See {@link #getDescription()} for more
  433. * information on what the description is.
  434. *
  435. * @see #setDescription(String, ContentMode)
  436. * @param description
  437. * the new description string for the component.
  438. */
  439. public void setDescription(String description) {
  440. setDescription(description, ContentMode.PREFORMATTED);
  441. }
  442. /**
  443. * Sets the component's description using given content {@code mode}. See
  444. * {@link #getDescription()} for more information on what the description
  445. * is.
  446. * <p>
  447. * If the content {@code mode} is {@literal ContentMode.HTML} the
  448. * description is displayed as HTML in tooltips or directly in certain
  449. * components so care should be taken to avoid creating the possibility for
  450. * HTML injection and possibly XSS vulnerabilities.
  451. *
  452. * @param description
  453. * the new description string for the component.
  454. * @param mode
  455. * the content mode for the description
  456. * @since 8.0
  457. */
  458. public void setDescription(String description, ContentMode mode) {
  459. getState().description = description;
  460. getState().descriptionContentMode = mode;
  461. }
  462. /*
  463. * Gets the component's parent component. Don't add a JavaDoc comment here,
  464. * we use the default documentation from implemented interface.
  465. */
  466. @Override
  467. public HasComponents getParent() {
  468. return parent;
  469. }
  470. @Override
  471. public void setParent(HasComponents parent) {
  472. // If the parent is not changed, don't do anything
  473. if (parent == null ? this.parent == null : parent.equals(this.parent)) {
  474. return;
  475. }
  476. if (parent != null && this.parent != null) {
  477. throw new IllegalStateException(
  478. getClass().getName() + " already has a parent.");
  479. }
  480. ClientConnector oldParent = getParent();
  481. // Send a detach event if the component is currently attached
  482. if (isAttached()) {
  483. detach();
  484. }
  485. // Connect to new parent
  486. this.parent = parent;
  487. // Send attach event if the component is now attached
  488. if (isAttached()) {
  489. attach();
  490. }
  491. if (oldParent != null) {
  492. oldParent.markAsDirty();
  493. }
  494. }
  495. /**
  496. * Returns the closest ancestor with the given type.
  497. * <p>
  498. * To find the Window that contains the component, use {@code Window w =
  499. * getParent(Window.class);}
  500. * </p>
  501. *
  502. * @param <T>
  503. * The type of the ancestor
  504. * @param parentType
  505. * The ancestor class we are looking for
  506. * @return The first ancestor that can be assigned to the given class. Null
  507. * if no ancestor with the correct type could be found.
  508. */
  509. public <T extends HasComponents> T findAncestor(Class<T> parentType) {
  510. HasComponents p = getParent();
  511. while (p != null) {
  512. if (parentType.isAssignableFrom(p.getClass())) {
  513. return parentType.cast(p);
  514. }
  515. p = p.getParent();
  516. }
  517. return null;
  518. }
  519. /**
  520. * Gets the error message for this component.
  521. *
  522. * @return ErrorMessage containing the description of the error state of the
  523. * component or null, if the component contains no errors. Extending
  524. * classes should override this method if they support other error
  525. * message types such as validation errors or buffering errors. The
  526. * returned error message contains information about all the errors.
  527. */
  528. public ErrorMessage getErrorMessage() {
  529. return componentError;
  530. }
  531. /**
  532. * Gets the component's error message.
  533. *
  534. * @link Terminal.ErrorMessage#ErrorMessage(String, int)
  535. *
  536. * @return the component's error message.
  537. */
  538. public ErrorMessage getComponentError() {
  539. return componentError;
  540. }
  541. /**
  542. * Sets the component's error message. The message may contain certain XML
  543. * tags, for more information see
  544. *
  545. * @link Component.ErrorMessage#ErrorMessage(String, int)
  546. *
  547. * @param componentError
  548. * the new <code>ErrorMessage</code> of the component.
  549. */
  550. public void setComponentError(ErrorMessage componentError) {
  551. this.componentError = componentError;
  552. fireComponentErrorEvent();
  553. markAsDirty();
  554. }
  555. /*
  556. * Notify the component that it's attached to a window. Don't add a JavaDoc
  557. * comment here, we use the default documentation from implemented
  558. * interface.
  559. */
  560. @Override
  561. public void attach() {
  562. super.attach();
  563. if (delayedFocus) {
  564. focus();
  565. }
  566. setActionManagerViewer();
  567. if (locale != null) {
  568. getUI().getLocaleService().addLocale(locale);
  569. }
  570. }
  571. /*
  572. * Detach the component from application. Don't add a JavaDoc comment here,
  573. * we use the default documentation from implemented interface.
  574. */
  575. @Override
  576. public void detach() {
  577. super.detach();
  578. if (actionManager != null) {
  579. // Remove any existing viewer. UI cast is just to make the
  580. // compiler happy
  581. actionManager.setViewer((UI) null);
  582. }
  583. }
  584. /**
  585. * Sets the focus for this component if the component is {@link Focusable}.
  586. */
  587. protected void focus() {
  588. if (this instanceof Focusable) {
  589. final VaadinSession session = getSession();
  590. if (session != null) {
  591. getUI().setFocusedComponent((Focusable) this);
  592. delayedFocus = false;
  593. } else {
  594. delayedFocus = true;
  595. }
  596. }
  597. }
  598. /**
  599. * Build CSS compatible string representation of height.
  600. *
  601. * @return CSS height
  602. */
  603. private String getCSSHeight() {
  604. return getHeight() + getHeightUnits().getSymbol();
  605. }
  606. /**
  607. * Build CSS compatible string representation of width.
  608. *
  609. * @return CSS width
  610. */
  611. private String getCSSWidth() {
  612. return getWidth() + getWidthUnits().getSymbol();
  613. }
  614. /**
  615. * Returns the shared state bean with information to be sent from the server
  616. * to the client.
  617. *
  618. * Subclasses should override this method and set any relevant fields of the
  619. * state returned by super.getState().
  620. *
  621. * @since 7.0
  622. *
  623. * @return updated component shared state
  624. */
  625. @Override
  626. protected AbstractComponentState getState() {
  627. return (AbstractComponentState) super.getState();
  628. }
  629. @Override
  630. protected AbstractComponentState getState(boolean markAsDirty) {
  631. return (AbstractComponentState) super.getState(markAsDirty);
  632. }
  633. @Override
  634. public void beforeClientResponse(boolean initial) {
  635. super.beforeClientResponse(initial);
  636. // TODO This logic should be on the client side and the state should
  637. // simply be a data object with "width" and "height".
  638. if (getHeight() >= 0 && (getHeightUnits() != Unit.PERCENTAGE
  639. || ComponentSizeValidator.parentCanDefineHeight(this))) {
  640. getState().height = "" + getCSSHeight();
  641. } else {
  642. getState().height = "";
  643. }
  644. if (getWidth() >= 0 && (getWidthUnits() != Unit.PERCENTAGE
  645. || ComponentSizeValidator.parentCanDefineWidth(this))) {
  646. getState().width = "" + getCSSWidth();
  647. } else {
  648. getState().width = "";
  649. }
  650. ErrorMessage error = getErrorMessage();
  651. if (null != error) {
  652. getState().errorMessage = error.getFormattedHtmlMessage();
  653. getState().errorLevel = error.getErrorLevel();
  654. } else {
  655. getState().errorMessage = null;
  656. getState().errorLevel = null;
  657. }
  658. }
  659. /* General event framework */
  660. private static final Method COMPONENT_EVENT_METHOD = ReflectTools
  661. .findMethod(Component.Listener.class, "componentEvent",
  662. Component.Event.class);
  663. /* Component event framework */
  664. /*
  665. * Registers a new listener to listen events generated by this component.
  666. * Don't add a JavaDoc comment here, we use the default documentation from
  667. * implemented interface.
  668. */
  669. @Override
  670. public Registration addListener(Component.Listener listener) {
  671. return addListener(Component.Event.class, listener,
  672. COMPONENT_EVENT_METHOD);
  673. }
  674. @Override
  675. @Deprecated
  676. public void removeListener(Component.Listener listener) {
  677. removeListener(Component.Event.class, listener, COMPONENT_EVENT_METHOD);
  678. }
  679. /**
  680. * Emits the component event. It is transmitted to all registered listeners
  681. * interested in such events.
  682. */
  683. protected void fireComponentEvent() {
  684. fireEvent(new Component.Event(this));
  685. }
  686. /**
  687. * Emits the component error event. It is transmitted to all registered
  688. * listeners interested in such events.
  689. */
  690. protected void fireComponentErrorEvent() {
  691. fireEvent(new Component.ErrorEvent(getComponentError(), this));
  692. }
  693. /**
  694. * Sets the data object, that can be used for any application specific data.
  695. * The component does not use or modify this data.
  696. *
  697. * @param data
  698. * the Application specific data.
  699. * @since 3.1
  700. */
  701. public void setData(Object data) {
  702. applicationData = data;
  703. }
  704. /**
  705. * Gets the application specific data. See {@link #setData(Object)}.
  706. *
  707. * @return the Application specific data set with setData function.
  708. * @since 3.1
  709. */
  710. public Object getData() {
  711. return applicationData;
  712. }
  713. /* Sizeable and other size related methods */
  714. /*
  715. * (non-Javadoc)
  716. *
  717. * @see com.vaadin.Sizeable#getHeight()
  718. */
  719. @Override
  720. public float getHeight() {
  721. return height;
  722. }
  723. /*
  724. * (non-Javadoc)
  725. *
  726. * @see com.vaadin.server.Sizeable#getHeightUnits()
  727. */
  728. @Override
  729. public Unit getHeightUnits() {
  730. return heightUnit;
  731. }
  732. /*
  733. * (non-Javadoc)
  734. *
  735. * @see com.vaadin.server.Sizeable#getWidth()
  736. */
  737. @Override
  738. public float getWidth() {
  739. return width;
  740. }
  741. /*
  742. * (non-Javadoc)
  743. *
  744. * @see com.vaadin.server.Sizeable#getWidthUnits()
  745. */
  746. @Override
  747. public Unit getWidthUnits() {
  748. return widthUnit;
  749. }
  750. /*
  751. * (non-Javadoc)
  752. *
  753. * @see com.vaadin.server.Sizeable#setHeight(float, Unit)
  754. */
  755. @Override
  756. public void setHeight(float height, Unit unit) {
  757. if (unit == null) {
  758. throw new IllegalArgumentException("Unit can not be null");
  759. }
  760. this.height = height;
  761. heightUnit = unit;
  762. markAsDirty();
  763. // ComponentSizeValidator.setHeightLocation(this);
  764. }
  765. /*
  766. * (non-Javadoc)
  767. *
  768. * @see com.vaadin.server.Sizeable#setSizeFull()
  769. */
  770. @Override
  771. public void setSizeFull() {
  772. setWidth(100, Unit.PERCENTAGE);
  773. setHeight(100, Unit.PERCENTAGE);
  774. }
  775. /*
  776. * (non-Javadoc)
  777. *
  778. * @see com.vaadin.server.Sizeable#setSizeUndefined()
  779. */
  780. @Override
  781. public void setSizeUndefined() {
  782. setWidthUndefined();
  783. setHeightUndefined();
  784. }
  785. /*
  786. * (non-Javadoc)
  787. *
  788. * @see com.vaadin.server.Sizeable#setWidthUndefined()
  789. */
  790. @Override
  791. public void setWidthUndefined() {
  792. setWidth(-1, Unit.PIXELS);
  793. }
  794. /*
  795. * (non-Javadoc)
  796. *
  797. * @see com.vaadin.server.Sizeable#setHeightUndefined()
  798. */
  799. @Override
  800. public void setHeightUndefined() {
  801. setHeight(-1, Unit.PIXELS);
  802. }
  803. /*
  804. * (non-Javadoc)
  805. *
  806. * @see com.vaadin.server.Sizeable#setWidth(float, Unit)
  807. */
  808. @Override
  809. public void setWidth(float width, Unit unit) {
  810. if (unit == null) {
  811. throw new IllegalArgumentException("Unit can not be null");
  812. }
  813. this.width = width;
  814. widthUnit = unit;
  815. markAsDirty();
  816. // ComponentSizeValidator.setWidthLocation(this);
  817. }
  818. /*
  819. * (non-Javadoc)
  820. *
  821. * @see com.vaadin.server.Sizeable#setWidth(java.lang.String)
  822. */
  823. @Override
  824. public void setWidth(String width) {
  825. SizeWithUnit size = SizeWithUnit.parseStringSize(width);
  826. if (size != null) {
  827. setWidth(size.getSize(), size.getUnit());
  828. } else {
  829. setWidth(-1, Unit.PIXELS);
  830. }
  831. }
  832. /*
  833. * (non-Javadoc)
  834. *
  835. * @see com.vaadin.server.Sizeable#setHeight(java.lang.String)
  836. */
  837. @Override
  838. public void setHeight(String height) {
  839. SizeWithUnit size = SizeWithUnit.parseStringSize(height);
  840. if (size != null) {
  841. setHeight(size.getSize(), size.getUnit());
  842. } else {
  843. setHeight(-1, Unit.PIXELS);
  844. }
  845. }
  846. /*
  847. * (non-Javadoc)
  848. *
  849. * @see com.vaadin.ui.Component#readDesign(org.jsoup.nodes.Element,
  850. * com.vaadin.ui.declarative.DesignContext)
  851. */
  852. @Override
  853. public void readDesign(Element design, DesignContext designContext) {
  854. Attributes attr = design.attributes();
  855. // handle default attributes
  856. for (String attribute : getDefaultAttributes()) {
  857. if (design.hasAttr(attribute)) {
  858. DesignAttributeHandler.assignValue(this, attribute,
  859. design.attr(attribute));
  860. }
  861. }
  862. // handle locale
  863. if (attr.hasKey("locale")) {
  864. setLocale(getLocaleFromString(attr.get("locale")));
  865. }
  866. // handle width and height
  867. readSize(attr);
  868. // handle component error
  869. if (attr.hasKey("error")) {
  870. UserError error = new UserError(attr.get("error"),
  871. com.vaadin.server.AbstractErrorMessage.ContentMode.HTML,
  872. ErrorLevel.ERROR);
  873. setComponentError(error);
  874. }
  875. // Tab index when applicable
  876. if (design.hasAttr("tabindex") && this instanceof Focusable) {
  877. ((Focusable) this).setTabIndex(DesignAttributeHandler.readAttribute(
  878. "tabindex", design.attributes(), Integer.class));
  879. }
  880. // check for unsupported attributes
  881. Set<String> supported = new HashSet<>();
  882. supported.addAll(getDefaultAttributes());
  883. supported.addAll(getCustomAttributes());
  884. for (Attribute a : attr) {
  885. if (!a.getKey().startsWith(":")
  886. && !supported.contains(a.getKey())) {
  887. // Add unknown attributes as custom attributes to the context
  888. designContext.setCustomAttribute(this, a.getKey(),
  889. a.getValue());
  890. }
  891. }
  892. }
  893. /**
  894. * Constructs a Locale corresponding to the given string. The string should
  895. * consist of one, two or three parts with '_' between the different parts
  896. * if there is more than one part. The first part specifies the language,
  897. * the second part the country and the third part the variant of the locale.
  898. *
  899. * @param localeString
  900. * the locale specified as a string
  901. * @return the Locale object corresponding to localeString
  902. */
  903. private Locale getLocaleFromString(String localeString) {
  904. if (localeString == null) {
  905. return null;
  906. }
  907. String[] parts = localeString.split("_");
  908. if (parts.length > 3) {
  909. throw new RuntimeException(
  910. "Cannot parse the locale string: " + localeString);
  911. }
  912. switch (parts.length) {
  913. case 1:
  914. return new Locale(parts[0]);
  915. case 2:
  916. return new Locale(parts[0], parts[1]);
  917. default:
  918. return new Locale(parts[0], parts[1], parts[2]);
  919. }
  920. }
  921. /**
  922. * Toggles responsiveness of this component.
  923. *
  924. * @since 7.5.0
  925. * @param responsive
  926. * boolean enables responsiveness, false disables
  927. */
  928. public void setResponsive(boolean responsive) {
  929. if (responsive) {
  930. // make responsive if necessary
  931. if (!isResponsive()) {
  932. Responsive.makeResponsive(this);
  933. }
  934. } else {
  935. // remove responsive extensions
  936. List<Extension> extensions = new ArrayList<>(getExtensions());
  937. for (Extension e : extensions) {
  938. if (e instanceof Responsive) {
  939. removeExtension(e);
  940. }
  941. }
  942. }
  943. }
  944. /**
  945. * Returns true if the component is responsive.
  946. *
  947. * @since 7.5.0
  948. * @return true if the component is responsive
  949. */
  950. public boolean isResponsive() {
  951. for (Extension e : getExtensions()) {
  952. if (e instanceof Responsive) {
  953. return true;
  954. }
  955. }
  956. return false;
  957. }
  958. /**
  959. * Sets the read-only status in the state of this {@code AbstractComponent}.
  960. * This method should be made public in {@link Component Components} that
  961. * implement {@link HasValue}.
  962. *
  963. * @param readOnly
  964. * a boolean value specifying whether the component is put
  965. * read-only mode or not
  966. */
  967. protected void setReadOnly(boolean readOnly) {
  968. if (getState(false) instanceof AbstractFieldState) {
  969. if (readOnly != isReadOnly()) {
  970. ((AbstractFieldState) getState()).readOnly = readOnly;
  971. }
  972. } else {
  973. throw new IllegalStateException(
  974. "This component does not support the read-only mode, since state is of type "
  975. + getStateType().getSimpleName()
  976. + " and does not inherit "
  977. + AbstractFieldState.class.getSimpleName());
  978. }
  979. }
  980. /**
  981. * Returns the read-only status from the state of this
  982. * {@code AbstractComponent}. This method should be made public in
  983. * {@link Component Components} that implement {@link HasValue}.
  984. *
  985. * @return {@code true} if state has read-only on; {@code false} if not
  986. * @see #setReadOnly(boolean)
  987. */
  988. protected boolean isReadOnly() {
  989. if (getState(false) instanceof AbstractFieldState) {
  990. return ((AbstractFieldState) getState(false)).readOnly;
  991. }
  992. throw new IllegalStateException(
  993. "This component does not support the read-only mode, since state is of type "
  994. + getStateType().getSimpleName()
  995. + " and does not inherit "
  996. + AbstractFieldState.class.getSimpleName());
  997. }
  998. /**
  999. * Reads the size of this component from the given design attributes. If the
  1000. * attributes do not contain relevant size information, defaults is
  1001. * consulted.
  1002. *
  1003. * @param attributes
  1004. * the design attributes
  1005. */
  1006. private void readSize(Attributes attributes) {
  1007. // read width
  1008. if (attributes.hasKey("width-auto") || attributes.hasKey("size-auto")) {
  1009. this.setWidth(null);
  1010. } else if (attributes.hasKey("width-full")
  1011. || attributes.hasKey("size-full")) {
  1012. this.setWidth("100%");
  1013. } else if (attributes.hasKey("width")) {
  1014. this.setWidth(attributes.get("width"));
  1015. }
  1016. // read height
  1017. if (attributes.hasKey("height-auto")
  1018. || attributes.hasKey("size-auto")) {
  1019. this.setHeight(null);
  1020. } else if (attributes.hasKey("height-full")
  1021. || attributes.hasKey("size-full")) {
  1022. this.setHeight("100%");
  1023. } else if (attributes.hasKey("height")) {
  1024. this.setHeight(attributes.get("height"));
  1025. }
  1026. }
  1027. /**
  1028. * Writes the size related attributes for the component if they differ from
  1029. * the defaults
  1030. *
  1031. * @param attributes
  1032. * the attribute map where the attribute are written
  1033. * @param defaultInstance
  1034. * the default instance of the class for fetching the default
  1035. * values
  1036. */
  1037. private void writeSize(Attributes attributes, Component defaultInstance) {
  1038. if (hasEqualSize(defaultInstance)) {
  1039. // we have default values -> ignore
  1040. return;
  1041. }
  1042. boolean widthFull = getWidth() == 100f
  1043. && getWidthUnits().equals(Sizeable.Unit.PERCENTAGE);
  1044. boolean heightFull = getHeight() == 100f
  1045. && getHeightUnits().equals(Sizeable.Unit.PERCENTAGE);
  1046. boolean widthAuto = getWidth() == -1;
  1047. boolean heightAuto = getHeight() == -1;
  1048. // first try the full shorthands
  1049. if (widthFull && heightFull) {
  1050. attributes.put("size-full", true);
  1051. } else if (widthAuto && heightAuto) {
  1052. attributes.put("size-auto", true);
  1053. } else {
  1054. // handle width
  1055. if (!hasEqualWidth(defaultInstance)) {
  1056. if (widthFull) {
  1057. attributes.put("width-full", true);
  1058. } else if (widthAuto) {
  1059. attributes.put("width-auto", true);
  1060. } else {
  1061. String widthString = DesignAttributeHandler.getFormatter()
  1062. .format(getWidth()) + getWidthUnits().getSymbol();
  1063. attributes.put("width", widthString);
  1064. }
  1065. }
  1066. if (!hasEqualHeight(defaultInstance)) {
  1067. // handle height
  1068. if (heightFull) {
  1069. attributes.put("height-full", true);
  1070. } else if (heightAuto) {
  1071. attributes.put("height-auto", true);
  1072. } else {
  1073. String heightString = DesignAttributeHandler.getFormatter()
  1074. .format(getHeight()) + getHeightUnits().getSymbol();
  1075. attributes.put("height", heightString);
  1076. }
  1077. }
  1078. }
  1079. }
  1080. /**
  1081. * Test if the given component has equal width with this instance
  1082. *
  1083. * @param component
  1084. * the component for the width comparison
  1085. * @return true if the widths are equal
  1086. */
  1087. private boolean hasEqualWidth(Component component) {
  1088. return getWidth() == component.getWidth()
  1089. && getWidthUnits().equals(component.getWidthUnits());
  1090. }
  1091. /**
  1092. * Test if the given component has equal height with this instance
  1093. *
  1094. * @param component
  1095. * the component for the height comparison
  1096. * @return true if the heights are equal
  1097. */
  1098. private boolean hasEqualHeight(Component component) {
  1099. return getHeight() == component.getHeight()
  1100. && getHeightUnits().equals(component.getHeightUnits());
  1101. }
  1102. /**
  1103. * Test if the given components has equal size with this instance
  1104. *
  1105. * @param component
  1106. * the component for the size comparison
  1107. * @return true if the sizes are equal
  1108. */
  1109. private boolean hasEqualSize(Component component) {
  1110. return hasEqualWidth(component) && hasEqualHeight(component);
  1111. }
  1112. /**
  1113. * Returns a collection of attributes that do not require custom handling
  1114. * when reading or writing design. These are typically attributes of some
  1115. * primitive type. The default implementation searches setters with
  1116. * primitive values
  1117. *
  1118. * @return a collection of attributes that can be read and written using the
  1119. * default approach.
  1120. */
  1121. private Collection<String> getDefaultAttributes() {
  1122. Collection<String> attributes = DesignAttributeHandler
  1123. .getSupportedAttributes(this.getClass());
  1124. attributes.removeAll(getCustomAttributes());
  1125. return attributes;
  1126. }
  1127. /**
  1128. * Returns a collection of attributes that should not be handled by the
  1129. * basic implementation of the {@link #readDesign(Element, DesignContext)}
  1130. * and {@link #writeDesign(Element, DesignContext)} methods. Typically these
  1131. * are handled in a custom way in the overridden versions of the above
  1132. * methods
  1133. *
  1134. * @since 7.4
  1135. *
  1136. * @return the collection of attributes that are not handled by the basic
  1137. * implementation
  1138. */
  1139. protected Collection<String> getCustomAttributes() {
  1140. List<String> l = new ArrayList<>(Arrays.asList(CUSTOM_ATTRIBUTES));
  1141. if (this instanceof Focusable) {
  1142. l.add("tab-index");
  1143. l.add("tabindex");
  1144. }
  1145. return l;
  1146. }
  1147. private static final String[] CUSTOM_ATTRIBUTES = { "width", "height",
  1148. "debug-id", "error", "width-auto", "height-auto", "width-full",
  1149. "height-full", "size-auto", "size-full", "immediate", "locale",
  1150. "read-only", "_id" };
  1151. /*
  1152. * (non-Javadoc)
  1153. *
  1154. * @see com.vaadin.ui.Component#writeDesign(org.jsoup.nodes.Element,
  1155. * com.vaadin.ui.declarative.DesignContext)
  1156. */
  1157. @Override
  1158. public void writeDesign(Element design, DesignContext designContext) {
  1159. AbstractComponent def = designContext.getDefaultInstance(this);
  1160. Attributes attr = design.attributes();
  1161. // handle default attributes
  1162. for (String attribute : getDefaultAttributes()) {
  1163. DesignAttributeHandler.writeAttribute(this, attribute, attr, def,
  1164. designContext);
  1165. }
  1166. // handle locale
  1167. if (getLocale() != null && (getParent() == null
  1168. || !getLocale().equals(getParent().getLocale()))) {
  1169. design.attr("locale", getLocale().toString());
  1170. }
  1171. // handle size
  1172. writeSize(attr, def);
  1173. // handle component error
  1174. String errorMsg = getComponentError() != null
  1175. ? getComponentError().getFormattedHtmlMessage()
  1176. : null;
  1177. String defErrorMsg = def.getComponentError() != null
  1178. ? def.getComponentError().getFormattedHtmlMessage()
  1179. : null;
  1180. if (!SharedUtil.equals(errorMsg, defErrorMsg)) {
  1181. attr.put("error", errorMsg);
  1182. }
  1183. // handle tab index
  1184. if (this instanceof Focusable) {
  1185. DesignAttributeHandler.writeAttribute("tabindex", attr,
  1186. ((Focusable) this).getTabIndex(),
  1187. ((Focusable) def).getTabIndex(), Integer.class,
  1188. designContext);
  1189. }
  1190. // handle custom attributes
  1191. Map<String, String> customAttributes = designContext
  1192. .getCustomAttributes(this);
  1193. if (customAttributes != null) {
  1194. for (Entry<String, String> entry : customAttributes.entrySet()) {
  1195. attr.put(entry.getKey(), entry.getValue());
  1196. }
  1197. }
  1198. }
  1199. /*
  1200. * Actions
  1201. */
  1202. /**
  1203. * Gets the {@link ActionManager} used to manage the
  1204. * {@link ShortcutListener}s added to this component.
  1205. *
  1206. * @return the ActionManager in use
  1207. */
  1208. protected ActionManager getActionManager() {
  1209. if (actionManager == null) {
  1210. actionManager = new ConnectorActionManager(this);
  1211. setActionManagerViewer();
  1212. }
  1213. return actionManager;
  1214. }
  1215. /**
  1216. * Set a viewer for the action manager to be the parent sub window (if the
  1217. * component is in a window) or the UI (otherwise). This is still a
  1218. * simplification of the real case as this should be handled by the parent
  1219. * VOverlay (on the client side) if the component is inside an VOverlay
  1220. * component.
  1221. */
  1222. private void setActionManagerViewer() {
  1223. if (actionManager != null && getUI() != null) {
  1224. // Attached and has action manager
  1225. Window w = findAncestor(Window.class);
  1226. if (w != null) {
  1227. actionManager.setViewer(w);
  1228. } else {
  1229. actionManager.setViewer(getUI());
  1230. }
  1231. }
  1232. }
  1233. public Registration addShortcutListener(ShortcutListener shortcut) {
  1234. Objects.requireNonNull(shortcut, "Listener must not be null.");
  1235. getActionManager().addAction(shortcut);
  1236. return () -> getActionManager().removeAction(shortcut);
  1237. }
  1238. @Deprecated
  1239. public void removeShortcutListener(ShortcutListener shortcut) {
  1240. getActionManager().removeAction(shortcut);
  1241. }
  1242. /**
  1243. * Determine whether a <code>content</code> component is equal to, or the
  1244. * ancestor of this component.
  1245. *
  1246. * @param content
  1247. * the potential ancestor element
  1248. * @return <code>true</code> if the relationship holds
  1249. */
  1250. protected boolean isOrHasAncestor(Component content) {
  1251. if (content instanceof HasComponents) {
  1252. for (Component parent = this; parent != null; parent = parent
  1253. .getParent()) {
  1254. if (parent.equals(content)) {
  1255. return true;
  1256. }
  1257. }
  1258. }
  1259. return false;
  1260. }
  1261. @Override
  1262. public Registration addContextClickListener(ContextClickListener listener) {
  1263. // Register default Context Click RPC if needed. This RPC won't be
  1264. // called if there are no listeners on the server-side. A client-side
  1265. // connector can override this and use a different RPC channel.
  1266. if (getRpcManager(ContextClickRpc.class.getName()) == null) {
  1267. registerRpc(
  1268. (ContextClickRpc) (MouseEventDetails details) -> fireEvent(
  1269. new ContextClickEvent(AbstractComponent.this,
  1270. details)));
  1271. }
  1272. return addListener(EventId.CONTEXT_CLICK, ContextClickEvent.class,
  1273. listener, ContextClickEvent.CONTEXT_CLICK_METHOD);
  1274. }
  1275. @Override
  1276. @Deprecated
  1277. public void removeContextClickListener(ContextClickListener listener) {
  1278. removeListener(EventId.CONTEXT_CLICK, ContextClickEvent.class,
  1279. listener);
  1280. }
  1281. /**
  1282. * Sets the visibility of the required indicator. <strong>NOTE: Does not
  1283. * apply for all components!</strong>.
  1284. * <p>
  1285. * If the component supports the required indicator (state extends
  1286. * {@link AbstractFieldState}), then expose this method and
  1287. * {@link #isRequiredIndicatorVisible()} as {@code public} in the component
  1288. * and call this method.
  1289. * <p>
  1290. * This method will throw a {@link IllegalStateException} if the component
  1291. * state (returned by {@link #getState()}) does not inherit
  1292. * {@link AbstractFieldState}.
  1293. *
  1294. * @param visible
  1295. * <code>true</code> to make the required indicator visible,
  1296. * <code>false</code> if not
  1297. * @since 8.0
  1298. */
  1299. protected void setRequiredIndicatorVisible(boolean visible) {
  1300. if (getState(false) instanceof AbstractFieldState) {
  1301. ((AbstractFieldState) getState()).required = visible;
  1302. } else {
  1303. throw new IllegalStateException(
  1304. "This component does not support the required indicator, since state is of type "
  1305. + getStateType().getSimpleName()
  1306. + " and does not inherit "
  1307. + AbstractFieldState.class.getSimpleName());
  1308. }
  1309. }
  1310. /**
  1311. * Checks whether the required indicator is visible or not. <strong>NOTE:
  1312. * Does not apply for all components!</strong>.
  1313. * <p>
  1314. * This method will throw a {@link IllegalStateException} if the component
  1315. * state (returned by {@link #getState()}) does not inherit
  1316. * {@link AbstractFieldState}.
  1317. *
  1318. * @return <code>true</code> if visible, <code>false</code> if not
  1319. * @see #setRequiredIndicatorVisible(boolean)
  1320. * @since 8.0
  1321. */
  1322. protected boolean isRequiredIndicatorVisible() {
  1323. if (getState(false) instanceof AbstractFieldState) {
  1324. return ((AbstractFieldState) getState(false)).required;
  1325. }
  1326. throw new IllegalStateException(
  1327. "This component does not support the required indicator, since state is of type "
  1328. + getStateType().getSimpleName()
  1329. + " and does not inherit "
  1330. + AbstractFieldState.class.getSimpleName());
  1331. }
  1332. }