001: package projectmanagement.presentation.projects;
002:
003: import projectmanagement.presentation.*;
004: import projectmanagement.spec.project.*;
005: import com.lutris.appserver.server.httpPresentation.*;
006: import org.enhydra.xml.xmlc.XMLObject;
007:
008: import org.w3c.dom.*;
009: import org.w3c.dom.html.*;
010:
011: /**
012: * Shows a list of projects to administer.
013: *
014: * @author Sasa Bojanic
015: * @version 1.0
016: */
017: public class Administering extends BasePO {
018:
019: /**
020: * Constants
021: */
022: private static String CUSTOMER = "customer";
023:
024: /**
025: * Superclass method override. Returns 2.
026: */
027: protected int getRequiredAuthLevel() {
028: return 2;
029: }
030:
031: /**
032: * Default event. Just show the page.
033: */
034: public XMLObject handleDefault() throws HttpPresentationException {
035:
036: AdministeringHTML page = new AdministeringHTML();
037:
038: String customer = this .getComms().request
039: .getParameter(CUSTOMER);
040: if (customer != null && customer.length() == 0) {
041: customer = null;
042: }
043:
044: String errorMsg = this .getSessionData()
045: .getAndClearUserMessage();
046: /*if(null != errorMsg) {
047: page.setTextLblErrorText(errorMsg);
048: } else {
049: page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
050: }*/
051:
052: try {
053: ProjectManager projectManager = ProjectManagerFactory
054: .getProjectManager("projectmanagement.business.project.ProjectManagerImpl");
055: Project[] projects = projectManager
056: .getAllProjectsForCustomer(customer);
057:
058: // fetches the table element from HTML document
059: HTMLTableElement table = page.getElementTblProjects();
060:
061: if (projects != null) {
062: for (int i = 0; i < projects.length; i++) {
063: // creating row in HTML table which describes table properties
064: HTMLTableRowElement htmlRE = createNewRow(page,
065: projects[i]);
066: // appending row at the end of table
067: table.appendChild(htmlRE);
068: }
069: }
070: //Remove template selection row from table
071: table.removeChild(page.getElementTemplateRow());
072:
073: /* Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
074: * We need to allow ProjectManagement_pres to be functional , response
075: * will be default HTML page
076: */
077: } catch (NullPointerException ex) {
078:
079: } catch (Exception ex) {
080: this .writeDebugMsg("Error populating list of projects: "
081: + ex);
082: throw new ProjectManagementPresentationException(
083: "Error getting list of projects: ", ex);
084: }
085:
086: // write out HTML
087: return page;
088: }
089:
090: /**
091: * Creates the new row of HTML table element, based on given parameters.
092: */
093: private HTMLTableRowElement createNewRow(
094: AdministeringHTML administeringHTML, Project project) {
095:
096: String projectID = "";
097:
098: try {
099: projectID = project.getHandle();
100: administeringHTML.setTextTxtCustomer(project.getCustomer()
101: .getCompanyName());
102: administeringHTML.setTextTxtName(project.getName());
103: administeringHTML.setTextTxtMoneyPerHour(String
104: .valueOf(project.getMoneyPerHour()));
105: } catch (Exception ex) {
106: }
107:
108: // image to get details on project
109: HTMLImageElement detailsImg = administeringHTML
110: .getElementImgDetails();
111: detailsImg.setName(projectID);
112:
113: // image to modify project information
114: HTMLImageElement modifyImg = administeringHTML
115: .getElementImgModify();
116: modifyImg.setName(projectID);
117:
118: // image to delete project
119: HTMLImageElement deleteImg = administeringHTML
120: .getElementImgDelete();
121: deleteImg.setName(projectID);
122:
123: HTMLTableRowElement row = (HTMLTableRowElement) administeringHTML
124: .getElementTemplateRow().cloneNode(true);
125:
126: return row;
127: }
128:
129: }
|