home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / Scripting / orgtree / OrgTreeNode.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  3.9 KB  |  165 lines

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