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.

LegacyLocatorStrategy.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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.client.componentlocator;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import com.google.gwt.core.client.JavaScriptObject;
  20. import com.google.gwt.dom.client.Element;
  21. import com.google.gwt.regexp.shared.RegExp;
  22. import com.google.gwt.user.client.DOM;
  23. import com.google.gwt.user.client.ui.HasWidgets;
  24. import com.google.gwt.user.client.ui.RootPanel;
  25. import com.google.gwt.user.client.ui.Widget;
  26. import com.vaadin.client.ApplicationConnection;
  27. import com.vaadin.client.ComponentConnector;
  28. import com.vaadin.client.ConnectorMap;
  29. import com.vaadin.client.ServerConnector;
  30. import com.vaadin.client.Util;
  31. import com.vaadin.client.VCaption;
  32. import com.vaadin.client.WidgetUtil;
  33. import com.vaadin.client.ui.SubPartAware;
  34. import com.vaadin.client.ui.VCssLayout;
  35. import com.vaadin.client.ui.VGridLayout;
  36. import com.vaadin.client.ui.VOverlay;
  37. import com.vaadin.client.ui.VTabsheetPanel;
  38. import com.vaadin.client.ui.VUI;
  39. import com.vaadin.client.ui.VWindow;
  40. import com.vaadin.client.ui.orderedlayout.Slot;
  41. import com.vaadin.client.ui.orderedlayout.VAbstractOrderedLayout;
  42. import com.vaadin.client.ui.window.WindowConnector;
  43. import com.vaadin.shared.AbstractComponentState;
  44. import com.vaadin.shared.Connector;
  45. import com.vaadin.shared.communication.SharedState;
  46. /**
  47. * The LegacyLocatorStrategy class handles the legacy locator syntax that was
  48. * introduced in version 5.4 of the framework. The legacy locator strategy is
  49. * always used if no other strategy claims responsibility for a locator string.
  50. *
  51. * @since 7.2
  52. * @author Vaadin Ltd
  53. */
  54. public class LegacyLocatorStrategy implements LocatorStrategy {
  55. /**
  56. * Separator used in the String locator between a parent and a child widget.
  57. */
  58. static final String PARENTCHILD_SEPARATOR = "/";
  59. /**
  60. * Separator used in the String locator between the part identifying the
  61. * containing widget and the part identifying the target element within the
  62. * widget.
  63. */
  64. static final String SUBPART_SEPARATOR = "#";
  65. /**
  66. * String that identifies the root panel when appearing first in the String
  67. * locator.
  68. */
  69. static final String ROOT_ID = "Root";
  70. private final ApplicationConnection client;
  71. private static final RegExp VALID_SYNTAX = RegExp.compile(
  72. "^((\\w+::)?((PID_S)?\\w[-$_a-zA-Z0-9.' ]*)?)?(/[-$_a-zA-Z0-9]+\\[\\d+\\])*/?(#.*)?$");
  73. public LegacyLocatorStrategy(ApplicationConnection clientConnection) {
  74. client = clientConnection;
  75. }
  76. @Override
  77. public boolean validatePath(String path) {
  78. return VALID_SYNTAX.test(path);
  79. }
  80. @Override
  81. public String getPathForElement(Element targetElement) {
  82. ComponentConnector connector = Util.findPaintable(client,
  83. targetElement);
  84. Widget w = null;
  85. if (connector != null) {
  86. // If we found a Paintable then we use that as reference. We should
  87. // find the Paintable for all but very special cases (like
  88. // overlays).
  89. w = connector.getWidget();
  90. /*
  91. * Still if the Paintable contains a widget that implements
  92. * SubPartAware, we want to use that as a reference
  93. */
  94. Widget targetParent = findParentWidget(targetElement, w);
  95. while (targetParent != w && targetParent != null) {
  96. if (targetParent instanceof SubPartAware) {
  97. /*
  98. * The targetParent widget is a child of the Paintable and
  99. * the first parent (of the targetElement) that implements
  100. * SubPartAware
  101. */
  102. w = targetParent;
  103. break;
  104. }
  105. targetParent = targetParent.getParent();
  106. }
  107. }
  108. if (w == null) {
  109. // Check if the element is part of a widget that is attached
  110. // directly to the root panel
  111. RootPanel rootPanel = RootPanel.get();
  112. int rootWidgetCount = rootPanel.getWidgetCount();
  113. for (int i = 0; i < rootWidgetCount; i++) {
  114. Widget rootWidget = rootPanel.getWidget(i);
  115. if (rootWidget.getElement().isOrHasChild(targetElement)) {
  116. // The target element is contained by this root widget
  117. w = findParentWidget(targetElement, rootWidget);
  118. break;
  119. }
  120. }
  121. if (w != null) {
  122. // We found a widget but we should still see if we find a
  123. // SubPartAware implementor (we cannot find the Paintable as
  124. // there is no link from VOverlay to its paintable/owner).
  125. Widget subPartAwareWidget = findSubPartAwareParentWidget(w);
  126. if (subPartAwareWidget != null) {
  127. w = subPartAwareWidget;
  128. }
  129. }
  130. }
  131. if (w == null) {
  132. // Containing widget not found
  133. return null;
  134. }
  135. // Determine the path for the target widget
  136. String path = getPathForWidget(w);
  137. if (path == null) {
  138. /*
  139. * No path could be determined for the target widget. Cannot create
  140. * a locator string.
  141. */
  142. return null;
  143. }
  144. // The parent check is a work around for Firefox 15 which fails to
  145. // compare elements properly (#9534)
  146. if (w.getElement() == targetElement) {
  147. /*
  148. * We are done if the target element is the root of the target
  149. * widget.
  150. */
  151. return path;
  152. } else if (w instanceof SubPartAware) {
  153. /*
  154. * If the widget can provide an identifier for the targetElement we
  155. * let it do that
  156. */
  157. String elementLocator = ((SubPartAware) w)
  158. .getSubPartName(DOM.asOld(targetElement));
  159. if (elementLocator != null) {
  160. return path + LegacyLocatorStrategy.SUBPART_SEPARATOR
  161. + elementLocator;
  162. }
  163. }
  164. /*
  165. * If everything else fails we use the DOM path to identify the target
  166. * element
  167. */
  168. String domPath = getDOMPathForElement(targetElement, w.getElement());
  169. if (domPath == null) {
  170. return path;
  171. } else {
  172. return path + domPath;
  173. }
  174. }
  175. /**
  176. * {@inheritDoc}
  177. */
  178. @Override
  179. public Element getElementByPath(String path) {
  180. return getElementByPathStartingAt(path, null);
  181. }
  182. /**
  183. * {@inheritDoc}
  184. */
  185. @Override
  186. public Element getElementByPathStartingAt(String path,
  187. Element baseElement) {
  188. /*
  189. * Path is of type "targetWidgetPath#componentPart" or
  190. * "targetWidgetPath".
  191. */
  192. String[] parts = path.split(LegacyLocatorStrategy.SUBPART_SEPARATOR, 2);
  193. String widgetPath = parts[0];
  194. // Note that this only works if baseElement can be mapped to a
  195. // widget to which the path is relative. Otherwise, the current
  196. // implementation simply interprets the path as if baseElement was
  197. // null.
  198. Widget baseWidget = WidgetUtil.findWidget(baseElement);
  199. Widget w = getWidgetFromPath(widgetPath, baseWidget);
  200. if (w == null || !WidgetUtil.isAttachedAndDisplayed(w)) {
  201. return null;
  202. }
  203. if (parts.length == 1) {
  204. int pos = widgetPath.indexOf("domChild");
  205. if (pos == -1) {
  206. return w.getElement();
  207. }
  208. // Contains dom reference to a sub element of the widget
  209. String subPath = widgetPath.substring(pos);
  210. return getElementByDOMPath(w.getElement(), subPath);
  211. } else if (parts.length == 2) {
  212. if (w instanceof SubPartAware) {
  213. return ((SubPartAware) w).getSubPartElement(parts[1]);
  214. }
  215. }
  216. return null;
  217. }
  218. /**
  219. * {@inheritDoc}
  220. */
  221. @Override
  222. public List<Element> getElementsByPath(String path) {
  223. // This type of search is not supported in LegacyLocator
  224. List<Element> array = new ArrayList<>();
  225. Element e = getElementByPath(path);
  226. if (e != null) {
  227. array.add(e);
  228. }
  229. return array;
  230. }
  231. /**
  232. * {@inheritDoc}
  233. */
  234. @Override
  235. public List<Element> getElementsByPathStartingAt(String path,
  236. Element root) {
  237. // This type of search is not supported in LegacyLocator
  238. List<Element> array = new ArrayList<>();
  239. Element e = getElementByPathStartingAt(path, root);
  240. if (e != null) {
  241. array.add(e);
  242. }
  243. return array;
  244. }
  245. /**
  246. * Finds the first widget in the hierarchy (moving upwards) that implements
  247. * SubPartAware. Returns the SubPartAware implementor or null if none is
  248. * found.
  249. *
  250. * @param w
  251. * The widget to start from. This is returned if it implements
  252. * SubPartAware.
  253. * @return The first widget (upwards in hierarchy) that implements
  254. * SubPartAware or null
  255. */
  256. Widget findSubPartAwareParentWidget(Widget w) {
  257. while (w != null) {
  258. if (w instanceof SubPartAware) {
  259. return w;
  260. }
  261. w = w.getParent();
  262. }
  263. return null;
  264. }
  265. /**
  266. * Returns the first widget found when going from {@code targetElement}
  267. * upwards in the DOM hierarchy, assuming that {@code ancestorWidget} is a
  268. * parent of {@code targetElement}.
  269. *
  270. * @param targetElement
  271. * @param ancestorWidget
  272. * @return The widget whose root element is a parent of
  273. * {@code targetElement}.
  274. */
  275. private Widget findParentWidget(Element targetElement,
  276. Widget ancestorWidget) {
  277. /*
  278. * As we cannot resolve Widgets from the element we start from the
  279. * widget and move downwards to the correct child widget, as long as we
  280. * find one.
  281. */
  282. if (ancestorWidget instanceof HasWidgets) {
  283. for (Widget w : ((HasWidgets) ancestorWidget)) {
  284. if (w.getElement().isOrHasChild(targetElement)) {
  285. return findParentWidget(targetElement, w);
  286. }
  287. }
  288. }
  289. // No children found, this is it
  290. return ancestorWidget;
  291. }
  292. /**
  293. * Locates an element based on a DOM path and a base element.
  294. *
  295. * @param baseElement
  296. * The base element which the path is relative to
  297. * @param path
  298. * String locator (consisting of domChild[x] parts) that
  299. * identifies the element
  300. * @return The element identified by path, relative to baseElement or null
  301. * if the element could not be found.
  302. */
  303. private Element getElementByDOMPath(Element baseElement, String path) {
  304. String[] parts = path.split(PARENTCHILD_SEPARATOR);
  305. Element element = baseElement;
  306. for (int i = 0, l = parts.length; i < l; ++i) {
  307. String part = parts[i];
  308. if (part.startsWith("domChild[")) {
  309. String childIndexString = part.substring("domChild[".length(),
  310. part.length() - 1);
  311. if (WidgetUtil.findWidget(
  312. baseElement) instanceof VAbstractOrderedLayout) {
  313. if (element.hasChildNodes()) {
  314. Element e = element.getFirstChildElement().cast();
  315. String cn = e.getClassName();
  316. if (cn != null && (cn.equals("v-expand")
  317. || cn.contains("v-has-caption"))) {
  318. element = e;
  319. }
  320. }
  321. }
  322. try {
  323. int childIndex = Integer.parseInt(childIndexString);
  324. element = DOM.getChild(element, childIndex);
  325. } catch (Exception e) {
  326. return null;
  327. }
  328. if (element == null) {
  329. return null;
  330. }
  331. } else {
  332. path = parts[i];
  333. for (int j = i + 1; j < l; ++j) {
  334. path += PARENTCHILD_SEPARATOR + parts[j];
  335. }
  336. return getElementByPathStartingAt(path, element);
  337. }
  338. }
  339. return element;
  340. }
  341. /**
  342. * Generates a String locator using domChild[x] parts for the element
  343. * relative to the baseElement.
  344. *
  345. * @param element
  346. * The target element
  347. * @param baseElement
  348. * The starting point for the locator. The generated path is
  349. * relative to this element.
  350. * @return A String locator that can be used to locate the target element
  351. * using {@link #getElementByDOMPath(Element, String)} or null if
  352. * the locator String cannot be created.
  353. */
  354. private String getDOMPathForElement(Element element, Element baseElement) {
  355. Element e = element;
  356. String path = "";
  357. while (true) {
  358. int childIndex = -1;
  359. Element siblingIterator = e;
  360. while (siblingIterator != null) {
  361. childIndex++;
  362. siblingIterator = siblingIterator.getPreviousSiblingElement()
  363. .cast();
  364. }
  365. path = PARENTCHILD_SEPARATOR + "domChild[" + childIndex + "]"
  366. + path;
  367. JavaScriptObject parent = e.getParentElement();
  368. if (parent == null) {
  369. return null;
  370. }
  371. // The parent check is a work around for Firefox 15 which fails to
  372. // compare elements properly (#9534)
  373. if (parent == baseElement) {
  374. break;
  375. }
  376. e = parent.cast();
  377. }
  378. return path;
  379. }
  380. /**
  381. * Creates a locator String for the given widget. The path can be used to
  382. * locate the widget using {@link #getWidgetFromPath(String, Widget)}.
  383. * <p/>
  384. * Returns null if no path can be determined for the widget or if the widget
  385. * is null.
  386. *
  387. * @param w
  388. * The target widget
  389. * @return A String locator for the widget
  390. */
  391. private String getPathForWidget(Widget w) {
  392. if (w == null) {
  393. return null;
  394. }
  395. String elementId = w.getElement().getId();
  396. if (elementId != null && !elementId.isEmpty()
  397. && !elementId.startsWith("gwt-uid-")) {
  398. // Use PID_S+id if the user has set an id but do not use it for auto
  399. // generated id:s as these might not be consistent
  400. return "PID_S" + elementId;
  401. } else if (w instanceof VUI) {
  402. return "";
  403. } else if (w instanceof VWindow) {
  404. Connector windowConnector = ConnectorMap.get(client)
  405. .getConnector(w);
  406. List<WindowConnector> subWindowList = client.getUIConnector()
  407. .getSubWindows();
  408. int indexOfSubWindow = subWindowList.indexOf(windowConnector);
  409. return PARENTCHILD_SEPARATOR + "VWindow[" + indexOfSubWindow + "]";
  410. } else if (w instanceof RootPanel) {
  411. return ROOT_ID;
  412. }
  413. Widget parent = w.getParent();
  414. String basePath = getPathForWidget(parent);
  415. if (basePath == null) {
  416. return null;
  417. }
  418. String simpleName = Util.getSimpleName(w);
  419. /*
  420. * Check if the parent implements Iterable. At least VPopupView does not
  421. * implement HasWdgets so we cannot check for that.
  422. */
  423. if (!(parent instanceof Iterable<?>)) {
  424. // Parent does not implement Iterable so we cannot find out which
  425. // child this is
  426. return null;
  427. }
  428. int pos = 0;
  429. for (Object child : (Iterable<?>) parent) {
  430. if (child == w) {
  431. return basePath + PARENTCHILD_SEPARATOR + simpleName + "[" + pos
  432. + "]";
  433. }
  434. String simpleName2 = Util.getSimpleName(child);
  435. if (simpleName.equals(simpleName2)) {
  436. pos++;
  437. }
  438. }
  439. return null;
  440. }
  441. /**
  442. * Locates the widget based on a String locator.
  443. *
  444. * @param path
  445. * The String locator that identifies the widget.
  446. * @param baseWidget
  447. * the widget to which the path is relative, null if relative to
  448. * root
  449. * @return The Widget identified by the String locator or null if the widget
  450. * could not be identified.
  451. */
  452. @SuppressWarnings("unchecked")
  453. private Widget getWidgetFromPath(String path, Widget baseWidget) {
  454. Widget w = baseWidget;
  455. String[] parts = path.split(PARENTCHILD_SEPARATOR);
  456. for (int i = 0; i < parts.length; i++) {
  457. String part = parts[i];
  458. if (part.equals(ROOT_ID)) {
  459. w = RootPanel.get();
  460. } else if (part.isEmpty()) {
  461. if (w == null) {
  462. w = client.getUIConnector().getWidget();
  463. }
  464. } else if (w == null) {
  465. String id = part;
  466. // Must be old static pid (PID_S*)
  467. ServerConnector connector = ConnectorMap.get(client)
  468. .getConnector(id);
  469. if (connector == null) {
  470. // Lookup by component id
  471. // TODO Optimize this
  472. connector = findConnectorById(client.getUIConnector(),
  473. id.substring(5));
  474. }
  475. if (connector instanceof ComponentConnector) {
  476. w = ((ComponentConnector) connector).getWidget();
  477. } else {
  478. // Not found
  479. return null;
  480. }
  481. } else if (part.startsWith("domChild[")) {
  482. // The target widget has been found and the rest identifies the
  483. // element
  484. break;
  485. } else if (w instanceof Iterable) {
  486. // W identifies a widget that contains other widgets, as it
  487. // should. Try to locate the child
  488. Iterable<?> parent = (Iterable<?>) w;
  489. // Part is of type "VVerticalLayout[0]", split this into
  490. // VVerticalLayout and 0
  491. String[] split = part.split("\\[", 2);
  492. String widgetClassName = split[0];
  493. String indexString = split[1].substring(0,
  494. split[1].length() - 1);
  495. int widgetPosition;
  496. try {
  497. widgetPosition = Integer.parseInt(indexString);
  498. } catch (NumberFormatException e) {
  499. // We've probably been fed a new-style Vaadin locator with a
  500. // string-form predicate, that doesn't match anything in the
  501. // search space.
  502. return null;
  503. }
  504. // AbsolutePanel in GridLayout has been removed -> skip it
  505. if (w instanceof VGridLayout
  506. && "AbsolutePanel".equals(widgetClassName)) {
  507. continue;
  508. }
  509. // FlowPane in CSSLayout has been removed -> skip it
  510. if (w instanceof VCssLayout
  511. && "VCssLayout$FlowPane".equals(widgetClassName)) {
  512. continue;
  513. }
  514. // ChildComponentContainer and VOrderedLayout$Slot have been
  515. // replaced with Slot
  516. if (w instanceof VAbstractOrderedLayout
  517. && ("ChildComponentContainer".equals(widgetClassName)
  518. || "VOrderedLayout$Slot"
  519. .equals(widgetClassName))) {
  520. widgetClassName = "Slot";
  521. }
  522. if (w instanceof VTabsheetPanel && widgetPosition != 0) {
  523. // TabSheetPanel now only contains 1 connector => the index
  524. // is always 0 which indicates the widget in the active tab
  525. widgetPosition = 0;
  526. }
  527. if (w instanceof VOverlay
  528. && "VCalendarPanel".equals(widgetClassName)) {
  529. // Vaadin 7.1 adds a wrapper for datefield popups
  530. parent = (Iterable<?>) ((Iterable<?>) parent).iterator()
  531. .next();
  532. }
  533. /*
  534. * The new grid and ordered layouts do not contain
  535. * ChildComponentContainer widgets. This is instead simulated by
  536. * constructing a path step that would find the desired widget
  537. * from the layout and injecting it as the next search step
  538. * (which would originally have found the widget inside the
  539. * ChildComponentContainer)
  540. */
  541. if ((w instanceof VGridLayout)
  542. && "ChildComponentContainer".equals(widgetClassName)
  543. && i + 1 < parts.length) {
  544. HasWidgets layout = (HasWidgets) w;
  545. String nextPart = parts[i + 1];
  546. String[] nextSplit = nextPart.split("\\[", 2);
  547. String nextWidgetClassName = nextSplit[0];
  548. // Find the n:th child and count the number of children with
  549. // the same type before it
  550. int nextIndex = 0;
  551. for (Widget child : layout) {
  552. boolean matchingType = nextWidgetClassName
  553. .equals(Util.getSimpleName(child));
  554. if (matchingType && widgetPosition == 0) {
  555. // This is the n:th child that we looked for
  556. break;
  557. } else if (widgetPosition < 0) {
  558. // Error if we're past the desired position without
  559. // a match
  560. return null;
  561. } else if (matchingType) {
  562. // If this was another child of the expected type,
  563. // increase the count for the next step
  564. nextIndex++;
  565. }
  566. // Don't count captions
  567. if (!(child instanceof VCaption)) {
  568. widgetPosition--;
  569. }
  570. }
  571. // Advance to the next step, this time checking for the
  572. // actual child widget
  573. parts[i + 1] = nextWidgetClassName + '[' + nextIndex + ']';
  574. continue;
  575. }
  576. // Locate the child
  577. Iterable<? extends Widget> iterable;
  578. /*
  579. * VWindow and VContextMenu workarounds for backwards
  580. * compatibility
  581. */
  582. if (widgetClassName.equals("VWindow")) {
  583. List<WindowConnector> windows = client.getUIConnector()
  584. .getSubWindows();
  585. List<VWindow> windowWidgets = new ArrayList<>(
  586. windows.size());
  587. for (WindowConnector wc : windows) {
  588. windowWidgets.add(wc.getWidget());
  589. }
  590. iterable = windowWidgets;
  591. } else if (widgetClassName.equals("VContextMenu")) {
  592. return client.getContextMenu();
  593. } else {
  594. iterable = (Iterable<? extends Widget>) parent;
  595. }
  596. boolean ok = false;
  597. // Find the widgetPosition:th child of type "widgetClassName"
  598. for (Widget child : iterable) {
  599. String simpleName2 = Util.getSimpleName(child);
  600. if (!widgetClassName.equals(simpleName2)
  601. && child instanceof Slot) {
  602. /*
  603. * Support legacy tests without any selector for the
  604. * Slot widget (i.e. /VVerticalLayout[0]/VButton[0]) by
  605. * directly checking the stuff inside the slot
  606. */
  607. child = ((Slot) child).getWidget();
  608. simpleName2 = Util.getSimpleName(child);
  609. }
  610. if (widgetClassName.equals(simpleName2)) {
  611. if (widgetPosition == 0) {
  612. w = child;
  613. ok = true;
  614. break;
  615. }
  616. widgetPosition--;
  617. }
  618. }
  619. if (!ok) {
  620. // Did not find the child
  621. return null;
  622. }
  623. } else {
  624. // W identifies something that is not a "HasWidgets". This
  625. // should not happen as all widget containers should implement
  626. // HasWidgets.
  627. return null;
  628. }
  629. }
  630. return w;
  631. }
  632. private ServerConnector findConnectorById(ServerConnector root, String id) {
  633. SharedState state = root.getState();
  634. if (state instanceof AbstractComponentState
  635. && id.equals(((AbstractComponentState) state).id)) {
  636. return root;
  637. }
  638. for (ServerConnector child : root.getChildren()) {
  639. ServerConnector found = findConnectorById(child, id);
  640. if (found != null) {
  641. return found;
  642. }
  643. }
  644. return null;
  645. }
  646. }