home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / treecnr.zip / readme < prev    next >
Text File  |  1996-04-23  |  5KB  |  107 lines

  1. -------------------------------------------------------
  2.  
  3. COPYRIGHT:
  4. ----------
  5. Copyright (C) International Business Machines Corp., 1991,1995.
  6.  
  7. DISCLAIMER OF WARRANTIES:
  8. -------------------------
  9. The following [enclosed] code is sample code created by IBM
  10. Corporation.  This sample code is not part of any standard IBM product
  11. and is provided to you solely for the purpose of assisting you in the
  12. development of your applications.  The code is provided "AS IS",
  13. without warranty of any kind.  IBM shall not be liable for any damages
  14. arising out of your use of the sample code, even if they have been
  15. advised of the possibility of such damages.
  16.  
  17. -------------------------------------------------------
  18.  TREECNR.ZIP
  19.  
  20. Using tree view within a container in the Visual Builder is not as easy as
  21. simply connecting a tree collection to the items attribute of a container.
  22. Until a simpler mechanism is supported, I have provided a sample of a
  23. technique that can make this work.  Download and unzip treecnr.zip and then
  24. load treecnr.vbb into the visual builder.  Bring up the Composition editor on
  25. the TreeCnr part and follow along the explanation below.
  26.  
  27.  
  28. Overview of the sample application
  29. ==================================
  30.  
  31. This application is a tree view container that support the maintenance of an
  32. organization chart for a company.  The container holds Person objects- a
  33. non-visual part that has three attributes: a persons 'name', 'phoneNumber',
  34. and their 'parentName'.  The 'parentName' is what is used to determine the
  35. parent of a person in the tree.
  36.  
  37. People can be added and deleted from the tree.  A person is added with the
  38. boss of the selected person.  If a person is deleted that has children under
  39. him, all the children will be deleted.  Take a minute to run treecnr.exe and
  40. get familiar with the way that the application works.
  41.  
  42.  
  43. Explanation of the implementation
  44. =================================
  45.  
  46. The storage mechanism for all the Person objects that get added to the
  47. container is an IVSequence.  The order of the objects in the IVSequence must
  48. be maintained so that it matches the order of the objects in the tree view of
  49. the container.  The sequence is attached to the 'items' attribute of the
  50. container so that when an object gets added or deleted from the sequence the
  51. corresponding container object gets added or deleted automatically in the
  52. container.  After the object gets added to the container special code has been
  53. added to move it under the correct parent.  Likewise, when an object is
  54. deleted, special code is needed to check if the object had any children and to
  55. also delete them.  The addition and deleting code will be explained in more
  56. detail below.
  57.  
  58. Note that since we are using a IVSequence to hold all the Person objects, the
  59. information about each objects parent must be kept as an attribute in the
  60. object itself- not in the collection.  This example assumes that the following
  61. member functions are implemented to set and query this information:
  62.  
  63.   IString name() const;   //returns the name of the object
  64.   IString parentName() const;  //returns the name of the parent object
  65. Person& setParentName(const IString& aBossName); //sets the name of the parent
  66.  
  67. Addition of objects
  68. -------------------
  69.  
  70. Addition of objects is done via a custom logic connection from the 'Add'
  71. pushbutton to the part itself.  This code in the custom logic connection first
  72. checks to make sure that an object is selected and that you are not attempting
  73. to add an object twice.  If either of these test fail, an exception is
  74. thrown.
  75.  
  76. Next, a new person is created with the correct 'name' and 'parentName'.  This
  77. is accomplished by simply calling the create() member function of the
  78. PersonFact that has been created on the freeform surface.  Then, call
  79. addObjectInTreeView(...) which adds the newly created object to the sequence
  80. and fixes up the container's treeview.  This member function is passed a
  81. pointer to the container, a pointer to the People collection, and a pointer to
  82. the new objects.  The member function is implemented in treecnr.cpv.  Edit
  83. this file and look at the comments for an explanation of how this member
  84. function works.
  85.  
  86. Deletion of objects
  87. -------------------
  88.  
  89. Deletion of objects is done via a event-to-member function connection between
  90. the 'buttonClickEvent' of the Delete button and the
  91. deleteObjectInTreeView(...) member function.  This member function is
  92. implemented in treecnr.cpv.  Edit the file and follow the commented code to
  93. see how this member function works.  When following this code, remember, that
  94. deleting an object from the sequence will automatically cause the object to be
  95. deleted for the container.
  96.  
  97.  
  98. Summary
  99. =======
  100.  
  101. That all there is to it, you can use this sample as a basis for constructing a
  102. tree view container with your own objects in it.
  103.  
  104.  George Decandio
  105.  Visual Builder Development
  106.  Internet: decandio @ raleigh.ibm.com
  107.