1 7 8 package projectmanagement.presentation.worksheets; 9 10 import projectmanagement.spec.employee.*; 11 import projectmanagement.spec.project.*; 12 import projectmanagement.presentation.*; 13 14 import org.w3c.dom.*; 15 import org.w3c.dom.html.*; 16 17 import com.lutris.appserver.server.httpPresentation.HttpPresentation; 19 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 20 import com.lutris.appserver.server.httpPresentation.HttpPresentationException; 21 import org.enhydra.xml.xmlc.XMLObject; 22 23 import java.io.IOException ; 25 import java.util.Calendar ; 26 27 30 public class Controls extends BasePO { 31 32 35 private static String EMPLOYEE = "employee"; 36 private static String PROJECT = "project"; 37 private static String YEAR = "year"; 38 private static String MONTH = "month"; 39 40 private static String IS_PERSONAL = "isPersonal"; 41 42 45 protected int getRequiredAuthLevel() { 46 String isPersonal=""; 47 try { 48 isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 49 } catch (Exception ex) {} 50 51 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 52 return 1; 53 } else { 54 return 2; 55 } 56 } 57 58 61 public XMLObject handleDefault() 62 throws HttpPresentationException { 63 64 ControlsHTML page=new ControlsHTML(); 65 66 String employee = this.getComms().request.getParameter(EMPLOYEE); 67 HTMLSelectElement sel=page.getElementCboEmployee(); 68 fillEmployeeSelection(page,sel,employee); 69 70 String project = this.getComms().request.getParameter(PROJECT); 71 sel=page.getElementCboProject(); 72 fillProjectSelection(page,sel,project); 73 74 String year = this.getComms().request.getParameter(YEAR); 75 String month = this.getComms().request.getParameter(MONTH); 76 77 if (year==null) { 78 year=String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); 79 } 80 HTMLInputElement txtYear=page.getElementTxtYear(); 81 txtYear.setValue(year); 82 83 if (month==null) { 84 month=String.valueOf(Calendar.getInstance().get(Calendar.MONTH)+1); 85 } 86 fillMonths(page,month); 87 88 String isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 89 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 90 page.getElementIsPersonal().setValue("true"); 91 } 92 93 return page; 94 } 95 96 private void fillEmployeeSelection (ControlsHTML page,HTMLSelectElement cboEmployees, 97 String selectedEmployeeID) throws ProjectManagementPresentationException { 98 HTMLOptionElement optEmployee = page.getElementOptEmployee(); 99 100 String isPersonal=""; 101 try { 102 isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 103 } catch (Exception ex) {} 104 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 105 try { 106 selectedEmployeeID=getUser().getHandle(); 107 } catch (Exception ex) {} 108 } 109 110 try { 111 EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl"); 112 Employee[] employees=employeeManager.getAllEmployees(); 113 114 optEmployee.removeChild(optEmployee.getFirstChild()); 116 117 118 119 HTMLOptionElement clonedOption=null; 121 Node optionTextNode=null; 122 if (isPersonal==null || !isPersonal.equalsIgnoreCase("true")) { 123 clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true); 124 clonedOption.setValue(""); 125 String all="All"; 126 optionTextNode = clonedOption.getOwnerDocument(). 127 createTextNode(all); 128 clonedOption.appendChild(optionTextNode); 129 clonedOption.setAttribute("selected","selected"); 130 cboEmployees.appendChild(clonedOption); 133 } 134 135 137 138 if (employees!=null) { 139 for (int i=0; i<employees.length; i++) { 140 Employee e=employees[i]; 141 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true") && 143 !e.getHandle().equals(selectedEmployeeID)) { 144 continue; 145 } 146 147 clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true); 155 clonedOption.setValue(e.getHandle()); 156 optionTextNode = clonedOption.getOwnerDocument(). 157 createTextNode(e.getFirstName()+" "+e.getLastName()); 158 clonedOption.appendChild(optionTextNode); 159 if (selectedEmployeeID!=null && e.getHandle().equals(selectedEmployeeID)) { 160 clonedOption.setAttribute("selected","selected"); 161 } 162 cboEmployees.appendChild(clonedOption); 165 } 166 } 167 cboEmployees.removeChild(optEmployee); 168 } catch(NullPointerException ex) { 169 } catch (Exception ex) { 170 this.writeDebugMsg("Error populating list of employees: " + ex); 171 throw new ProjectManagementPresentationException("Error populating employee list: ", ex); 172 } 173 174 175 } 176 177 private void fillProjectSelection (ControlsHTML page,HTMLSelectElement cboProjects, 178 String selectedProjectID) throws ProjectManagementPresentationException { 179 HTMLOptionElement optProject = page.getElementOptProject(); 180 optProject.removeChild(optProject.getFirstChild()); 182 183 String isPersonal=""; 184 try { 185 isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 186 } catch (Exception ex) {} 187 188 try { 189 190 HTMLOptionElement clonedOption = (HTMLOptionElement)optProject.cloneNode(true); 192 clonedOption.setValue(""); 193 String all="All"; 194 Node optionTextNode = clonedOption.getOwnerDocument(). 195 createTextNode(all); 196 clonedOption.appendChild(optionTextNode); 197 clonedOption.setAttribute("selected","selected"); 198 cboProjects.appendChild(clonedOption); 201 202 Project[] projects=null; 204 ProjectManager projectManager = ProjectManagerFactory.getProjectManager("projectmanagement.business.project.ProjectManagerImpl"); 205 206 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 207 projects=projectManager.getAllProjects(); 209 210 } else { 211 projects=projectManager.getAllProjects(); 212 } 213 if (projects!=null) { 214 for (int i=0; i<projects.length; i++) { 215 Project p=projects[i]; 216 clonedOption = (HTMLOptionElement)optProject.cloneNode(true); 224 clonedOption.setValue(p.getHandle()); 225 optionTextNode = clonedOption.getOwnerDocument(). 226 createTextNode(p.getName()); 227 clonedOption.appendChild(optionTextNode); 228 if (selectedProjectID!=null && p.getHandle().equals(selectedProjectID)) { 229 clonedOption.setAttribute("selected","selected"); 230 } 231 cboProjects.appendChild(clonedOption); 234 } 235 } 236 cboProjects.removeChild(optProject); 237 238 } catch(NullPointerException ex) { 239 } catch (Exception ex) { 240 ex.printStackTrace(); 241 this.writeDebugMsg("Error populating list of projects: " + ex); 242 throw new ProjectManagementPresentationException("Error populating project list: ", ex); 243 } 244 245 246 } 247 248 private void fillMonths(ControlsHTML page,String selectedMonthID) 249 throws ProjectManagementPresentationException { 250 HTMLSelectElement cboMonth=page.getElementCboMonth(); 251 HTMLOptionElement optMonth = page.getElementOptMonth(); 252 optMonth.removeChild(optMonth.getFirstChild()); 254 255 try { 256 HTMLOptionElement clonedOption = (HTMLOptionElement)optMonth.cloneNode(true); 258 String all="All"; 259 clonedOption.setValue(""); 260 Node optionTextNode = clonedOption.getOwnerDocument(). 261 createTextNode(all); 262 clonedOption.appendChild(optionTextNode); 263 cboMonth.appendChild(clonedOption); 264 265 for (int i=1; i<=12; i++) { 266 clonedOption = (HTMLOptionElement)optMonth.cloneNode(true); 274 String curMonth=String.valueOf(i); 275 clonedOption.setValue(curMonth); 276 optionTextNode = clonedOption.getOwnerDocument(). 277 createTextNode(curMonth); 278 clonedOption.appendChild(optionTextNode); 279 if (selectedMonthID!=null && curMonth.equals(selectedMonthID)) { 280 clonedOption.setAttribute("selected","selected"); 281 } 282 cboMonth.appendChild(clonedOption); 285 } 286 cboMonth.removeChild(optMonth); 287 } catch(NullPointerException ex) { 288 } catch (Exception ex) { 289 this.writeDebugMsg("Error populating list of months: " + ex); 290 throw new ProjectManagementPresentationException("Error populating month list: ", ex); 291 } 292 293 294 } 295 } 296 | Popular Tags |