001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.ui;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Vector;
023:
024: import org.ofbiz.entity.GenericDelegator;
025: import org.ofbiz.entity.GenericEntityException;
026: import org.ofbiz.entity.GenericValue;
027: import org.ofbiz.entity.condition.EntityExpr;
028: import org.ofbiz.entity.condition.EntityOperator;
029:
030: /**
031: * DOCUMENT ME!
032: *
033: */
034: public class RoleTreeNode extends BasicTreeNode {
035: public static final String module = RoleTreeNode.class.getName();
036:
037: public RoleTreeNode() {
038: super ();
039: }
040:
041: public RoleTreeNode(Object userObject) {
042: super (userObject);
043: }
044:
045: /**
046: * DOCUMENT ME!
047: *
048: * @param delegator
049: *
050: * @return
051: *
052: * @throws GenericEntityException
053: * @throws ClassNotFoundException
054: * @throws LinkageError
055: * @throws ExceptionInInitializerError
056: * @throws InstantiationException
057: * @throws IllegalAccessException
058: */
059: public static BasicTreeNode createTree(GenericDelegator delegator)
060: throws GenericEntityException, ClassNotFoundException,
061: LinkageError, ExceptionInInitializerError,
062: InstantiationException, IllegalAccessException {
063: return createTree(delegator, "Role", "roleId", "roleParentId",
064: "com.sourcetap.sfa.ui.RoleTreeNode");
065: }
066:
067: /**
068: * DOCUMENT ME!
069: *
070: * @param delegator
071: * @param accountId
072: *
073: * @return
074: *
075: * @throws GenericEntityException
076: * @throws ClassNotFoundException
077: * @throws LinkageError
078: * @throws ExceptionInInitializerError
079: * @throws InstantiationException
080: * @throws IllegalAccessException
081: */
082: public static BasicTreeNode createTree(GenericDelegator delegator,
083: String accountId) throws GenericEntityException,
084: ClassNotFoundException, LinkageError,
085: ExceptionInInitializerError, InstantiationException,
086: IllegalAccessException {
087: ArrayList orderBy = new ArrayList();
088: orderBy.add("roleParentId");
089:
090: HashMap acctMap = new HashMap();
091: acctMap.put("accountId", accountId);
092:
093: List rows = delegator.findByLike("Role", acctMap, orderBy);
094: GenericValue[] genericValue = (GenericValue[]) rows
095: .toArray(new GenericValue[0]);
096:
097: return createTree(genericValue, "roleId", "roleParentId",
098: "com.sourcetap.sfa.ui.RoleTreeNode");
099: }
100:
101: /**
102: * DOCUMENT ME!
103: *
104: * @return
105: */
106: public String getDisplayText() {
107: Object o = getUserObject();
108:
109: String name = "";
110: String assignments = "";
111: String roleId = "";
112:
113: if (o instanceof String) {
114: name = (String) o;
115:
116: if (name.equals("PLACEHOLDER")) {
117: name = "";
118: }
119: } else if (o instanceof GenericValue) {
120: GenericValue gv = (GenericValue) o;
121: name = (String) gv.get("roleName");
122: roleId = (String) gv.get("roleId");
123:
124: try {
125: GenericDelegator delegator = gv.getDelegator();
126:
127: //find contacts for role
128: Vector contactFields = new Vector();
129: Vector contactValueVector = new Vector();
130: Vector contactOps = new Vector();
131:
132: contactFields.add(new EntityExpr("roleId",
133: EntityOperator.EQUALS, roleId));
134:
135: List contacts = delegator.findByAnd("Contact",
136: contactFields, null);
137: GenericValue[] contactValues = (GenericValue[]) contacts
138: .toArray(new GenericValue[0]);
139:
140: for (int i = 0; i < contactValues.length; i++) {
141: GenericValue contactValue = contactValues[i];
142: String firstName = contactValue
143: .getString("firstName");
144: String lastName = contactValue
145: .getString("lastName");
146:
147: if (assignments.length() > 0) {
148: assignments = assignments + "<BR>";
149: }
150:
151: assignments = assignments + "<nobr>" + firstName
152: + " " + lastName + "</nobr>";
153: }
154: } catch (Exception e) {
155: }
156: }
157:
158: String html = "<div align=top><font color=#003399><b><center>"
159: + name + "</center></b></div>\n";
160:
161: if (assignments.length() > 0) {
162: html += ("<br><br><font color=#009933><center>"
163: + assignments + "</center>");
164: } else {
165: html += "<br><br><font color=#993300><center><i>Unassigned</i></center></font>";
166: }
167:
168: // add buttons
169: html = html
170: + "<br><div class=freeFormSectionTitleTable>"
171: + "<FORM NAME=TerritoryFormButton STYLE=\"BORDER:0; MARGIN:0; PADDING:0; \" METHOD=post ACTION=territoryEdit TARGET=contentFrame>"
172: + "<INPUT TYPE=hidden NAME=roleId VALUE="
173: + roleId
174: + ">"
175: + "<INPUT TYPE=hidden NAME=action VALUE=button>"
176: + "<INPUT CLASS=titleBarImageButton TYPE=image NAME=newButton TITLE=\"Create a new record\" SRC=/sfaimages/New24.gif>"
177: + "<INPUT CLASS=titleBarImageButton TYPE=image NAME=editButton TITLE=\"Edit the current record\" SRC=/sfaimages/Edit24.gif>"
178: + "<INPUT CLASS=titleBarImageButton TYPE=image NAME=deleteButton TITLE=\"Delete the current record\" SRC=/sfaimages/Delete24.gif>"
179: + "</FORM></div>";
180:
181: return html;
182: }
183: }
|