1 7 8 package projectmanagement.presentation.payrates; 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 22 import java.io.IOException ; 24 25 28 public class Controls implements HttpPresentation { 29 30 33 private static String EMPLOYEE = "employee"; 34 private static String PROJECT = "project"; 35 36 public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException { 37 ControlsHTML page=new ControlsHTML(); 38 39 String employee = comms.request.getParameter(EMPLOYEE); 40 HTMLSelectElement sel=page.getElementCboEmployee(); 41 fillEmployeeSelection(page,sel,employee); 42 43 String project = comms.request.getParameter(PROJECT); 44 sel=page.getElementCboProject(); 45 fillProjectSelection(page,sel,project); 46 47 comms.response.writeDOM(page); 48 } 49 50 private void fillEmployeeSelection (ControlsHTML page,HTMLSelectElement cboEmployees, 51 String selectedEmployeeID) throws ProjectManagementPresentationException { 52 HTMLOptionElement optEmployee = page.getElementOptEmployee(); 53 54 try { 55 EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl"); 56 Employee[] employees=employeeManager.getAllEmployees(); 57 58 optEmployee.removeChild(optEmployee.getFirstChild()); 60 61 62 HTMLOptionElement clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true); 64 clonedOption.setValue(""); 65 String all="All"; 66 Node optionTextNode = clonedOption.getOwnerDocument(). 67 createTextNode(all); 68 clonedOption.appendChild(optionTextNode); 69 clonedOption.setAttribute("selected","selected"); 70 71 cboEmployees.appendChild(clonedOption); 74 75 76 77 if (employees!=null) { 79 for (int i=0; i<employees.length; i++) { 80 Employee e=employees[i]; 81 clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true); 89 clonedOption.setValue(e.getHandle()); 90 optionTextNode = clonedOption.getOwnerDocument(). 91 createTextNode(e.getFirstName()+" "+e.getLastName()); 92 clonedOption.appendChild(optionTextNode); 93 if (selectedEmployeeID!=null && e.getHandle().equals(selectedEmployeeID)) { 94 clonedOption.setAttribute("selected","selected"); 95 96 } 97 cboEmployees.appendChild(clonedOption); 100 } 101 } 102 cboEmployees.removeChild(optEmployee); 103 } catch(NullPointerException ex) { 104 } catch (Exception ex) { 105 throw new ProjectManagementPresentationException("Error populating employee list: ", ex); 107 } 108 109 110 } 111 112 private void fillProjectSelection (ControlsHTML page,HTMLSelectElement cboProjects, 113 String selectedProjectID) throws ProjectManagementPresentationException { 114 HTMLOptionElement optProject = page.getElementOptProject(); 115 116 117 try { 118 119 ProjectManager projectManager = ProjectManagerFactory.getProjectManager("projectmanagement.business.project.ProjectManagerImpl"); 120 Project[] projects=projectManager.getAllProjects(); 121 122 optProject.removeChild(optProject.getFirstChild()); 124 125 HTMLOptionElement clonedOption = (HTMLOptionElement)optProject.cloneNode(true); 127 clonedOption.setValue(""); 128 String all="All"; 129 Node optionTextNode = clonedOption.getOwnerDocument(). 130 createTextNode(all); 131 clonedOption.appendChild(optionTextNode); 132 clonedOption.setAttribute("selected","selected"); 133 134 cboProjects.appendChild(clonedOption); 137 138 140 141 if (projects!=null) { 142 for (int i=0; i<projects.length; i++) { 143 Project p=projects[i]; 144 clonedOption = (HTMLOptionElement)optProject.cloneNode(true); 152 clonedOption.setValue(p.getHandle()); 153 optionTextNode = clonedOption.getOwnerDocument(). 154 createTextNode(p.getName()); 155 clonedOption.appendChild(optionTextNode); 156 if (selectedProjectID!=null && p.getHandle().equals(selectedProjectID)) { 157 clonedOption.setAttribute("selected","selected"); 158 159 } 160 cboProjects.appendChild(clonedOption); 163 } 164 } 165 166 cboProjects.removeChild(optProject); 167 168 } catch(NullPointerException ex) { 169 } catch (Exception ex) { 170 throw new ProjectManagementPresentationException("Error populating project list: ", ex); 172 } 173 174 } 175 176 } 177 | Popular Tags |