Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ReferralList.java

Go to the documentation of this file.
00001 import java.util.Vector;
00002 import java.sql.SQLException;
00003 
00004 public class ReferralList extends Widget
00005 { 
00006         ActionButton action;
00007         ReferralEditor editor;
00008         Vector referrals = new Vector();
00009         int active;
00010         
00011         public static final int ADD = 1;
00012         public static final int EDIT = 2;
00013         public static final int DELETE = 3;
00014         
00015         public ReferralList(String prefix, Form form)
00016         {
00017     super(prefix, form); 
00018     action = new ActionButton(n("action"), form);
00019     addChild(action);
00020         }
00021         
00022         public void loadValues()
00023         {
00024     super.loadValues();
00025     
00026     modal = loadAttribute("modal") != null;
00027     
00028     String l = loadAttribute("referrals");
00029     if (l != null) referrals = (Vector) unserialize(l);
00030     
00031     String a = loadAttribute("active");    
00032     
00033     for(;;)
00034     if (modal)
00035     {
00036       if (a != null) active = toInt(a, -1);      
00037       editor = new ReferralEditor(active, referrals, n("editor"), form);
00038       if (a == null) editor.loadDefaults(); else editor.loadValues();        
00039       
00040       if (editor.done)
00041         modal = false;
00042       else if (editor.more)
00043       {
00044         a = null;
00045         active = -1;
00046       }
00047       else
00048          return;
00049     }   
00050     else
00051     {   
00052       switch (action.action)
00053       {
00054         case ADD:
00055           modal = true;
00056           active = -1;
00057         break;
00058         case EDIT:
00059           modal = true;
00060           active = action.param;
00061         break;
00062         case DELETE:
00063           referrals.remove(action.param);
00064           return;
00065         default:
00066           return;
00067       }
00068     }
00069         }
00070                 
00071         public void display(boolean hidden)
00072         {
00073     printAttribute("referrals", serialize(referrals));
00074 
00075     if (modal)
00076     {
00077       printAttribute("modal", "1");
00078       printAttribute("active", Integer.toString(active));
00079       editor.display(hidden);
00080       return;
00081     }
00082     else if (hidden)
00083       return;
00084     
00085     if (referrals.size() <= 0)
00086     {
00087       action.display("Add a referral...", ADD);
00088     }
00089     else
00090     {
00091       action.display("Add another referral...", ADD);
00092       p("<br>\n<table>\n");
00093       int l = referrals.size();
00094       
00095       Query q = new Query(form.connectDb(), form.pw);
00096       try
00097       {
00098         for(int i = 0; i < l; ++i)
00099         {
00100           Referral r = (Referral) referrals.get(i);
00101           
00102           q.query("\n"+
00103 "            SELECT d.name, p.name\n"+
00104 "            FROM doctors AS d\n"+
00105 "            INNER JOIN practices AS p USING (practice_id)\n"+
00106 "            WHERE d.doctor_ID = " + r.doctor_id
00107           );
00108           
00109           if (q.r == null) continue;
00110           
00111           String doctor = "unknown";
00112           String practice = "unknown";
00113           if (q.r.next() && q.r.isLast())
00114           {
00115             doctor = q.r.getString(1);
00116             practice = q.r.getString(2);
00117           }
00118 
00119           p(
00120 "\n"+
00121 "<tr>\n"+
00122 "  <td>\n"+
00123 "    <table border=1 RULES=NONE FRAME=BOX>\n"+
00124 "    <tr><td colspan=2><strong>Referral " + (r.incoming ? "From" : "To") + "</strong></td></tr>\n"+
00125 "    <tr>\n"+
00126 "      <td valign=top><i>Doctor:</i></td>\n"+
00127 "      <td>" + doctor + "</td>  \n"+
00128 "    </tr>\n"+
00129 "    <tr>\n"+
00130 "      <td valign=top><i>Practice:</i></td>\n"+
00131 "      <td>" + practice + "</td>  \n"+
00132 "    </tr>    \n"+
00133 "    </table>\n"+
00134 "  </td>\n"+
00135 "  <td>\n"+
00136 "  "); 
00137     action.display("Edit...", EDIT, i); p(" ");
00138     action.display("Delete", DELETE, i); p("\n"+
00139 "  </td>\n"+
00140 "</tr>\n"+
00141 "");
00142         } // for
00143       } // try
00144       catch (SQLException e)
00145       {
00146         p(e);
00147       }
00148       finally
00149       {
00150         q.close();
00151       }
00152       p("</table>\n");     
00153     }
00154         }
00155 };

Generated on Mon Mar 6 23:34:34 2006 by  doxygen 1.4.4