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

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