cancel
Showing results for 
Search instead for 
Did you mean: 

How to change tree-selection from another view?

Former Member
0 Kudos

Hello!

I am working on a webdynpro project with a classic model like: navigation (recursive tree in "TreeView") on the left and the main views on the right side.

The tree works well, I can initialize it with my data and on actionSelect I can change to the corresponding view on the right side.

The treeElements are bound to some data, I get from a JDBC database or XML file. It's built in the following way:

TreeNode
- hasChildren
- id (according to the database entity IDs)
- ignoreAction
- isExpanded
- parentElementId
- text
selectedElement

Of course, the user can navigate through the views by using buttons like "next" or "previous". In this case, I'd like to change the selection of the tree - according to the shown view.

I had the idea to implement it this way:

onPlugFromAnotherView(BigDecimal id) {
itereate through tree
if treeElement.getID().equals(id)
treeElement.setSelection;
} 

...but I didn't found any methods like this. Is there a opportunity to do it like this? Or another way?

Greetings,

Ramó

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

One possibility would be to keep a map "treeNodeById" mapping each ID to the corresponding "tree node" (represented by the context element).

Then you could easily select a tree node from its ID:


void selectTreeNode(String id)
{
  IWDNodeElement e = (IWDNodeElement) treeNodeById.get(id);
  try
  {
    wdContext.nodeTreeNode().setTreeSelection(e);
  }
  catch (WDContextException x)
  {
    /* handle x */
  }
}

The map could by created while building the context node that stores the tree nodes.

Armin

Former Member
0 Kudos

Thanks a lot for your help!

It work's great!

Former Member
0 Kudos

One last question to this topic:

In case that the method selects a treeNodeElement, which is not visible, because it's parentNode is not expanded: Is it possible to expand the parentNode?

for example like:

IWDNodeElement e = (IWDNodeElement) treeNodeMap.get(elementId);
wdContext.nodeTreeNode().setTreeSelection(e);
e.getParentNode().setIsExpanded(true);

Greetings,

Ramó

Former Member
0 Kudos

As far as I know, the current implementation automatically expands the path to the selected tree node (which might not be what you expect). Isn't that the case in your application?

Armin

Former Member
0 Kudos

Hello! No, in my application actually there is no way to expand the nodes to tree selection automatically.

But it sounds like it wouldn't be so difficult to implement this...

...ok, it wasn't really difficult. I just switched the "expanded" property of the TreeNodeType to "true".

thanks for your help!

Ramón

Edited by: Ramón Diegel on Jul 31, 2008 11:20 AM

Answers (0)