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.customization;
018:
019: import java.util.Iterator;
020:
021: import org.ofbiz.base.util.Debug;
022: import org.ofbiz.entity.GenericDelegator;
023: import org.ofbiz.entity.GenericEntityException;
024: import org.ofbiz.entity.GenericValue;
025: import org.ofbiz.entity.model.ModelEntity;
026: import org.ofbiz.entity.model.ModelField;
027:
028: import com.sourcetap.sfa.event.DataMatrix;
029: import com.sourcetap.sfa.event.GenericEventProcessor;
030: import com.sourcetap.sfa.replication.GenericReplicator;
031: import com.sourcetap.sfa.util.StringHelper;
032: import com.sourcetap.sfa.util.UserInfo;
033:
034: /**
035: * DOCUMENT ME!
036: *
037: */
038: public class UIEntityEventProcessor extends GenericEventProcessor {
039: public static final String module = UIEntityEventProcessor.class
040: .getName();
041:
042: private static String displayObjectText20 = "1";
043: private static String displayObjectText60 = "2";
044: private static String displayObjectDateTime = "17";
045: private static String displayObjectDate = "18";
046: private static String displayObjectTime = "19";
047: private static String displayObjectCheckbox = "41";
048: private static String displayObjectCurrency = "25";
049: private static String displayObjectNumber = "26";
050: private static String displayObjectSelectUser = "21";
051: private static String displayObjectText255 = "34";
052: private static String displayObjectTextArea = "55";
053:
054: /**
055: * Create the default UIAttribute values by copying from fields from the Table Definition
056: *
057: * @param userInfo
058: * @param delegator
059: * @param dataMatrix
060: *
061: * @return
062: */
063: protected int postInsert(UserInfo userInfo,
064: GenericDelegator delegator, DataMatrix dataMatrix) {
065:
066: // Get the current values.
067: GenericValue uiEntityGV = dataMatrix.getCurrentBuffer()
068: .getGenericValue(0, 0);
069: String entityId = uiEntityGV.getString("entityId");
070: String entityName = uiEntityGV.getString("entityName");
071:
072: if ((entityId == null) || (entityName == null))
073: return STATUS_CONTINUE;
074:
075: ModelEntity me = delegator.getModelEntity(entityName);
076: if (me == null)
077: return STATUS_CONTINUE;
078:
079: ModelEntity uiAttributeME = delegator
080: .getModelEntity("UiAttribute");
081:
082: Iterator fieldI = me.getFieldsIterator();
083: int displayOrder = 0;
084:
085: while (fieldI.hasNext()) {
086: ModelField fld = (ModelField) fieldI.next();
087:
088: String attrName = fld.getName();
089: String colName = fld.getName();
090: String type = fld.getType();
091: boolean isPK = fld.getIsPk();
092:
093: String displayType = "";
094: String maxLength = "20";
095: String editMask = "";
096: String displayLogic = "";
097: boolean isMandatory = fld.getIsPk();
098: boolean isReadOnly = false;
099: boolean isVisible = true;
100: boolean isSearchable = true;
101: boolean isExtension = false;
102: displayOrder += 10;
103: String displayLabel = StringHelper
104: .javaNameToDescription(attrName);
105: int colSpan = 1;
106: int rowSpan = 1;
107: boolean startOnNewRow = false;
108: String displayObjectId = "0";
109:
110: if (attrName.equals("createdBy")
111: || attrName.equals("modifiedBy")) {
112: displayObjectId = displayObjectSelectUser;
113: maxLength = "60";
114:
115: } else if (type.equals("date-time")) {
116: displayObjectId = displayObjectDateTime;
117: } else if (type.equals("time")) {
118: displayObjectId = displayObjectTime;
119: } else if (type.equals("date")) {
120: displayObjectId = displayObjectDate;
121: } else if (type.equals("currency-amount")) {
122: displayObjectId = displayObjectCurrency;
123: } else if (type.equals("floating-point")
124: || type.equals("numeric")) {
125: displayObjectId = displayObjectNumber;
126: } else if (type.equals("id") || type.equals("id-ne")) {
127: displayObjectId = displayObjectText20;
128: } else if (type.equals("id-long")
129: || type.equals("short-varchar")
130: || type.equals("id-long-ne")
131: || type.equals("tel-number")) {
132: displayObjectId = displayObjectText60;
133: maxLength = "60";
134: } else if (type.equals("id-vlong")
135: || type.equals("long-varchar")
136: || type.equals("comment")
137: || type.equals("description")
138: || type.equals("value") || type.equals("email")
139: || type.equals("url") || type.equals("id-vlong-ne")) {
140: displayObjectId = displayObjectText255;
141: maxLength = "255";
142: } else if (type.equals("very-short")) {
143: displayObjectId = displayObjectText20;
144: maxLength = "10";
145: } else if (type.equals("indicator")) {
146: displayObjectId = displayObjectCheckbox;
147: maxLength = "1";
148: } else if (type.equals("very-long")) {
149: displayObjectId = displayObjectTextArea;
150: maxLength = "1000";
151: } else if (type.equals("name")) {
152: displayObjectId = displayObjectText60;
153: maxLength = "100";
154: } else {
155: displayObjectId = displayObjectText20;
156: maxLength = "20";
157: }
158:
159: if (type.equals("id-ne") || type.equals("id-long-ne")
160: || type.equals("id-vlong-ne")) {
161: isMandatory = true;
162: }
163:
164: String attributeId = GenericReplicator.getNextSeqId(
165: "UiAttribute", delegator);
166:
167: GenericValue uiAttributeGV = new GenericValue(uiAttributeME);
168: uiAttributeGV.setDelegator(delegator);
169: uiAttributeGV.set("attributeId", attributeId);
170: uiAttributeGV.set("entityId", entityId);
171: uiAttributeGV.set("attributeName", attrName);
172: uiAttributeGV.set("description", displayLabel);
173: uiAttributeGV.set("columnName", colName);
174: uiAttributeGV.set("displayObjectId", displayObjectId);
175: uiAttributeGV.set("maxLength", maxLength);
176: uiAttributeGV.set("editMask", "");
177: uiAttributeGV.set("displayLogic", "");
178: uiAttributeGV.set("isMandatory", Boolean
179: .valueOf(isMandatory));
180: uiAttributeGV
181: .set("isReadOnly", Boolean.valueOf(isReadOnly));
182: uiAttributeGV.set("isVisible", Boolean.valueOf(isVisible));
183: uiAttributeGV.set("isSearchable", Boolean
184: .valueOf(isSearchable));
185: uiAttributeGV.set("isExtension", Boolean
186: .valueOf(isExtension));
187: uiAttributeGV
188: .set("displayOrder", new Integer(displayOrder));
189: uiAttributeGV.set("displayLabel", displayLabel);
190: uiAttributeGV.set("displayLength", maxLength);
191: uiAttributeGV.set("colSpan", new Integer(colSpan));
192: uiAttributeGV.set("rowSpan", new Integer(rowSpan));
193: uiAttributeGV.set("startOnNewRow", Boolean
194: .valueOf(startOnNewRow));
195:
196: // This is a copy of an existing screen section.
197:
198: try {
199: delegator.create(uiAttributeGV);
200: } catch (GenericEntityException e) {
201: Debug.logError(e, module);
202: }
203: }
204:
205: return STATUS_CONTINUE;
206: }
207:
208: /**
209: * DOCUMENT ME!
210: *
211: * @param userInfo
212: * @param delegator
213: * @param originatingEntityName
214: * @param entityGV
215: *
216: * @return
217: */
218: public int deleteAllRelated(UserInfo userInfo,
219: GenericDelegator delegator, String originatingEntityName,
220: GenericValue entityGV) {
221:
222: int status = STATUS_CONTINUE;
223:
224: // Delete related screen section entities.
225: status = deleteOneRelated(userInfo, delegator, entityGV, "",
226: "UiAttribute", originatingEntityName,
227: new GenericEventProcessor());
228:
229: return status;
230: }
231: }
|