cancel
Showing results for 
Search instead for 
Did you mean: 

Show two trees with same context structure

Former Member
0 Kudos

Hi,

I'm having problems showing two trees using the same context structure but different data simultaneously.

Here is my context structure:

tree (value node)

- expanded (boolean)

- label (string)

- leaf (boolean)

- recursion (recursion node with ref on tree)

I fill the first two layers of this tree in wdDoInit, the rest is loaded dynamically triggered by the onLoadChildren event.

This setting works fine for one tree. But I have the requirement to set up a second tree using the context structure of the first tree with different data. The problem is both should be shown simultaneously.

What I expected to work is:

1. to wrap the above mentioned structure into a container

2. make the tree a prototype (singleton=false) and

3. instantiate two tree nodes

4. fill both nodes with data

5. bind each with its corresponding ui elements manually

So the "shared" context structure would be:

treeContainer (value node)

- tree (value node, singleton=false)

-- expanded (boolean)

-- label (string)

-- leaf (boolean)

-- recursion (recursion node with ref on tree)

My data mapping code begins with these lines

ITreeContainerElement treeContainerElement =
treeContainerNode.createTreeContainerElement();
treeContainerNode.addElement(treeContainerElement);
ITreeNode treeFactory = wdContext.nodeTree();

which is then called one time for each tree. What happens is that both trees show the aggregated data, so each tree shows the data for both trees. When I use the factory of the element instead

ITreeContainerElement treeContainerElement =
treeContainerNode.createTreeContainerElement();
treeContainerNode.addElement(treeContainerElement);
ITreeNode treeFactory = treeContainerElement.nodeTree();

both trees show the data for the first tree.

I am aware that when I copy the context tree to a different location and rename every value node, e.h. tree2, recursion2 that this will work. But the problem is that the two trees will interact together, e.g. copy branches, and I want to use the typed API since the tree will get quite complex and they have absolutely the same structure.

I guess I'm getting sth. terribly wrong here with my understanding of the context, so any help is appreciated.

Best regards,

Fabian

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

It seems to be that my understanding of the context was terribly wrong. After I traced the behaviour in the debugger I realized that I made one important fault. The datasource of the UI elements should have been bound to the first and second instance of the recursion node container. Therefore the parent node should not be singleton since I access two instances simultaneously.

However, I now separated both trees in the context for the sake of maintainability. I work now with the generic API In order to reuse the functionality.

To determine the correct container I introduced the convention that the tree value node should only contain the recursion node. Then I use the following code to determine the right container:

	private IWDNode getContainer(IWDNodeElement parentElement) {
		IWDNode parentContainer = parentElement.node();
		IWDNodeInfo parentContainerInfo = parentContainer.getNodeInfo();
		boolean isRecursive = parentContainerInfo.isRecursive();

		String childName = null;
		if (isRecursive)
			childName = parentContainerInfo.getName();
		else {
			IWDNodeInfo recursiveNodeInfo =
				(IWDNodeInfo) parentContainer
					.getNodeInfo()
					.iterateChildren()
					.next();
			childName = recursiveNodeInfo.getName();
		}
		return parentContainer.getChildNode(childName, parentElement.index());
	}

I'm sorry if my question was somehow imprecise and lead into the wrong direction. With the code now working I reckon the question as answered and give you both points for good answers!

Best regards,

Fabian

Former Member
0 Kudos

Hello Fabian,

you say you have different data, but the same structure.

the tree will get quite complex and they have absolutely the same structure

Your solution is to have copies of the data attributes in the tree.

tree (value node)

- expanded_left (boolean)

- expanded_right (boolean)

- some_real_data_left

- some_real_data_right

- label (string) (could be the same?)

- leaf (boolean) (could be the same as well)

- recursion

In your layout you bind the left tree to the left data and vice versa.

I hope I got your question right.

Viele Grüße

Matthias

Former Member
0 Kudos

Hello Fabian,

one more thing:

If i missunderstood you and you have a different structure in the tree but the same structure in the context then you might try to use the visibility attribute. I'm not sure, but maybe it is per element and not per tree...

Kind regards,

Matthias

Former Member
0 Kudos

I think what you want to do is not possible. You can of course populate your context structure with a "forest" instead of tree but unfortunately you cannot bind different Tree UI elements to the forest such that they display the different roots.

To solve the problem you have to duplicate the context structure. You can use the same attribute names however (only node names must be unique per context) and use the methods from WDCopyService for copying the node elements.

Armin