001: package com.sourcetap.sfa.ui;
002:
003: import java.util.ArrayList;
004: import java.util.Iterator;
005: import java.util.List;
006:
007: import org.ofbiz.base.util.Debug;
008: import org.ofbiz.base.util.UtilMisc;
009: import org.ofbiz.entity.GenericDelegator;
010: import org.ofbiz.entity.GenericEntityException;
011: import org.ofbiz.entity.GenericValue;
012:
013: public class UIReportOrderBy {
014: public static final String module = UIReportOrderBy.class.getName();
015:
016: protected String reportOrderId;
017: protected String reportId;
018: protected String attributeId;
019: protected int sortOrder;
020: protected String displayLabel;
021:
022: protected boolean attNameLoaded = false;
023: protected String attributeName;
024: protected String entityName;
025:
026: protected GenericDelegator delegator;
027:
028: public static List loadFromGVL(List reportOrderByGVL) {
029: List retList = new ArrayList();
030: Iterator iter = reportOrderByGVL.iterator();
031: while (iter.hasNext()) {
032: GenericValue gv = (GenericValue) iter.next();
033: retList.add(new UIReportOrderBy(gv));
034: }
035: return retList;
036: }
037:
038: public UIReportOrderBy(GenericValue genricValue) {
039: setReportOrderId(genricValue.getString("reportOrderId"));
040: setReportId(genricValue.getString("reportId"));
041: setAttributeId(genricValue.getString("attributeId"));
042: setDisplayLabel(genricValue.getString("displayLabel"));
043: setSortOrder(genricValue.getString("sortOrder"));
044:
045: setDelegator(genricValue.getDelegator());
046: }
047:
048: public UIReportOrderBy(String attributeId, int sortOrder,
049: String displayLabel) {
050: setAttributeId(attributeId);
051: setSortOrder(sortOrder);
052: setDisplayLabel(displayLabel);
053: }
054:
055: public void loadEntityAttributeInfo(GenericDelegator delegator,
056: String attributeId) {
057: try {
058: List eaGVL = delegator.findByAnd("UiEntityAttribute",
059: UtilMisc.toMap("attributeId", attributeId));
060: GenericValue eaGV = (GenericValue) eaGVL.get(0);
061:
062: setEntityName(eaGV.getString("entityName"));
063: setAttributeName(eaGV.getString("attributeName"));
064: attNameLoaded = true;
065:
066: } catch (GenericEntityException e) {
067: // TODO Auto-generated catch block
068: e.printStackTrace();
069: }
070: }
071:
072: /**
073: * @return
074: */
075: public String getAttributeId() {
076: return attributeId;
077: }
078:
079: /**
080: * @return
081: */
082: public String getAttributeName() {
083: if (!attNameLoaded)
084: loadEntityAttributeInfo(getDelegator(), getAttributeId());
085: return attributeName;
086: }
087:
088: /**
089: * @return
090: */
091: public GenericDelegator getDelegator() {
092: return delegator;
093: }
094:
095: /**
096: * @return
097: */
098: public String getEntityName() {
099: if (!attNameLoaded)
100: loadEntityAttributeInfo(getDelegator(), getAttributeId());
101: return entityName;
102: }
103:
104: /**
105: * @return
106: */
107: public String getReportId() {
108: return reportId;
109: }
110:
111: /**
112: * @return
113: */
114: public String getReportOrderId() {
115: return reportOrderId;
116: }
117:
118: /**
119: * @return
120: */
121: public int getSortOrder() {
122: return sortOrder;
123: }
124:
125: /**
126: * @param string
127: */
128: public void setAttributeId(String string) {
129: attributeId = string;
130: }
131:
132: /**
133: * @param string
134: */
135: public void setAttributeName(String string) {
136: attributeName = string;
137: }
138:
139: /**
140: * @param delegator
141: */
142: public void setDelegator(GenericDelegator delegator) {
143: this .delegator = delegator;
144: }
145:
146: /**
147: * @param string
148: */
149: public void setEntityName(String string) {
150: entityName = string;
151: }
152:
153: /**
154: * @param string
155: */
156: public void setReportId(String string) {
157: reportId = string;
158: }
159:
160: /**
161: * @param string
162: */
163: public void setReportOrderId(String string) {
164: reportOrderId = string;
165: }
166:
167: /**
168: * @param i
169: */
170: public void setSortOrder(int i) {
171: sortOrder = i;
172: }
173:
174: /**
175: * @param s
176: */
177: public void setSortOrder(String s) {
178: try {
179: sortOrder = Integer.valueOf(s).intValue();
180: } catch (NumberFormatException e) {
181: Debug.logError("error converting sortOrder to int: " + s,
182: module);
183: }
184: }
185:
186: /**
187: * @return
188: */
189: public String getDisplayLabel() {
190: return displayLabel;
191: }
192:
193: /**
194: * @param string
195: */
196: public void setDisplayLabel(String string) {
197: displayLabel = string;
198: }
199:
200: }
|