home *** CD-ROM | disk | FTP | other *** search
- -------------------------------------------------------
-
- COPYRIGHT:
- ----------
- Copyright (C) International Business Machines Corp., 1991,1995.
-
- DISCLAIMER OF WARRANTIES:
- -------------------------
- The following [enclosed] code is sample code created by IBM
- Corporation. This sample code is not part of any standard IBM product
- and is provided to you solely for the purpose of assisting you in the
- development of your applications. The code is provided "AS IS",
- without warranty of any kind. IBM shall not be liable for any damages
- arising out of your use of the sample code, even if they have been
- advised of the possibility of such damages.
-
- -------------------------------------------------------
- TREECNR.ZIP
-
- Using tree view within a container in the Visual Builder is not as easy as
- simply connecting a tree collection to the items attribute of a container.
- Until a simpler mechanism is supported, I have provided a sample of a
- technique that can make this work. Download and unzip treecnr.zip and then
- load treecnr.vbb into the visual builder. Bring up the Composition editor on
- the TreeCnr part and follow along the explanation below.
-
-
- Overview of the sample application
- ==================================
-
- This application is a tree view container that support the maintenance of an
- organization chart for a company. The container holds Person objects- a
- non-visual part that has three attributes: a persons 'name', 'phoneNumber',
- and their 'parentName'. The 'parentName' is what is used to determine the
- parent of a person in the tree.
-
- People can be added and deleted from the tree. A person is added with the
- boss of the selected person. If a person is deleted that has children under
- him, all the children will be deleted. Take a minute to run treecnr.exe and
- get familiar with the way that the application works.
-
-
- Explanation of the implementation
- =================================
-
- The storage mechanism for all the Person objects that get added to the
- container is an IVSequence. The order of the objects in the IVSequence must
- be maintained so that it matches the order of the objects in the tree view of
- the container. The sequence is attached to the 'items' attribute of the
- container so that when an object gets added or deleted from the sequence the
- corresponding container object gets added or deleted automatically in the
- container. After the object gets added to the container special code has been
- added to move it under the correct parent. Likewise, when an object is
- deleted, special code is needed to check if the object had any children and to
- also delete them. The addition and deleting code will be explained in more
- detail below.
-
- Note that since we are using a IVSequence to hold all the Person objects, the
- information about each objects parent must be kept as an attribute in the
- object itself- not in the collection. This example assumes that the following
- member functions are implemented to set and query this information:
-
- IString name() const; //returns the name of the object
- IString parentName() const; //returns the name of the parent object
- Person& setParentName(const IString& aBossName); //sets the name of the parent
-
- Addition of objects
- -------------------
-
- Addition of objects is done via a custom logic connection from the 'Add'
- pushbutton to the part itself. This code in the custom logic connection first
- checks to make sure that an object is selected and that you are not attempting
- to add an object twice. If either of these test fail, an exception is
- thrown.
-
- Next, a new person is created with the correct 'name' and 'parentName'. This
- is accomplished by simply calling the create() member function of the
- PersonFact that has been created on the freeform surface. Then, call
- addObjectInTreeView(...) which adds the newly created object to the sequence
- and fixes up the container's treeview. This member function is passed a
- pointer to the container, a pointer to the People collection, and a pointer to
- the new objects. The member function is implemented in treecnr.cpv. Edit
- this file and look at the comments for an explanation of how this member
- function works.
-
- Deletion of objects
- -------------------
-
- Deletion of objects is done via a event-to-member function connection between
- the 'buttonClickEvent' of the Delete button and the
- deleteObjectInTreeView(...) member function. This member function is
- implemented in treecnr.cpv. Edit the file and follow the commented code to
- see how this member function works. When following this code, remember, that
- deleting an object from the sequence will automatically cause the object to be
- deleted for the container.
-
-
- Summary
- =======
-
- That all there is to it, you can use this sample as a basis for constructing a
- tree view container with your own objects in it.
-
- George Decandio
- Visual Builder Development
- Internet: decandio @ raleigh.ibm.com
-