@Override
public String getPathForElement(Element targetElement) {
ComponentConnector connector = Util
.findPaintable(client, targetElement);
Widget w = null;
if (connector != null) {
// If we found a Paintable then we use that as reference. We should
// find the Paintable for all but very special cases (like
// overlays).
w = connector.getWidget();
/*
* Still if the Paintable contains a widget that implements
* SubPartAware, we want to use that as a reference
*/
Widget targetParent = findParentWidget(targetElement, w);
while (targetParent != w && targetParent != null) {
if (targetParent instanceof SubPartAware) {
/*
* The targetParent widget is a child of the Paintable and
* the first parent (of the targetElement) that implements
* SubPartAware
*/
w = targetParent;
break;
}
targetParent = targetParent.getParent();
}
}
if (w == null) {
// Check if the element is part of a widget that is attached
// directly to the root panel
RootPanel rootPanel = RootPanel.get();
int rootWidgetCount = rootPanel.getWidgetCount();
for (int i = 0; i < rootWidgetCount; i++) {
Widget rootWidget = rootPanel.getWidget(i);
if (rootWidget.getElement().isOrHasChild(targetElement)) {
// The target element is contained by this root widget
w = findParentWidget(targetElement, rootWidget);
break;
}
}
if (w != null) {
// We found a widget but we should still see if we find a
// SubPartAware implementor (we cannot find the Paintable as
// there is no link from VOverlay to its paintable/owner).
Widget subPartAwareWidget = findSubPartAwareParentWidget(w);
if (subPartAwareWidget != null) {
w = subPartAwareWidget;
}
}
}