home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / Samples / ActiveXBeans / orgtree / OrgTreeNode.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  3.9 KB  |  167 lines

  1. /**
  2.  *
  3.  *  OrgTreeNode.java
  4.  *
  5.  *      This object represents one individual in the org tree.
  6.  *
  7.  *  (C) Copyright 1998 by Microsoft Corporation. All rights reserved.
  8.  * 
  9.  */
  10. import java.awt.*;                      // standard java
  11. import java.applet.*;
  12. import com.ms.ui.*;                     // microsoft afc
  13.  
  14. public class OrgTreeNode extends UITree
  15. {
  16.     transient private static Image   empImage = null;
  17.     transient private static Image   mgrImage = null;
  18.  
  19.     transient private String name;
  20.     transient private String manager;
  21.     transient private String title;
  22.     transient private int    row;
  23.  
  24.     public static void oneTimeInit( Applet host)
  25.     {
  26.         MediaTracker mt = new MediaTracker(host);            // track the images being loaded
  27.  
  28.         empImage = host.getImage(host.getCodeBase(), "employee.gif");
  29.         mt.addImage(empImage, 0);
  30.  
  31.         mgrImage = host.getImage(host.getCodeBase(), "manager.gif");
  32.         mt.addImage(mgrImage, 0);
  33.  
  34.         // wait for all the images to be loaded
  35.         try 
  36.         {
  37.             mt.waitForAll();
  38.         } 
  39.         catch (InterruptedException e) 
  40.         {
  41.             e.printStackTrace();
  42.         }
  43.  
  44.     }
  45.  
  46.     public OrgTreeNode(String empName, String empTitle, String empManager, int dbRow)
  47.     {
  48.         super( empImage, empName+" - "+empTitle );
  49.  
  50.         setSelectionMode(UITree.SINGLESELECT);
  51.  
  52.         name        = empName;
  53.         title       = empTitle;
  54.         manager     = empManager;
  55.         row         = dbRow;
  56.     }
  57.  
  58.     /**
  59.      *  Returns the name of this employee
  60.      */
  61.     public String getName()
  62.     {
  63.         return (name);
  64.     }
  65.  
  66.     /**
  67.      *  Returns the title of this employee
  68.      */
  69.     public String getTitle()
  70.     {
  71.         return (title);
  72.     }
  73.  
  74.     /**
  75.      *  Return the row of this employee
  76.      */
  77.     public int getRow()
  78.     {
  79.         return (row);
  80.     }
  81.  
  82.     /**
  83.      *  Returns the OrgTreeNode which is the manager
  84.      */
  85.     public OrgTreeNode getManagerNode()
  86.     {
  87.         if (getParent() instanceof OrgTreeNode)
  88.         {
  89.             return (OrgTreeNode)getParent();
  90.         } else
  91.         {
  92.             return null;
  93.         }
  94.     }
  95.  
  96.     /**
  97.      *  Returns the name of the employee's manager
  98.      */
  99.     public String getManagerName()
  100.     {
  101.         return manager;
  102.     }
  103.  
  104.     /**
  105.      * This sets the current tree node to be a manager tree node. i.e. it
  106.      * changes his image
  107.      *
  108.      * @param    boolean    is this guy a manager or not
  109.      */
  110.     public void setManager(boolean isManager)
  111.     {
  112.         if( isManager)
  113.         {
  114.             ((UIItem)getHeader()).setImage(mgrImage);
  115.         }
  116.         else
  117.         {
  118.             ((UIItem)getHeader()).setImage(empImage);
  119.         }
  120.     }
  121.  
  122.     /**
  123.      *  If this OrgTreeNode represents the specified node's manager,
  124.      *  this adds it to this OrgTreeNode, and returns true.
  125.      *  Otherwise, it returns false.
  126.      */
  127.     public boolean addTeamMember( OrgTreeNode otn )
  128.     {
  129.         int i,c;
  130.         boolean found = false;
  131.  
  132.         // if our name matches the manager of this node,
  133.         // add it to us
  134.         if (otn.getManagerName().equalsIgnoreCase( getName() ))
  135.         {
  136.             // add to us
  137.             add( otn );
  138.             
  139.             // we're now a manager
  140.             setManager(true);
  141.  
  142.             found = true;
  143.         } else
  144.         {
  145.             UIComponent cmp;
  146.  
  147.             // look for our team in the subordinates and add us to it if found
  148.             c = getComponentCount();
  149.  
  150.             // loop through all our components and put us in the proper team
  151.             for ( i = 0; i < c; i++ )
  152.             {
  153.                 cmp = (UIComponent) getComponent(i);
  154.  
  155.                 // if we find our team, we're done
  156.                 if ( (cmp instanceof OrgTreeNode) &&
  157.                      ((OrgTreeNode)(getComponent(i))).addTeamMember( otn ) )
  158.                 {
  159.                     found = true;
  160.                     break;
  161.                 }
  162.             }
  163.         }
  164.         return found;
  165.     }
  166. }
  167.