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.Iterator;
022: import java.util.List;
023:
024: import org.ofbiz.base.util.UtilTimer;
025: import org.ofbiz.entity.GenericDelegator;
026: import org.ofbiz.entity.GenericEntityException;
027: import org.ofbiz.entity.GenericPK;
028: import org.ofbiz.entity.GenericValue;
029: import org.ofbiz.entity.model.ModelEntity;
030:
031: /**
032: * DOCUMENT ME!
033: *
034: */
035: public class UIDisplayObject {
036: public static final String module = UIDisplayObject.class.getName();
037: private static final boolean TIMER = false;
038: public static final String DISPLAY_TYPE_CHECKBOX = "CHECKBOX";
039: public static final String DISPLAY_TYPE_CURRENCY = "CURRENCY";
040: public static final String DISPLAY_TYPE_DATE = "DATE";
041: public static final String DISPLAY_TYPE_DATETIME = "DATETIME";
042: public static final String DISPLAY_TYPE_HIDDEN = "HIDDEN";
043: public static final String DISPLAY_TYPE_NUMBER = "NUMBER";
044: public static final String DISPLAY_TYPE_PERCENT = "PERCENT";
045: public static final String DISPLAY_TYPE_SEARCH_TEXT = "SEARCH_TEXT";
046: public static final String DISPLAY_TYPE_SELECT = "SELECT";
047: public static final String DISPLAY_TYPE_TEXT = "TEXT";
048: public static final String DISPLAY_TYPE_TEXTAREA = "TEXTAREA";
049: public static final String DISPLAY_TYPE_TIME = "TIME";
050: public static final String DISPLAY_TYPE_FILE = "FILE";
051: protected String displayObjectId = "";
052: protected String displayTypeId = "";
053: protected String attribAlign = "";
054: protected String attribAnchorHrefDef = "";
055: protected String attribAnchorTarget = "";
056: protected String attribCheckedDisplay = "Yes";
057: protected String attribCheckedValue = "Y";
058: protected String attribClass = "";
059: protected String attribCols = "";
060: protected String attribDisabled = "";
061: protected String attribDisplayMask = "";
062: protected String attribEmptyFirst = "";
063: protected String attribEntity = "";
064: protected String attribEntityDisplayDef = "";
065: protected String attribEventHandling = "";
066: protected String attribEntityFindDef = "";
067: protected String attribEntityFindMethod = "";
068: protected String attribEntityOrderDef = "";
069: protected String attribEntityPkFindDef = "";
070: protected String attribEntityValueDef = "";
071: protected String attribEntitySearchDef = "";
072: protected String attribFixedValues = "";
073: protected String attribFillMethod = "";
074: protected String attribMaxLength = "";
075: protected String attribRows = "";
076: protected String attribSize = "";
077: protected String attribReadOnly = "";
078: protected String attribUncheckedDisplay = "No";
079: protected String attribUncheckedValue = "N";
080: protected String attribWrap = "";
081: protected GenericDelegator delegator = null;
082: protected boolean attributesLoaded = false;
083:
084: public UIDisplayObject(String displayObjectId,
085: GenericDelegator delegator) throws GenericEntityException {
086: UtilTimer timer = new UtilTimer();
087:
088: if (TIMER) {
089: timer.timerString(3,
090: "[UIDisplayObject.UIDisplayObject] Start");
091: }
092:
093: // Get the UI display object generic value from the database.
094: ModelEntity uiDisplayObjectEntity = delegator
095: .getModelEntity("UiDisplayObject");
096: HashMap findMap = new HashMap();
097: findMap.put("displayObjectId", displayObjectId);
098:
099: GenericPK uiDisplayObjectPK = new GenericPK(
100: uiDisplayObjectEntity, findMap);
101: GenericValue uiDisplayObjectGV = delegator
102: .findByPrimaryKey(uiDisplayObjectPK);
103:
104: if (uiDisplayObjectGV == null) {
105: throw new GenericEntityException(
106: "No display object was found with ID "
107: + displayObjectId);
108: }
109:
110: setDisplayObjectId(displayObjectId);
111: setDisplayTypeId(uiDisplayObjectGV.getString("displayTypeId"));
112: setDelegator(delegator);
113:
114: if (TIMER) {
115: timer.timerString(3,
116: "[UIDisplayObject.UIDisplayObject] End");
117: }
118: }
119:
120: /**
121: * DOCUMENT ME!
122: *
123: * @return
124: */
125: public String getDisplayObjectId() {
126: return displayObjectId;
127: }
128:
129: /**
130: * DOCUMENT ME!
131: *
132: * @return
133: */
134: public String getDisplayTypeId() {
135: return displayTypeId;
136: }
137:
138: /**
139: * DOCUMENT ME!
140: *
141: * @return
142: */
143: public String getAttribAlign() {
144: return attribAlign;
145: }
146:
147: /**
148: * DOCUMENT ME!
149: *
150: * @return
151: */
152: public String getAttribAnchorHrefDef() {
153: return attribAnchorHrefDef;
154: }
155:
156: /**
157: * DOCUMENT ME!
158: *
159: * @return
160: */
161: public String getAttribAnchorTarget() {
162: return attribAnchorTarget;
163: }
164:
165: /**
166: * DOCUMENT ME!
167: *
168: * @return
169: */
170: public String getAttribCheckedDisplay() {
171: return attribCheckedDisplay;
172: }
173:
174: /**
175: * DOCUMENT ME!
176: *
177: * @return
178: */
179: public String getAttribCheckedValue() {
180: return attribCheckedValue;
181: }
182:
183: /**
184: * DOCUMENT ME!
185: *
186: * @param action
187: * @param isMandatory
188: *
189: * @return
190: */
191: public String getAttribClass(String action, boolean isMandatory) {
192: if (attribClass.equals("")) {
193: // Class is empty. Just return it.
194: return attribClass;
195: } else {
196: if (action.equals(UIScreenSection.ACTION_SHOW_QUERY)
197: || action
198: .equals(UIScreenSection.ACTION_SHOW_QUERY_REPORT)
199: || action
200: .equals(UIScreenSection.ACTION_SHOW_REPORT)) {
201: return attribClass + "Query";
202: } else if (isMandatory) {
203: return attribClass + "Mandatory";
204: } else {
205: return attribClass;
206: }
207: }
208: }
209:
210: /**
211: * DOCUMENT ME!
212: *
213: * @return
214: */
215: public String getAttribCols() {
216: return attribCols;
217: }
218:
219: /**
220: * DOCUMENT ME!
221: *
222: * @return
223: */
224: public String getAttribDisabled() {
225: return attribDisabled;
226: }
227:
228: /**
229: * DOCUMENT ME!
230: *
231: * @return
232: */
233: public String getAttribDisplayMask() {
234: return attribDisplayMask;
235: }
236:
237: /**
238: * DOCUMENT ME!
239: *
240: * @param action
241: *
242: * @return
243: */
244: public String getAttribEmptyFirst(String action) {
245: if (action.equals(UIScreenSection.ACTION_SHOW_QUERY)) {
246: return "Y";
247: } else {
248: return attribEmptyFirst;
249: }
250: }
251:
252: /**
253: * DOCUMENT ME!
254: *
255: * @return
256: */
257: public String getAttribEntity() {
258: return attribEntity;
259: }
260:
261: /**
262: * DOCUMENT ME!
263: *
264: * @return
265: */
266: public String getAttribEntityDisplayDef() {
267: return attribEntityDisplayDef;
268: }
269:
270: /**
271: * DOCUMENT ME!
272: *
273: * @return
274: */
275: public String getAttribEventHandling() {
276: return attribEventHandling;
277: }
278:
279: /**
280: * DOCUMENT ME!
281: *
282: * @return
283: */
284: public String getAttribEntityFindDef() {
285: return attribEntityFindDef;
286: }
287:
288: /**
289: * DOCUMENT ME!
290: *
291: * @return
292: */
293: public String getAttribEntityFindMethod() {
294: return attribEntityFindMethod;
295: }
296:
297: /**
298: * DOCUMENT ME!
299: *
300: * @return
301: */
302: public String getAttribEntityOrderDef() {
303: return attribEntityOrderDef;
304: }
305:
306: /**
307: * DOCUMENT ME!
308: *
309: * @return
310: */
311: public String getAttribEntityPkFindDef() {
312: return attribEntityPkFindDef;
313: }
314:
315: /**
316: * DOCUMENT ME!
317: *
318: * @return
319: */
320: public String getAttribEntityValueDef() {
321: return attribEntityValueDef;
322: }
323:
324: /**
325: * DOCUMENT ME!
326: *
327: * @return
328: */
329: public String getAttribEntitySearchDef() {
330: return attribEntitySearchDef;
331: }
332:
333: /**
334: * DOCUMENT ME!
335: *
336: * @return
337: */
338: public String getAttribFixedValues() {
339: return attribFixedValues;
340: }
341:
342: /**
343: * DOCUMENT ME!
344: *
345: * @return
346: */
347: public String getAttribFillMethod() {
348: return attribFillMethod;
349: }
350:
351: /**
352: * DOCUMENT ME!
353: *
354: * @return
355: */
356: public String getAttribMaxLength() {
357: return attribMaxLength;
358: }
359:
360: /**
361: * DOCUMENT ME!
362: *
363: * @return
364: */
365: public String getAttribRows() {
366: return attribRows;
367: }
368:
369: /**
370: * DOCUMENT ME!
371: *
372: * @return
373: */
374: public String getAttribSize() {
375: return attribSize;
376: }
377:
378: /**
379: * DOCUMENT ME!
380: *
381: * @return
382: */
383: public String getAttribReadOnly() {
384: return attribReadOnly;
385: }
386:
387: /**
388: * DOCUMENT ME!
389: *
390: * @return
391: */
392: public String getAttribUncheckedDisplay() {
393: return attribUncheckedDisplay;
394: }
395:
396: /**
397: * DOCUMENT ME!
398: *
399: * @return
400: */
401: public String getAttribUncheckedValue() {
402: return attribUncheckedValue;
403: }
404:
405: /**
406: * DOCUMENT ME!
407: *
408: * @return
409: */
410: public String getAttribWrap() {
411: return attribWrap;
412: }
413:
414: /**
415: * DOCUMENT ME!
416: *
417: * @return
418: */
419: public GenericDelegator getDelegator() {
420: return delegator;
421: }
422:
423: /**
424: * DOCUMENT ME!
425: *
426: * @param displayObjectId_
427: */
428: public void setDisplayObjectId(String displayObjectId_) {
429: displayObjectId = (displayObjectId_ == null) ? ""
430: : displayObjectId_;
431: }
432:
433: /**
434: * DOCUMENT ME!
435: *
436: * @param displayTypeId_
437: */
438: public void setDisplayTypeId(String displayTypeId_) {
439: displayTypeId = (displayTypeId_ == null) ? "" : displayTypeId_;
440: }
441:
442: /**
443: * DOCUMENT ME!
444: *
445: * @param attribAlign_
446: */
447: public void setAttribAlign(String attribAlign_) {
448: attribAlign = attribAlign_;
449: }
450:
451: /**
452: * DOCUMENT ME!
453: *
454: * @param attribAnchorHrefDef_
455: */
456: public void setAttribAnchorHrefDef(String attribAnchorHrefDef_) {
457: attribAnchorHrefDef = attribAnchorHrefDef_;
458: }
459:
460: /**
461: * DOCUMENT ME!
462: *
463: * @param attribAnchorTarget_
464: */
465: public void setAttribAnchorTarget(String attribAnchorTarget_) {
466: attribAnchorTarget = attribAnchorTarget_;
467: }
468:
469: /**
470: * DOCUMENT ME!
471: *
472: * @param attribCheckedDisplay_
473: */
474: public void setAttribCheckedDisplay(String attribCheckedDisplay_) {
475: attribCheckedDisplay = attribCheckedDisplay_;
476: }
477:
478: /**
479: * DOCUMENT ME!
480: *
481: * @param attribCheckedValue_
482: */
483: public void setAttribCheckedValue(String attribCheckedValue_) {
484: attribCheckedValue = attribCheckedValue_;
485: }
486:
487: /**
488: * DOCUMENT ME!
489: *
490: * @param attribClass_
491: */
492: public void setAttribClass(String attribClass_) {
493: attribClass = attribClass_;
494: }
495:
496: /**
497: * DOCUMENT ME!
498: *
499: * @param attribCols_
500: */
501: public void setAttribCols(String attribCols_) {
502: attribCols = attribCols_;
503: }
504:
505: /**
506: * DOCUMENT ME!
507: *
508: * @param attribDisabled_
509: */
510: public void setAttribDisabled(String attribDisabled_) {
511: attribDisabled = attribDisabled_;
512: }
513:
514: /**
515: * DOCUMENT ME!
516: *
517: * @param attribDisplayMask_
518: */
519: public void setAttribDisplayMask(String attribDisplayMask_) {
520: attribDisplayMask = attribDisplayMask_;
521: }
522:
523: /**
524: * DOCUMENT ME!
525: *
526: * @param attribEmptyFirst_
527: */
528: public void setAttribEmptyFirst(String attribEmptyFirst_) {
529: attribEmptyFirst = attribEmptyFirst_;
530: }
531:
532: /**
533: * DOCUMENT ME!
534: *
535: * @param attribEntity_
536: */
537: public void setAttribEntity(String attribEntity_) {
538: attribEntity = attribEntity_;
539: }
540:
541: /**
542: * DOCUMENT ME!
543: *
544: * @param attribEntityDisplayDef_
545: */
546: public void setAttribEntityDisplayDef(String attribEntityDisplayDef_) {
547: attribEntityDisplayDef = attribEntityDisplayDef_;
548: }
549:
550: /**
551: * DOCUMENT ME!
552: *
553: * @param attribEventHandling_
554: */
555: public void setAttribEventHandling(String attribEventHandling_) {
556: attribEventHandling = attribEventHandling_;
557: }
558:
559: /**
560: * DOCUMENT ME!
561: *
562: * @param attribEntityFindDef_
563: */
564: public void setAttribEntityFindDef(String attribEntityFindDef_) {
565: attribEntityFindDef = attribEntityFindDef_;
566: }
567:
568: /**
569: * DOCUMENT ME!
570: *
571: * @param attribEntityFindMethod_
572: */
573: public void setAttribEntityFindMethod(String attribEntityFindMethod_) {
574: attribEntityFindMethod = attribEntityFindMethod_;
575: }
576:
577: /**
578: * DOCUMENT ME!
579: *
580: * @param attribEntityOrderDef_
581: */
582: public void setAttribEntityOrderDef(String attribEntityOrderDef_) {
583: attribEntityOrderDef = attribEntityOrderDef_;
584: }
585:
586: /**
587: * DOCUMENT ME!
588: *
589: * @param attribEntityPkFindDef_
590: */
591: public void setAttribEntityPkFindDef(String attribEntityPkFindDef_) {
592: attribEntityPkFindDef = attribEntityPkFindDef_;
593: }
594:
595: /**
596: * DOCUMENT ME!
597: *
598: * @param attribEntityValueDef_
599: */
600: public void setAttribEntityValueDef(String attribEntityValueDef_) {
601: attribEntityValueDef = attribEntityValueDef_;
602: }
603:
604: /**
605: * DOCUMENT ME!
606: *
607: * @param attribEntitySearchDef_
608: */
609: public void setAttribEntitySearchDef(String attribEntitySearchDef_) {
610: attribEntitySearchDef = attribEntitySearchDef_;
611: }
612:
613: /**
614: * DOCUMENT ME!
615: *
616: * @param attribFixedValues_
617: */
618: public void setAttribFixedValues(String attribFixedValues_) {
619: attribFixedValues = attribFixedValues_;
620: }
621:
622: /**
623: * DOCUMENT ME!
624: *
625: * @param attribFillMethod_
626: */
627: public void setAttribFillMethod(String attribFillMethod_) {
628: attribFillMethod = attribFillMethod_;
629: }
630:
631: /**
632: * DOCUMENT ME!
633: *
634: * @param attribMaxLength_
635: */
636: public void setAttribMaxLength(String attribMaxLength_) {
637: attribMaxLength = attribMaxLength_;
638: }
639:
640: /**
641: * DOCUMENT ME!
642: *
643: * @param attribRows_
644: */
645: public void setAttribRows(String attribRows_) {
646: attribRows = attribRows_;
647: }
648:
649: /**
650: * DOCUMENT ME!
651: *
652: * @param attribSize_
653: */
654: public void setAttribSize(String attribSize_) {
655: attribSize = attribSize_;
656: }
657:
658: /**
659: * DOCUMENT ME!
660: *
661: * @param attribReadOnly_
662: */
663: public void setAttribReadOnly(String attribReadOnly_) {
664: attribReadOnly = attribReadOnly_;
665: }
666:
667: /**
668: * DOCUMENT ME!
669: *
670: * @param attribUncheckedDisplay_
671: */
672: public void setAttribUncheckedDisplay(String attribUncheckedDisplay_) {
673: attribUncheckedDisplay = attribUncheckedDisplay_;
674: }
675:
676: /**
677: * DOCUMENT ME!
678: *
679: * @param attribUncheckedValue_
680: */
681: public void setAttribUncheckedValue(String attribUncheckedValue_) {
682: attribUncheckedValue = attribUncheckedValue_;
683: }
684:
685: /**
686: * DOCUMENT ME!
687: *
688: * @param attribWrap_
689: */
690: public void setAttribWrap(String attribWrap_) {
691: attribWrap = attribWrap_;
692: }
693:
694: /**
695: * DOCUMENT ME!
696: *
697: * @param delegator_
698: */
699: public void setDelegator(GenericDelegator delegator_) {
700: delegator = delegator_;
701: }
702:
703: /**
704: * DOCUMENT ME!
705: *
706: * @throws GenericEntityException
707: */
708: public void loadAttributes() throws GenericEntityException {
709: if (attributesLoaded) {
710: return;
711: }
712:
713: UtilTimer timer = new UtilTimer();
714:
715: if (TIMER) {
716: timer.timerString(4,
717: "[UIDisplayObject.loadAttributes] Start");
718: }
719:
720: attributesLoaded = true;
721:
722: // Get all UI display object attributes' generic values from the database.
723: HashMap findMap = new HashMap();
724: findMap.put("displayObjectId", getDisplayObjectId());
725:
726: ArrayList order = new ArrayList();
727: order.add("displayAttribId");
728:
729: List uiDisplayObjectAttribL = getDelegator().findByAnd(
730: "UiDisplayObjectAttrib", findMap, order);
731: Iterator uiDisplayObjectAttribI = uiDisplayObjectAttribL
732: .iterator();
733:
734: while (uiDisplayObjectAttribI.hasNext()) {
735: GenericValue uiDisplayObjectAttribGV = (GenericValue) uiDisplayObjectAttribI
736: .next();
737: String displayAttribId = uiDisplayObjectAttribGV
738: .getString("displayAttribId");
739:
740: if (displayAttribId == null) {
741: displayAttribId = "";
742: }
743:
744: String attributeValue = uiDisplayObjectAttribGV
745: .getString("attributeValue");
746:
747: if (attributeValue == null) {
748: attributeValue = "";
749: }
750:
751: if (displayAttribId.equals("ALIGN")) {
752: setAttribAlign(attributeValue);
753: } else if (displayAttribId.equals("ANCHOR_HREF_DEF")) {
754: setAttribAnchorHrefDef(attributeValue);
755: } else if (displayAttribId.equals("ANCHOR_TARGET")) {
756: setAttribAnchorTarget(attributeValue);
757: } else if (displayAttribId.equals("CHECKED_DISPLAY")) {
758: setAttribCheckedDisplay(attributeValue);
759: } else if (displayAttribId.equals("CHECKED_VALUE")) {
760: setAttribCheckedValue(attributeValue);
761: } else if (displayAttribId.equals("CLASS")) {
762: setAttribClass(attributeValue);
763: } else if (displayAttribId.equals("COLS")) {
764: setAttribCols(attributeValue);
765: } else if (displayAttribId.equals("DISABLED")) {
766: setAttribDisabled(attributeValue);
767: } else if (displayAttribId.equals("DISPLAY_MASK")) {
768: setAttribDisplayMask(attributeValue);
769: } else if (displayAttribId.equals("EMPTY_FIRST")) {
770: setAttribEmptyFirst(attributeValue);
771: } else if (displayAttribId.equals("ENTITY")) {
772: setAttribEntity(attributeValue);
773: } else if (displayAttribId.equals("ENTITY_DISPLAY_DEF")) {
774: setAttribEntityDisplayDef(attributeValue);
775: } else if (displayAttribId.equals("EVENT_HANDLING")) {
776: setAttribEventHandling(attributeValue);
777: } else if (displayAttribId.equals("ENTITY_FIND_DEF")) {
778: setAttribEntityFindDef(attributeValue);
779: } else if (displayAttribId.equals("ENTITY_FIND_METHOD")) {
780: setAttribEntityFindMethod(attributeValue);
781: } else if (displayAttribId.equals("ENTITY_ORDER_DEF")) {
782: setAttribEntityOrderDef(attributeValue);
783: } else if (displayAttribId.equals("ENTITY_PK_FIND_DEF")) {
784: setAttribEntityPkFindDef(attributeValue);
785: } else if (displayAttribId.equals("ENTITY_VALUE_DEF")) {
786: setAttribEntityValueDef(attributeValue);
787: } else if (displayAttribId.equals("ENTITY_SEARCH_DEF")) {
788: setAttribEntitySearchDef(attributeValue);
789: } else if (displayAttribId.equals("FIXED_VALUES")) {
790: setAttribFixedValues(attributeValue);
791: } else if (displayAttribId.equals("FILL_METHOD")) {
792: setAttribFillMethod(attributeValue);
793: } else if (displayAttribId.equals("MAX_LENGTH")) {
794: setAttribMaxLength(attributeValue);
795: } else if (displayAttribId.equals("ROWS")) {
796: setAttribRows(attributeValue);
797: } else if (displayAttribId.equals("SIZE")) {
798: setAttribSize(attributeValue);
799: } else if (displayAttribId.equals("READ_ONLY")) {
800: setAttribReadOnly(attributeValue);
801: } else if (displayAttribId.equals("UNCHECKED_DISPLAY")) {
802: setAttribUncheckedDisplay(attributeValue);
803: } else if (displayAttribId.equals("UNCHECKED_VALUE")) {
804: setAttribUncheckedValue(attributeValue);
805: } else if (displayAttribId.equals("WRAP")) {
806: setAttribWrap(attributeValue);
807: }
808: }
809:
810: if (TIMER) {
811: timer
812: .timerString(4,
813: "[UIDisplayObject.loadAttributes] End");
814: }
815:
816: return;
817: }
818: }
|