Aady
11-22-2006, 03:15 AM
I am working on a design that involes two views.
Each view needs to display data in tree format. The data is fetched from two different xml files, one for each tree.
When the application loads, only the first view should be visible showing the first tree. The second view must be empty/invisible.
When the user clicks on a node of the first tree, then only second tree should be displayed in the second view. The data represented by second tree is dependant on the value of the node on the first tree, clicked by the user.
Each time the user selects a node in the first view, the second tree must get refreshed and a tree with new data should be drawn, satisfying the user selection in the first tree.
In the following example, I have used two data files.
1. FirstTree - contains the names of a number animals and birds.
2. SecondTree - contains the name of favorite food of those animals and birds.
If I click "Elephant" in the first tree, Second Tree data must be read from the "Foods" file, and a tree with two nodes "Coconut" and "Cake" must be displayed in the second view.
FirstTree.xml
<zoo>
<Group name="Animals" isopen="true">
<species name="Tiger" isleaf="true" />
<species name="Cow" isleaf="true" />
<species name="Rabbit" isleaf="true" />
<species name="Elephant" isleaf="true" />
</Group>
<Group name="Birds" isopen="true">
<species name="Parrot" isleaf="true" />
<species name="Peacock" isleaf="true" />
<species name="Cocoo" isleaf="true" />
</Group>
</zoo>
SecondTree.xml
<Foods>
<food name="Carrot" isleaf="true" selectionName="Tiger"/>
<food name="Cabbage" isleaf="true" selectionName="Cow"/>
<food name="Deer" isleaf="true" selectionName="Rabbit"/>
<food name="Coconut" isleaf="true" selectionName="Elephant" />
<food name="Cauliflower" isleaf="true" selectionName="Parrot" />
<food name="Potato" isleaf="true" selectionName="Peacock" />
<food name="Tomato" isleaf="true" selectionName="Cocoo" />
<food name="Pizza" isleaf="true" selectionName="Tiger" />
<food name="Noodles" isleaf="true" selectionName="Cow" />
<food name="Rice" isleaf="true" selectionName="Rabbit" />
<food name="Cake" isleaf="true" selectionName="Elephant" />
<food name="Chocolate" isleaf="true" selectionName="Parrot" />
<food name="Nuts" isleaf="true" selectionName="Peacock" />
</Foods>
I plan to use XPath expression to achieve this. I have not succeeded in completing this.
If I use the following code with XPath expression, with hard-coded value "Elephant", the second tree will show the right data:
<dataset name="dset_zoo" src="/FirstTree.xml"/>
<dataset name="dset_food" src="/SecondTree.xml"/>
<view y="80" width="200" height="200" >
<tree datapath="dset_food:/" icon="null" showroot="false">
<tree id="ctree2" datapath="Foods[@selectionName='Elephant']" icon="null" text="$path{'@name'}" isleaf="$path{'@isleaf'}"/> </tree>
</view>
How can I make it dynamic ?
The first tree selection could be captured through "onactivate" method of the tree
<method event="onactivate">
if (this.isleaf) {
var selectedSpecies = this.datapath.xpathQuery('@name');
if (selectedSpecies!= null) {
Debug.write('Selection: ' + selectedSpecies);
}
}
</method>
How can I pass this selection as a variable to the second tree Expression, before the second tree is being loaded?
Any help is appreciated.
Each view needs to display data in tree format. The data is fetched from two different xml files, one for each tree.
When the application loads, only the first view should be visible showing the first tree. The second view must be empty/invisible.
When the user clicks on a node of the first tree, then only second tree should be displayed in the second view. The data represented by second tree is dependant on the value of the node on the first tree, clicked by the user.
Each time the user selects a node in the first view, the second tree must get refreshed and a tree with new data should be drawn, satisfying the user selection in the first tree.
In the following example, I have used two data files.
1. FirstTree - contains the names of a number animals and birds.
2. SecondTree - contains the name of favorite food of those animals and birds.
If I click "Elephant" in the first tree, Second Tree data must be read from the "Foods" file, and a tree with two nodes "Coconut" and "Cake" must be displayed in the second view.
FirstTree.xml
<zoo>
<Group name="Animals" isopen="true">
<species name="Tiger" isleaf="true" />
<species name="Cow" isleaf="true" />
<species name="Rabbit" isleaf="true" />
<species name="Elephant" isleaf="true" />
</Group>
<Group name="Birds" isopen="true">
<species name="Parrot" isleaf="true" />
<species name="Peacock" isleaf="true" />
<species name="Cocoo" isleaf="true" />
</Group>
</zoo>
SecondTree.xml
<Foods>
<food name="Carrot" isleaf="true" selectionName="Tiger"/>
<food name="Cabbage" isleaf="true" selectionName="Cow"/>
<food name="Deer" isleaf="true" selectionName="Rabbit"/>
<food name="Coconut" isleaf="true" selectionName="Elephant" />
<food name="Cauliflower" isleaf="true" selectionName="Parrot" />
<food name="Potato" isleaf="true" selectionName="Peacock" />
<food name="Tomato" isleaf="true" selectionName="Cocoo" />
<food name="Pizza" isleaf="true" selectionName="Tiger" />
<food name="Noodles" isleaf="true" selectionName="Cow" />
<food name="Rice" isleaf="true" selectionName="Rabbit" />
<food name="Cake" isleaf="true" selectionName="Elephant" />
<food name="Chocolate" isleaf="true" selectionName="Parrot" />
<food name="Nuts" isleaf="true" selectionName="Peacock" />
</Foods>
I plan to use XPath expression to achieve this. I have not succeeded in completing this.
If I use the following code with XPath expression, with hard-coded value "Elephant", the second tree will show the right data:
<dataset name="dset_zoo" src="/FirstTree.xml"/>
<dataset name="dset_food" src="/SecondTree.xml"/>
<view y="80" width="200" height="200" >
<tree datapath="dset_food:/" icon="null" showroot="false">
<tree id="ctree2" datapath="Foods[@selectionName='Elephant']" icon="null" text="$path{'@name'}" isleaf="$path{'@isleaf'}"/> </tree>
</view>
How can I make it dynamic ?
The first tree selection could be captured through "onactivate" method of the tree
<method event="onactivate">
if (this.isleaf) {
var selectedSpecies = this.datapath.xpathQuery('@name');
if (selectedSpecies!= null) {
Debug.write('Selection: ' + selectedSpecies);
}
}
</method>
How can I pass this selection as a variable to the second tree Expression, before the second tree is being loaded?
Any help is appreciated.