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