import java.util.Arrays;
import java.util.List;
+import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.RootPanel;
import com.vaadin.client.ui.AbstractConnector;
import com.vaadin.client.ui.SubPartAware;
import com.vaadin.client.ui.VNotification;
+import com.vaadin.client.ui.ui.UIConnector;
/**
* The VaadinFinder locator strategy implements an XPath-like syntax for
} else {
+ final UIConnector uiConnector = client.getUIConnector();
elements.addAll(eliminateDuplicates(getElementsByPathStartingAtConnector(
- path, client.getUIConnector())));
+ path, uiConnector, Document.get().getBody())));
}
for (SelectorPredicate p : postFilters) {
path = path.substring(1, path.lastIndexOf(')'));
}
+ final ComponentConnector searchRoot = Util.findPaintable(client, root);
List<Element> elements = getElementsByPathStartingAtConnector(path,
- Util.findPaintable(client, root));
+ searchRoot, root);
for (SelectorPredicate p : postFilters) {
// Post filtering supports only indexes and follows instruction
* found.
*/
private List<Element> getElementsByPathStartingAtConnector(String path,
- ComponentConnector root) {
+ ComponentConnector root, Element actualRoot) {
String[] pathComponents = path.split(SUBPART_SEPARATOR);
List<ComponentConnector> connectors;
if (pathComponents[0].length() > 0) {
List<Element> output = new ArrayList<Element>();
if (null != connectors && !connectors.isEmpty()) {
- if (pathComponents.length > 1) {
- // We have subparts
- for (ComponentConnector connector : connectors) {
+ for (ComponentConnector connector : connectors) {
+ if (!actualRoot
+ .isOrHasChild(connector.getWidget().getElement())) {
+ // Filter out widgets that are not children of actual root
+ continue;
+ }
+
+ if (pathComponents.length > 1) {
+ // We have SubParts
if (connector.getWidget() instanceof SubPartAware) {
output.add(((SubPartAware) connector.getWidget())
.getSubPartElement(pathComponents[1]));
}
- }
- } else {
- for (ComponentConnector connector : connectors) {
+ } else {
output.add(connector.getWidget().getElement());
}
}