001: /*
002: * projectManagement
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package projectmanagement.presentation.payrates;
009:
010: import projectmanagement.spec.employee.*;
011: import projectmanagement.spec.project.*;
012: import projectmanagement.presentation.*;
013:
014: import org.w3c.dom.*;
015: import org.w3c.dom.html.*;
016:
017: // Enhydra SuperServlet imports
018: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
019: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
020: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
021:
022: // Standard imports
023: import java.io.IOException;
024:
025: /**
026: * Generates the blank HTML page.
027: */
028: public class Controls implements HttpPresentation {
029:
030: /**
031: * Constants
032: */
033: private static String EMPLOYEE = "employee";
034: private static String PROJECT = "project";
035:
036: public void run(HttpPresentationComms comms)
037: throws HttpPresentationException, IOException {
038: ControlsHTML page = new ControlsHTML();
039:
040: String employee = comms.request.getParameter(EMPLOYEE);
041: HTMLSelectElement sel = page.getElementCboEmployee();
042: fillEmployeeSelection(page, sel, employee);
043:
044: String project = comms.request.getParameter(PROJECT);
045: sel = page.getElementCboProject();
046: fillProjectSelection(page, sel, project);
047:
048: comms.response.writeDOM(page);
049: }
050:
051: private void fillEmployeeSelection(ControlsHTML page,
052: HTMLSelectElement cboEmployees, String selectedEmployeeID)
053: throws ProjectManagementPresentationException {
054: HTMLOptionElement optEmployee = page.getElementOptEmployee();
055:
056: try {
057: EmployeeManager employeeManager = EmployeeManagerFactory
058: .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
059: Employee[] employees = employeeManager.getAllEmployees();
060:
061: // Remove the dummy storyboard text from the prototype HTML
062: optEmployee.removeChild(optEmployee.getFirstChild());
063:
064: // set the text to select all employees - default option
065: HTMLOptionElement clonedOption = (HTMLOptionElement) optEmployee
066: .cloneNode(true);
067: clonedOption.setValue("");
068: String all = "All";
069: Node optionTextNode = clonedOption.getOwnerDocument()
070: .createTextNode(all);
071: clonedOption.appendChild(optionTextNode);
072: clonedOption.setAttribute("selected", "selected");
073:
074: // Do only a shallow copy of the option as we don't want the text child
075: // of the node option
076: cboEmployees.appendChild(clonedOption);
077:
078: // set all employees
079: if (employees != null) {
080: for (int i = 0; i < employees.length; i++) {
081: Employee e = employees[i];
082: // Now populate the combo with employees
083: // This algorithm is obscure because options
084: // are not normal HTML elements
085: // First populate the option value (the employee database ID).
086: // Then append a text child as the option
087: // text, which is what is displayed as the text
088: // in each row of the select box
089: clonedOption = (HTMLOptionElement) optEmployee
090: .cloneNode(true);
091: clonedOption.setValue(e.getHandle());
092: optionTextNode = clonedOption.getOwnerDocument()
093: .createTextNode(
094: e.getFirstName() + " "
095: + e.getLastName());
096: clonedOption.appendChild(optionTextNode);
097: if (selectedEmployeeID != null
098: && e.getHandle().equals(selectedEmployeeID)) {
099: clonedOption.setAttribute("selected",
100: "selected");
101:
102: }
103: // Do only a shallow copy of the option as we don't want the text child
104: // of the node option
105: cboEmployees.appendChild(clonedOption);
106: }
107: }
108: cboEmployees.removeChild(optEmployee);
109: } catch (NullPointerException ex) {
110: } catch (Exception ex) {
111: //this.writeDebugMsg("Error populating list of employees: " + ex);
112: throw new ProjectManagementPresentationException(
113: "Error populating employee list: ", ex);
114: }
115:
116: }
117:
118: private void fillProjectSelection(ControlsHTML page,
119: HTMLSelectElement cboProjects, String selectedProjectID)
120: throws ProjectManagementPresentationException {
121: HTMLOptionElement optProject = page.getElementOptProject();
122:
123: try {
124:
125: ProjectManager projectManager = ProjectManagerFactory
126: .getProjectManager("projectmanagement.business.project.ProjectManagerImpl");
127: Project[] projects = projectManager.getAllProjects();
128:
129: // Remove the dummy storyboard text from the prototype HTML
130: optProject.removeChild(optProject.getFirstChild());
131:
132: // set the text to select all projects - default option
133: HTMLOptionElement clonedOption = (HTMLOptionElement) optProject
134: .cloneNode(true);
135: clonedOption.setValue("");
136: String all = "All";
137: Node optionTextNode = clonedOption.getOwnerDocument()
138: .createTextNode(all);
139: clonedOption.appendChild(optionTextNode);
140: clonedOption.setAttribute("selected", "selected");
141:
142: // Do only a shallow copy of the option as we don't want the text child
143: // of the node option
144: cboProjects.appendChild(clonedOption);
145:
146: // set all projects
147:
148: if (projects != null) {
149: for (int i = 0; i < projects.length; i++) {
150: Project p = projects[i];
151: // Now populate the combo with projects
152: // This algorithm is obscure because options
153: // are not normal HTML elements
154: // First populate the option value (the project database ID).
155: // Then append a text child as the option
156: // text, which is what is displayed as the text
157: // in each row of the select box
158: clonedOption = (HTMLOptionElement) optProject
159: .cloneNode(true);
160: clonedOption.setValue(p.getHandle());
161: optionTextNode = clonedOption.getOwnerDocument()
162: .createTextNode(p.getName());
163: clonedOption.appendChild(optionTextNode);
164: if (selectedProjectID != null
165: && p.getHandle().equals(selectedProjectID)) {
166: clonedOption.setAttribute("selected",
167: "selected");
168:
169: }
170: // Do only a shallow copy of the option as we don't want the text child
171: // of the node option
172: cboProjects.appendChild(clonedOption);
173: }
174: }
175:
176: cboProjects.removeChild(optProject);
177:
178: } catch (NullPointerException ex) {
179: } catch (Exception ex) {
180: //this.writeDebugMsg("Error populating list of projects: " + ex);
181: throw new ProjectManagementPresentationException(
182: "Error populating project list: ", ex);
183: }
184:
185: }
186:
187: }
|