import java.util.List;
import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
*/
@Override
public String getPathForElement(Element targetElement) {
- if (targetElement == null) {
- return "";
+ Element oldTarget = targetElement;
+ Widget targetWidget = Util.findPaintable(client, targetElement)
+ .getWidget();
+ targetElement = targetWidget.getElement();
+
+ // Find SubPart name if needed.
+ String subPart = null;
+ boolean hasSubParts = targetWidget instanceof SubPartAware;
+ if (oldTarget != targetElement) {
+ if (hasSubParts) {
+ subPart = ((SubPartAware) targetWidget).getSubPartName(DOM
+ .asOld(oldTarget));
+ }
+
+ if (!hasSubParts || subPart == null) {
+ // Couldn't find SubPart name for element.
+ return null;
+ }
}
List<ConnectorPath> hierarchy = getConnectorHierarchyForElement(targetElement);
return null;
}
- return getBestSelector(generateQueries(path), targetElement);
+ return getBestSelector(generateQueries(path), targetElement, subPart);
}
/**
* List of selectors
* @param target
* Target element
+ * @param subPart
+ * sub part selector string for actual target
* @return Best selector string formatted with a post filter
*/
- private String getBestSelector(List<String> selectors, Element target) {
+ private String getBestSelector(List<String> selectors, Element target,
+ String subPart) {
// The last selector gives us smallest list index for target element.
String bestSelector = selectors.get(selectors.size() - 1);
int min = getElementsByPath(bestSelector).indexOf(target);
}
}
- return "(" + bestSelector + ")[" + min + "]";
+ return "(" + bestSelector + (subPart != null ? "#" + subPart : "")
+ + ")[" + min + "]";
}
.extractPostFilterPredicates(path);
if (postFilters.size() > 0) {
tmpPath = tmpPath.substring(1, tmpPath.lastIndexOf(')'));
+ if (tmpPath.contains("#")) {
+ // FIXME: SubParts should be handled.
+ tmpPath = tmpPath.split("#")[0];
+ }
}
// Generate an ElementQuery