21.08.2015 Views

Pro

February 1996 - JeffLuther.net

February 1996 - JeffLuther.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Pro</strong>G u p t aGet Connected with HierarchiesMichael CunninghamIn this article, we’re going tocreate a list box class that, afterinitialization, is capable ofpopulating and displaying the datain a hierarchical tree. I’ll need toderive a new class fromcOutlineListBox and add thefunctionality specific to handlinghierarchical data. I’ll call the newclass cOutlineConnectBy (hereafterreferred to as OCB) and the examplesthroughout the article will refer to data in anorganization chart (org chart). I’ll display the org chartdata graphically in the list box. (See Figure 1.) The sourcecode for this class, available through the services listedon Page 2, can be dropped into your applications forimmediate productivity improvements.The SQLWindows Visual Toolchest’s list box classcOutlineListBox, and an Oracle SQL extension commonlyreferred to as the “CONNECT BY,” are particularly wellsuited for working with hierarchical trees such as afamily tree or an organizational chart. ThecOutlineListBox is a list box class that providesfunctionality similar to that of the list boxes in Windows’File Manager. The CONNECT BY is a clause added to aSELECT statement to make querying hierarchical dataFigure 1. The creation of this organization chartdemonstrates how to use cOutlineConnectBy inworking with hierarchical data.Many sets of data in the real world areorganized into hierarchies: companyorganization charts, bills ofmaterial, family trees, and others. TheVisual Toolchest offers a way toportray such data graphically inSQLWindows application. But what’sthe best way to store such data indatabases and load it into treestructuredlist boxes? The authorpresents an effective answer for Oracledatabases, with general interestto all SQLWindows developers.simple. Like most other databases,standard ANSI SQL doesn’t supportCONNECT BY for queryinghierarchical data.What’s in a tree?A hierarchical tree is a directed graphmade up of nodes. In my examplesI’ll discuss an org chart in which eachnode in the tree represents anemployee. The top node in the tree iscalled the root node, and the nodesconnected to the root are called childnodes (making the root a parentnode). The nodes without childrenare leaf nodes (an employee with no subordinates). In theremainder of this article, we’ll use the family tree analogyof grandparent, parent, sibling, and child.The outline list boxYou should know a few things about outline list boxesbefore managing the items in the list. The outline list boxclass displays a hierarchical tree and therefore needs away to manage each node in the tree (or item in the listbox). Each item in the outline list box has a set ofproperties you use to manage your hierarchy. The ones tobe concerned with are: Item Handle, Item Text, ParentHandle, and Item Value.The Item Handle is a unique identifier given to eachitem (node) in the list box. The Item Handle is to items inthe outline list box as indexes are to items in a standardlist box. The difference is this: Because the Item Handle isactually a direct pointer to a node in the tree, it alwaysremains the same. For example, the outline list boxsupports Drag and Drop to enable a user to move itemsaround in the tree’s hierarchy. If a user were to drag a listbox item and move it up in the list, it would have adifferent index than it did previously, but the Item Handlewould remain the same.Since all nodes in hierarchical trees are connected (theconnections are called edges), each node needs to knowwhich existing node to attach itself to when added to thetree. In other words, it needs to know the Item Handle ofits parent. The Visual Toolchest refers to this as the ParentItem Handle and uses it as a parameter to the functionthat adds the item to the list. This is how all the items get12 Gupta <strong>Pro</strong> PREMIER ISSUE

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!