00001 package cedar.jetweb.html; 00002 00003 import java.io.PrintWriter; 00004 import java.io.BufferedWriter; 00005 import java.io.IOException; 00006 00007 import java.util.Vector; 00008 import java.util.Enumeration; 00009 import java.util.Collections; 00010 import java.util.List; 00011 00012 import cedar.jetweb.*; 00013 import cedar.jetweb.model.*; 00014 00023 public class HTMLProcessWriter extends HTMLWriter { 00024 00025 private boolean submissible_ = false; 00026 00027 00037 public HTMLProcessWriter(PrintWriter out, String newServletPath ){ 00038 super(out,newServletPath); 00039 } 00040 00041 public HTMLProcessWriter(BufferedWriter out, String newServletPath ){ 00042 00043 super(out,newServletPath); 00044 00045 } 00046 00057 public HTMLProcessWriter(String filename, String newServletPath ){ 00058 super(filename,newServletPath); 00059 } 00060 00061 00065 public void display(MCProcessType proc) throws JetWebException { 00066 00067 Collision collision = proc.getCollision(); 00068 00069 try { 00070 00071 ofile.write("<div class='jetweb-processtype'>"); 00072 00073 if(submissible_){ 00074 ofile.write 00075 ("<input type='CHECKBOX'" + 00076 " name='SELECTEDPROCESSID' value='" + 00077 proc.getId()+"'>"); 00078 } 00079 00080 if (!verbose){ 00081 ofile.write("ID: "); 00082 ofile.write(Integer.toString(proc.getId())); 00083 ofile.newLine(); 00084 ofile.write(" "); 00085 ofile.write(proc.getMCProcessName()); 00086 ofile.write(" in "); 00087 display(collision); 00088 ofile.newLine(); 00089 openForm("POST", servletPath); 00090 ofile.write("<input type='hidden' name='PROCESSID' value='"+proc.getId()+"'>"); 00091 ofile.newLine(); 00092 if(forms_.equals(1)){ 00093 ofile.write 00094 (HTMLUtils.writeSubmitButton 00095 ("PROCESSTYPE", 00096 "More details on this process type.", 00097 "More")); 00098 } 00099 00100 closeForm(); 00101 } else { 00102 00103 if (modifiable) { 00104 openForm("POST", servletPath); 00105 ofile.newLine(); 00106 ofile.write("<input type='hidden' name='PROCESSID' value='"+proc.getId()+"'>"); 00107 } 00108 ofile.write("<table>"); 00109 ofile.newLine(); 00110 ofile.write("<tr>"); 00111 ofile.write("<td>"); 00112 ofile.write("ID: "); 00113 ofile.write(Integer.toString(proc.getId())); 00114 ofile.write("</td>"); 00115 00116 ofile.write("<td>"); 00117 ofile.write(" Name:"); 00118 if (modifiable) { 00119 ofile.write(HTMLUtils.writeInputBox("PROCNAME",proc.getMCProcessName())); 00120 } else { 00121 ofile.write(proc.getMCProcessName()); 00122 } 00123 ofile.write("</td>"); 00124 00125 ofile.write("<td>"); 00126 ofile.write(" Incoming beams: </td>"); 00127 ofile.write("<td>"); 00128 00129 if (modifiable) { 00130 00131 ofile.write("<select name='COLLISIONID'>"); 00132 try { 00133 ofile.write("<option value="+collision.getId()+">"); 00134 ofile.write(collision.toString()); 00135 ofile.write("</option>"); 00136 } catch (NullPointerException e) { 00137 ofile.write("<option value='undefined'>Undefined</option>"); 00138 } 00139 Vector<Collision> cList = Collision.getAll(); 00140 for (Collision c : cList){ 00141 ofile.write("<option value='"+c.getId()+"'>"); 00142 ofile.write(c.toString()); 00143 ofile.write("</option>"); 00144 } 00145 ofile.write("</select>"); 00146 00147 } else { 00148 if (collision != null) { 00149 boolean tmp = verbose; 00150 verbose = false; 00151 display(collision); 00152 verbose = tmp; 00153 } else { 00154 ofile.write("undefined"); 00155 } 00156 } 00157 00158 00159 ofile.write("</td>"); 00160 ofile.write("</tr>"); 00161 ofile.newLine(); 00162 00163 ofile.write("<tr>"); 00164 00165 ofile.write("<td>"); 00166 ofile.write(" "); 00167 ofile.write("</td>"); 00168 00169 ofile.write("<td>"); 00170 ofile.write("Can be generated alone?:"); 00171 if (modifiable) { 00172 ofile.write(HTMLUtils.writeInputBox("ISVALID",Boolean.toString(proc.isValid()))); 00173 } else { 00174 ofile.write(Boolean.toString(proc.isValid())); 00175 } 00176 ofile.write("</td>"); 00177 00178 ofile.write("<td>"); 00179 ofile.write("Is compatible with ID "); 00180 StringBuffer pList = new StringBuffer(); 00181 for (Integer id : proc.getCompatibleProcesses()){ 00182 pList.append(":"+id); 00183 } 00184 if (modifiable) { 00185 ofile.write(HTMLUtils.writeInputBox("PLIST",pList)); 00186 ofile.write(" Must give a list containing only colons and integers. "); 00187 } else { 00188 ofile.write(pList.toString()); 00189 } 00190 00191 ofile.write("</td>"); 00192 00193 00194 ofile.write("<td align='right'>"); 00195 openForm("POST", servletPath); 00196 00197 ofile.write("<input type='hidden' name='PROCESSID' value='"+proc.getId()+"'>"); 00198 ofile.write(HTMLUtils.writeSubmitButton("PAPER", 00199 "View measurements relevant for this process.", 00200 "Data")); 00201 closeForm(); 00202 00203 ofile.write("</td>"); 00204 00205 ofile.write("</tr>"); 00206 ofile.write("</table>"); 00207 } 00208 ofile.newLine(); 00209 00210 if (modifiable) { 00211 ofile.write("<p>"); 00212 ofile.write(HTMLUtils.writeSubmitButton("DELETEPROC", 00213 "Remove this MCProcessType from the database.", 00214 "Delete")); 00215 ofile.write("Warning: may invalidate entries in the runseries and cross_section_switches tables!</p>"); 00216 ofile.write("<p>"); 00217 ofile.write(HTMLUtils.writeSubmitButton("MODIFYPROC", 00218 "Modify this MCProcessType in the database.", 00219 "Modify")); 00220 ofile.write("Warning: may lead to errors in the runseries and cross_section_switches tables!</p>"); 00221 00222 closeForm(); 00223 } 00224 00225 ofile.write("</div>"); 00226 00227 ofile.newLine(); 00228 00229 } catch (Exception e) { 00230 throw new JetWebException(e,"problem with writing MCProcessType "+proc); 00231 } 00232 00233 00234 00235 } 00236 00237 public HTMLProcessWriter addNewProcess() 00238 throws JetWebException{ 00239 00240 MCProcessType emptyProc = new MCProcessType(); 00241 Collision collision = emptyProc.getCollision(); 00242 00243 if (!modifiable) {return this;} 00244 00245 try{ 00246 ofile.write("<BODY>"); 00247 ofile.write("Add a new process:"); 00248 ofile.write("</BODY>"); 00249 00250 if (!verbose) { 00251 String html = emptyProc.getMCProcessName()+" in "; 00252 ofile.write(html); 00253 if (collision != null) { 00254 ofile.write(collision.toString()); 00255 } else { 00256 ofile.write("undefined beams"); 00257 } 00258 }else{ 00259 ofile.write("<div class='jetweb-processtype'>"); 00260 00261 openForm("POST", servletPath); 00262 00263 ofile.write("<table>"); 00264 ofile.newLine(); 00265 ofile.write("<tr>"); 00266 ofile.write("<td>"); 00267 ofile.write("ID:"); 00268 ofile.write(HTMLUtils.writeInputBox("PROCESSID", " ")); 00269 ofile.write("</td>"); 00270 ofile.write("<td>"); 00271 ofile.write(" Name:"); 00272 ofile.write(HTMLUtils.writeInputBox("PROCNAME", 00273 " ")); 00274 00275 ofile.write("</td>"); 00276 00277 ofile.write("<td>"); 00278 ofile.write(" Incoming beams: "); 00279 00280 ofile.write("<select name='COLLISIONID'>"); 00281 try { 00282 ofile.write("<option value="+collision.getId()+">"); 00283 ofile.write(collision.toString()); 00284 ofile.write("</option>"); 00285 } catch (NullPointerException e) { 00286 ofile.write("<option value='undefined'>Undefined</option>"); 00287 } 00288 Vector<Collision> cList = Collision.getAll(); 00289 for (Collision c : cList){ 00290 ofile.write("<option value='"+c.getId()+"'>"); 00291 ofile.write(c.toString()); 00292 ofile.write("</option>"); 00293 } 00294 ofile.write("</select>"); 00295 00296 ofile.write("</td>"); 00297 ofile.write("</tr>"); 00298 00299 ofile.write("<tr>"); 00300 00301 ofile.write("<td>"); 00302 ofile.write(" "); 00303 ofile.write("</td>"); 00304 00305 ofile.write("<td>"); 00306 ofile.write("Can be generated alone?:"); 00307 if (modifiable) { 00308 ofile.write(HTMLUtils.writeInputBox("ISVALID",Boolean.toString(emptyProc.isValid()))); 00309 } else { 00310 ofile.write(Boolean.toString(emptyProc.isValid())); 00311 } 00312 ofile.write("</td>"); 00313 00314 ofile.write("<td>"); 00315 ofile.write("Is compatible with ID "); 00316 StringBuffer pList = new StringBuffer(); 00317 for (Integer id : emptyProc.getCompatibleProcesses()){ 00318 pList.append(":"+id); 00319 } 00320 ofile.write(HTMLUtils.writeInputBox("PLIST"," ")); 00321 ofile.write(" Must give a list containing only colons and integers. "); 00322 00323 ofile.write("</td>"); 00324 00325 ofile.write("</tr>"); 00326 ofile.write("</table>"); 00327 ofile.write(HTMLUtils.writeSubmitButton("MODIFYPROC", 00328 "Modify this MCProcessType in the database.", 00329 "Modify")); 00330 ofile.write("Warning: may disrupt existing processes that the new process is compatible with!"); 00331 00332 closeForm(); 00333 ofile.write("</div>"); 00334 } 00335 //write(emptyProc); 00336 ofile.write("<BODY>"); 00337 ofile.write("<HR>"); 00338 ofile.write("Modify existing Processes:"); 00339 ofile.write("</BODY>"); 00340 }catch(IOException err){ 00341 throw new JetWebException(err,"problem with writing MCProcessType"); 00342 } 00343 return this; 00344 } 00345 00349 public void display(Collision collision) throws JetWebException { 00350 00351 String html = 00352 collision.getParticle1().getEnergy()+" GeV " 00353 +collision.getParticle1().getName()+" - " 00354 +collision.getParticle2().getEnergy()+" GeV " 00355 +collision.getParticle2().getName() 00356 +" collisions."; 00357 try { 00358 ofile.write("<div class='jetweb-collision'>"); 00359 ofile.newLine(); 00360 if (verbose) { 00361 00362 openForm("POST", servletPath); 00363 ofile.newLine(); 00364 ofile.write(html); 00365 ofile.write("<input type='hidden' name='COLLISIONID' value='"+collision.getId()+"'>"); 00366 if(forms_.equals(1)){ 00367 ofile.write 00368 (HTMLUtils.writeSubmitButton 00369 ("PROCESSTYPE", 00370 "Display the known processes for these beams.", 00371 "Processes")); 00372 } 00373 ofile.newLine(); 00374 00375 ofile.write(HTMLUtils.writeSubmitButton("PAPER", 00376 "View known measurements for this collision.", 00377 "Data")); 00378 ofile.newLine(); 00379 closeForm(); 00380 ofile.newLine(); 00381 } else { 00382 openForm("POST", servletPath); 00383 ofile.write(html); 00384 ofile.newLine(); 00385 ofile.write("<input type='hidden' name='COLLISIONID' value='"+collision.getId()+"'>"); 00386 ofile.newLine(); 00387 if(forms_.equals(1)){ 00388 ofile.write 00389 (HTMLUtils.writeSubmitButton 00390 ("COLLISION", 00391 "More details on this collision type.", 00392 "More")); 00393 } 00394 ofile.newLine(); 00395 closeForm(); 00396 } 00397 ofile.write("</div>"); 00398 ofile.newLine(); 00399 00400 } catch (IOException e) { 00401 throw new JetWebException(e); 00402 } 00403 } 00404 00408 public void writeMCProcessSelector(String modelIdString) throws JetWebException { 00409 00410 try { 00411 00412 Vector<MCProcessType> procs = MCProcessType.getAll(true); 00413 00414 if (modelIdString !=null){ 00415 ofile.write("<input type='hidden' name='MODELID' value='"+modelIdString+"'>"); 00416 ofile.write(HTMLUtils.writeSubmitButton("MOREDATA", 00417 "Submit the request", 00418 "Submit")); 00419 } 00420 00421 submissible_ = true; 00422 00423 for (MCProcessType proc : procs ) { 00424 00425 00426 00427 //ofile.write("<div align='left'>"); 00428 // ofile.write("<input type='CHECKBOX' name='SELECTEDPROCESSID' value='" 00429 // +proc.getId()+"'>"); 00430 display(proc); 00431 // ofile.write("</div>"); 00432 ofile.newLine(); 00433 00434 } 00435 00436 submissible_ = false; 00437 00438 } catch (IOException i) { 00439 throw new JetWebException(i); 00440 } 00441 } 00442 00443 00447 public void display(Object object) throws JetWebException { 00448 00449 if (object instanceof MCProcessType){ 00450 display((MCProcessType)object); 00451 } else if (object instanceof Collision){ 00452 display((Collision)object); 00453 } else { 00454 throw new JetWebException("Attempt to display "+object,"Using "+this); 00455 } 00456 } 00457 }
Generated Wed Jan 17 09:14:27 GMT 2007