Anatoly2
(Anatoly Shirokov)
February 14, 2011, 10:58am
1
As you know some GUI APIs have possibility to make to ensure visible tree item:
tree.ensureVisible(itemId);
After this the itemId item becomes visible.
Do you plan implement this feature in the Vaadin tree component? May be you know a workaround to reach the same using Vaadin tree component.
Thank you for any suggestions.
Jonatan
(Jonatan Kronqvist)
February 14, 2011, 12:33pm
2
Hi!
Currently there are no plans, but please create an enhancement ticket at
dev.vaadin.com
if you would like to see this feature in a future version.
As for a workaround, you can follow this algorithm to make your item the selected one:
Find the item ID of the item you want selected
Get the HierarchicalContainer and call getParent() and store them in a stack (or something) until you reach the root node
Starting from the last node added to the stack (the root node) call Tree.expandItem(node) on each item in the stack
Call Tree.setValue() with the item ID you want selected (see step 1)
After this has finished, you should have a tree that has expanded all the way to show your item and your item should be selected (hilighted).
HTH,
/Jonatan
Anatoly2
(Anatoly Shirokov)
February 14, 2011, 12:58pm
3
Jonatan, thank you very much for your answer.
My question was about slightly other thing.
As I can see setValue does not influence on item visibility (I mean visibility for user). Imagine big tree, wanted item hidden by current view port, I make the following call:
tree.setValue(itemId);
As the result tree does not change state (scroll position and something else) and the wanted item is still hidden from user.
My question was how to ensure visible the hidden from user item.
Thanks in advance,
Anatoly Shirokov.
John
(John Ahlroos)
February 14, 2011, 1:11pm
4
Well, one way to solve it is to extend the client side implementation, here is an example:
public class VMyTree extends VTree {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
super.updateFromUIDL(uidl, client);
Set<String> selectedIds = uidl.getStringArrayVariableAsSet("selected");
if (selectedIds != null && !selectedIds.isEmpty()) {
// Scroll selected item into view
TreeNode selected = getNodeByKey(selectedIds.iterator().next());
selected.scrollIntoView();
}
}
}
Anatoly2
(Anatoly Shirokov)
February 14, 2011, 2:25pm
5
Thank you very much John! It is very helpfull. One more question. Why doesn’t Vaadin use such an implementation inside? As for me it is expected behavior.
tarun2
(tarun sawlani)
February 23, 2012, 1:07pm
6
I tried this. But some how tree scrolls back down after scrolling to the caption in a flash. Can you please suggest.