Tree - how to add multiple items with the same caption

How can I add multiple items with the same caption? (See the attached file)
13018.bmp (128 KB)

I found an example that is using HierarchicalContainer.

Here is code for anyone interested…

final HierarchicalContainer propertyContainer = new HierarchicalContainer();
propertyContainer.addContainerProperty(“name”, String.class, null);

Object id = null;
Object aParent = null;

// Application1
id = propertyContainer.addItem();
propertyContainer.getContainerProperty(id, “name”).setValue(“Application1”);
aParent = id;

id = propertyContainer.addItem();
propertyContainer.getContainerProperty(id, “name”).setValue(“Setting”);
propertyContainer.setParent(id, aParent);
aParent = id;

id = propertyContainer.addItem();
propertyContainer.getContainerProperty(id, “name”).setValue(“PropertyName1-1”);
propertyContainer.setParent(id, aParent);

id = propertyContainer.addItem();
propertyContainer.getContainerProperty(id, “name”).setValue(“PropertyName1-2”);
propertyContainer.setParent(id, aParent);

// Application2
id = propertyContainer.addItem();
propertyContainer.getContainerProperty(id, “name”).setValue(“Application2”);
aParent = id;

id = propertyContainer.addItem();
propertyContainer.getContainerProperty(id, “name”).setValue(“Setting”);
propertyContainer.setParent(id, aParent);
aParent = id;

id = propertyContainer.addItem();
propertyContainer.getContainerProperty(id, “name”).setValue(“PropertyName2-1”);
propertyContainer.setParent(id, aParent);

id = propertyContainer.addItem();
propertyContainer.getContainerProperty(id, “name”).setValue(“PropertyName2-2”);
propertyContainer.setParent(id, aParent);

tree.setContainerDataSource(propertyContainer);
tree.setItemCaptionPropertyId(“name”);
tree.setItemCaptionMode(Tree.ItemCaptionMode.PROPERTY);

I was about to post this same question, but your experience is a little different than mine. I have no trouble having two nodes with the same caption if they have
different parents
, but when two
siblings
have the same caption, then only one shows. I’d like them to both show.

Unlike your example code, I’m using the Tree interfaces. The failure to show two siblings with the same caption exists whether I use a HierarchicalContainer or IndexedContainer.

Sadly I cannot help with respect to the Tree, but from a user’s perspective, if you have two elements with the same caption at the same level in the tree, how would the user know which of the two to click?

In my application, the caption is set by the user. The node can also be moved around the tree, but I cannot force global uniqueness.

Having both nodes show (with the same name) is clear to the user that they need to change one or both, and they can do so. Having one completely missing is just causing major confusion that they don’t know how to deal with.

I was writing an example to show something somewhat similar to what you posted few minutes ago.

I am not sure, but if you will use a container, beware to implement the equals accordingly, otherwise you will have problems to assign children to each node.

Disregard my report about two items with the same caption not showing. The problem was in my Comparable that controls the order of items added to the tree.

Please do like this
Object itemId = tree.addItem();
tree.setItemCaption(itemId, “Setting”);
tree.setParent(itemId, root);
tree.setChildrenAllowed(itemId, true);

Thanks Shashank !!