My TreeGid
component shows the relation between images and Products. The relation between image and product objects is n:m (see below for a simplified example, product 60148971 is linked to at least two images).
When a user selects a product (see example) it is important to know its parent node. We need this information from the UI model because the product can have more than one parent. As far as I understand, this is not possible in Vaadin 8.1+. Can anyone confirm this?
My current solution is to use simple Link
objects as node, this object contains a reference to the image and the product. For usage, see code snippet (extremely simplified, just to get the idea).
@Override // from HierarchicalDataProvider
public Stream<HasTitle> fetchChildren(final HierarchicalQuery hq) {
HasTitle item = hq.getParent();
...
} else if (item instanceof Product) {
final Product p = (Product)item;
return p.getImages().stream()
.map(img -> new Link(p, img));
...
}
However, I consider this a hack. So if there is a more efficient way to do this, please let me know!
(using Vaadin 8.2.alpha2)