Want to have accurate filtered dropdown lists on your dialog boxes?
You have probably invested a large amount of time and effort in building
the taxonomy describing the relationships that exist within your company.
Using the CIS API you can use this established and accurate taxonomy to create
filtered drop down lists in your applications. This ensures that your application’s
drop down lists always have the correct values.
Querying the Taxonomy in Real-Time
For example, let us assume that the taxonomy contains the following hierarchy.
You can use the CIS API to walk the tree and populate dropdowns such that when
the user selects 'Tissue and Cell Preparation' from the first box they get
'Freeze Etching, Freeze Substitution, Sectioning and Staining', then when they
pick 'Staining' they get 'Horseradish Peroxidase, etc''
Tissue and Cell Preparation
Freeze Etching
Freeze Substitution
Sectioning
Staining
Horseradish Peroxidase
Immunocytochemistry
Ferritin Labeling
Immunoelectron Microscopy
Immunofluorescence Technique
Immunoperoxidase
Silver Impregnation
|
|
Like walking any hierarchical tree the following steps should be taken;
- Find the top-level nodes and use them to populate the top level drop-down list.
- When the user selects a value, find the children of that node and populate the next drop-down.
- If the user selects another value, go to Step 2 and repeat the process
Obviously doing this in real time would be inefficient so the values would probably
be cached locally, this code illustrates how to read in those values.
Retrieving top-level taxonomy nodes
This example shows how you can retrieve all of the top-level taxonomy nodes from the
system. This includes sorting all of the nodes by their label.
Note: oSession is a valid remote, lightweight, or heavyweight session object, as
described in Chapter 3 of the Initializing Business Intelligence Services available
from the Developer Program website.
oRdSvc = RdService.access(oSession);
TaxonomyNodeMgr oMgr = oRdSvc.newTaxonomyNodeMgr();
ITaxonomyNode oTaxNode = oMgr.newEntity();
oMgr.filterByParentNodeId(0);
oMgr.sortByLabel(false);
for (boolean fResult = oMgr.first(oTaxNode);
fResult;
fResult = oMgr.next(oTaxNode))
{
// Here you can, for example, populate your top level drop down list
System.out.println(oTaxNode.getLabel());
}
oMgr.flush();
oMgr.resetFilters();
Once you have the root node of a taxonomy (that is, one of the nodes you found using this
procedure), you can find that node’s subnodes by specifying the root node’s ID as the parent
ID when calling filterByParentNodeId().
Retrieving subnodes of a taxonomy node
The procedure for retrieving subnodes of a given node differs from the procedure to find
top-level taxonomy nodes in only one step. When you specify the parent node ID in the call
to filterByParentNodeId(), you specify the node for which you wish to find the subnodes,
instead of 0. This example shows how you can retrieve all of the subnodes for a given node.
This example assumes two valid objects already exist:
oRdSvc = RdService.access(oSession);
TaxonomyNodeMgr oMgr = oRdSvc.newTaxonomyNodeMgr();
ITaxonomyNode oTaxNode = oMgr.newEntity();
// Instead of 0, use the ID of the parent node
oMgr.filterByParentNodeId(oParentNode.getId());
oMgr.sortByLabel(false);
for(boolean fResult = oMgr.first(oTaxNode);
fResult;
fResult = oMgr.next(oTaxNode))
{
// Here you can, for example, populate a drop down list
System.out.println(oTaxNode.getLabel());
}
oMgr.flush();
oMgr.resetFilters();
|