00001 import java.util.Vector; 00002 00003 public class DiagnosisList extends Widget 00004 { 00005 ActionButton action; 00006 DiagnosisEditor editor; 00007 Vector diagnoses = new Vector(); 00008 int active; 00009 00010 public static final int ADD = 1; 00011 public static final int EDIT = 2; 00012 public static final int DELETE = 3; 00013 00014 public DiagnosisList(String prefix, Form form) 00015 { 00016 super(prefix, form); 00017 action = new ActionButton(n("action"), form); 00018 addChild(action); 00019 } 00020 00021 public void loadValues() 00022 { 00023 super.loadValues(); 00024 00025 modal = loadAttribute("modal") != null; 00026 00027 String l = loadAttribute("list"); 00028 if (l != null) diagnoses = (Vector) unserialize(l); 00029 00030 String a = loadAttribute("active"); 00031 00032 for(;;) 00033 if (modal) 00034 { 00035 if (a != null) active = toInt(a, -1); 00036 editor = new DiagnosisEditor(active, diagnoses, n("editor"), form); 00037 if (a == null) editor.loadDefaults(); else editor.loadValues(); 00038 00039 if (editor.done) 00040 modal = false; 00041 else if (editor.more) 00042 { 00043 a = null; 00044 active = -1; 00045 } 00046 else 00047 return; 00048 } 00049 else 00050 { 00051 switch (action.action) 00052 { 00053 case ADD: 00054 modal = true; 00055 active = -1; 00056 break; 00057 case EDIT: 00058 modal = true; 00059 active = action.param; 00060 break; 00061 case DELETE: 00062 diagnoses.remove(action.param); 00063 return; 00064 default: 00065 return; 00066 } 00067 } 00068 } 00069 00070 public void display(boolean hidden) 00071 { 00072 printAttribute("list", serialize(diagnoses)); 00073 00074 if (modal) 00075 { 00076 printAttribute("modal", "1"); 00077 printAttribute("active", Integer.toString(active)); 00078 editor.display(hidden); 00079 return; 00080 } 00081 else if (hidden) 00082 return; 00083 00084 if (diagnoses.size() <= 0) 00085 { 00086 action.display("Add a diagnosis...", ADD); 00087 } 00088 else 00089 { 00090 action.display("Add another diagnosis...", ADD); 00091 p("<br>\n<table>\n"); 00092 int l = diagnoses.size(); 00093 for(int i = 0; i < l; ++i) 00094 { 00095 Diagnosis d = (Diagnosis) diagnoses.get(i); 00096 p( 00097 "\n"+ 00098 "<tr>\n"+ 00099 " <td>\n"+ 00100 " <table border=1 RULES=NONE FRAME=BOX>\n"+ 00101 " <tr><td colspan=2><strong>" + d.name + "</strong></td></tr>\n"+ 00102 " <tr>\n"+ 00103 " <td valign=top><i>Description:</i></td>\n"+ 00104 " <td>" + d.description + "</td> \n"+ 00105 " </tr>\n"+ 00106 " </table>\n"+ 00107 " </td>\n"+ 00108 " <td>\n"+ 00109 " "); 00110 action.display("Edit...", EDIT, i); p(" "); 00111 action.display("Delete", DELETE, i); p("\n"+ 00112 " </td>\n"+ 00113 "</tr>\n"+ 00114 ""); 00115 } 00116 p("</table>\n"); 00117 } 00118 } 00119 };