/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.ui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.ofbiz.base.util.UtilTimer;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.model.ModelEntity;
/**
* DOCUMENT ME!
*
*/
public class UIDisplayObject {
public static final String module = UIDisplayObject.class.getName();
private static final boolean TIMER = false;
public static final String DISPLAY_TYPE_CHECKBOX = "CHECKBOX";
public static final String DISPLAY_TYPE_CURRENCY = "CURRENCY";
public static final String DISPLAY_TYPE_DATE = "DATE";
public static final String DISPLAY_TYPE_DATETIME = "DATETIME";
public static final String DISPLAY_TYPE_HIDDEN = "HIDDEN";
public static final String DISPLAY_TYPE_NUMBER = "NUMBER";
public static final String DISPLAY_TYPE_PERCENT = "PERCENT";
public static final String DISPLAY_TYPE_SEARCH_TEXT = "SEARCH_TEXT";
public static final String DISPLAY_TYPE_SELECT = "SELECT";
public static final String DISPLAY_TYPE_TEXT = "TEXT";
public static final String DISPLAY_TYPE_TEXTAREA = "TEXTAREA";
public static final String DISPLAY_TYPE_TIME = "TIME";
public static final String DISPLAY_TYPE_FILE = "FILE";
protected String displayObjectId = "";
protected String displayTypeId = "";
protected String attribAlign = "";
protected String attribAnchorHrefDef = "";
protected String attribAnchorTarget = "";
protected String attribCheckedDisplay = "Yes";
protected String attribCheckedValue = "Y";
protected String attribClass = "";
protected String attribCols = "";
protected String attribDisabled = "";
protected String attribDisplayMask = "";
protected String attribEmptyFirst = "";
protected String attribEntity = "";
protected String attribEntityDisplayDef = "";
protected String attribEventHandling = "";
protected String attribEntityFindDef = "";
protected String attribEntityFindMethod = "";
protected String attribEntityOrderDef = "";
protected String attribEntityPkFindDef = "";
protected String attribEntityValueDef = "";
protected String attribEntitySearchDef = "";
protected String attribFixedValues = "";
protected String attribFillMethod = "";
protected String attribMaxLength = "";
protected String attribRows = "";
protected String attribSize = "";
protected String attribReadOnly = "";
protected String attribUncheckedDisplay = "No";
protected String attribUncheckedValue = "N";
protected String attribWrap = "";
protected GenericDelegator delegator = null;
protected boolean attributesLoaded = false;
public UIDisplayObject(String displayObjectId, GenericDelegator delegator)
throws GenericEntityException {
UtilTimer timer = new UtilTimer();
if (TIMER) {
timer.timerString(3, "[UIDisplayObject.UIDisplayObject] Start");
}
// Get the UI display object generic value from the database.
ModelEntity uiDisplayObjectEntity = delegator.getModelEntity(
"UiDisplayObject");
HashMap findMap = new HashMap();
findMap.put("displayObjectId", displayObjectId);
GenericPK uiDisplayObjectPK = new GenericPK(uiDisplayObjectEntity,
findMap);
GenericValue uiDisplayObjectGV = delegator.findByPrimaryKey(uiDisplayObjectPK);
if (uiDisplayObjectGV == null) {
throw new GenericEntityException(
"No display object was found with ID " + displayObjectId);
}
setDisplayObjectId(displayObjectId);
setDisplayTypeId(uiDisplayObjectGV.getString("displayTypeId"));
setDelegator(delegator);
if (TIMER) {
timer.timerString(3, "[UIDisplayObject.UIDisplayObject] End");
}
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getDisplayObjectId() {
return displayObjectId;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getDisplayTypeId() {
return displayTypeId;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribAlign() {
return attribAlign;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribAnchorHrefDef() {
return attribAnchorHrefDef;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribAnchorTarget() {
return attribAnchorTarget;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribCheckedDisplay() {
return attribCheckedDisplay;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribCheckedValue() {
return attribCheckedValue;
}
/**
* DOCUMENT ME!
*
* @param action
* @param isMandatory
*
* @return
*/
public String getAttribClass(String action, boolean isMandatory) {
if (attribClass.equals("")) {
// Class is empty. Just return it.
return attribClass;
} else {
if (action.equals(UIScreenSection.ACTION_SHOW_QUERY) ||
action.equals(UIScreenSection.ACTION_SHOW_QUERY_REPORT) ||
action.equals(UIScreenSection.ACTION_SHOW_REPORT)) {
return attribClass + "Query";
} else if (isMandatory) {
return attribClass + "Mandatory";
} else {
return attribClass;
}
}
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribCols() {
return attribCols;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribDisabled() {
return attribDisabled;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribDisplayMask() {
return attribDisplayMask;
}
/**
* DOCUMENT ME!
*
* @param action
*
* @return
*/
public String getAttribEmptyFirst(String action) {
if (action.equals(UIScreenSection.ACTION_SHOW_QUERY)) {
return "Y";
} else {
return attribEmptyFirst;
}
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEntity() {
return attribEntity;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEntityDisplayDef() {
return attribEntityDisplayDef;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEventHandling() {
return attribEventHandling;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEntityFindDef() {
return attribEntityFindDef;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEntityFindMethod() {
return attribEntityFindMethod;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEntityOrderDef() {
return attribEntityOrderDef;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEntityPkFindDef() {
return attribEntityPkFindDef;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEntityValueDef() {
return attribEntityValueDef;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribEntitySearchDef() {
return attribEntitySearchDef;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribFixedValues() {
return attribFixedValues;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribFillMethod() {
return attribFillMethod;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribMaxLength() {
return attribMaxLength;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribRows() {
return attribRows;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribSize() {
return attribSize;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribReadOnly() {
return attribReadOnly;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribUncheckedDisplay() {
return attribUncheckedDisplay;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribUncheckedValue() {
return attribUncheckedValue;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getAttribWrap() {
return attribWrap;
}
/**
* DOCUMENT ME!
*
* @return
*/
public GenericDelegator getDelegator() {
return delegator;
}
/**
* DOCUMENT ME!
*
* @param displayObjectId_
*/
public void setDisplayObjectId(String displayObjectId_) {
displayObjectId = (displayObjectId_ == null) ? "" : displayObjectId_;
}
/**
* DOCUMENT ME!
*
* @param displayTypeId_
*/
public void setDisplayTypeId(String displayTypeId_) {
displayTypeId = (displayTypeId_ == null) ? "" : displayTypeId_;
}
/**
* DOCUMENT ME!
*
* @param attribAlign_
*/
public void setAttribAlign(String attribAlign_) {
attribAlign = attribAlign_;
}
/**
* DOCUMENT ME!
*
* @param attribAnchorHrefDef_
*/
public void setAttribAnchorHrefDef(String attribAnchorHrefDef_) {
attribAnchorHrefDef = attribAnchorHrefDef_;
}
/**
* DOCUMENT ME!
*
* @param attribAnchorTarget_
*/
public void setAttribAnchorTarget(String attribAnchorTarget_) {
attribAnchorTarget = attribAnchorTarget_;
}
/**
* DOCUMENT ME!
*
* @param attribCheckedDisplay_
*/
public void setAttribCheckedDisplay(String attribCheckedDisplay_) {
attribCheckedDisplay = attribCheckedDisplay_;
}
/**
* DOCUMENT ME!
*
* @param attribCheckedValue_
*/
public void setAttribCheckedValue(String attribCheckedValue_) {
attribCheckedValue = attribCheckedValue_;
}
/**
* DOCUMENT ME!
*
* @param attribClass_
*/
public void setAttribClass(String attribClass_) {
attribClass = attribClass_;
}
/**
* DOCUMENT ME!
*
* @param attribCols_
*/
public void setAttribCols(String attribCols_) {
attribCols = attribCols_;
}
/**
* DOCUMENT ME!
*
* @param attribDisabled_
*/
public void setAttribDisabled(String attribDisabled_) {
attribDisabled = attribDisabled_;
}
/**
* DOCUMENT ME!
*
* @param attribDisplayMask_
*/
public void setAttribDisplayMask(String attribDisplayMask_) {
attribDisplayMask = attribDisplayMask_;
}
/**
* DOCUMENT ME!
*
* @param attribEmptyFirst_
*/
public void setAttribEmptyFirst(String attribEmptyFirst_) {
attribEmptyFirst = attribEmptyFirst_;
}
/**
* DOCUMENT ME!
*
* @param attribEntity_
*/
public void setAttribEntity(String attribEntity_) {
attribEntity = attribEntity_;
}
/**
* DOCUMENT ME!
*
* @param attribEntityDisplayDef_
*/
public void setAttribEntityDisplayDef(String attribEntityDisplayDef_) {
attribEntityDisplayDef = attribEntityDisplayDef_;
}
/**
* DOCUMENT ME!
*
* @param attribEventHandling_
*/
public void setAttribEventHandling(String attribEventHandling_) {
attribEventHandling = attribEventHandling_;
}
/**
* DOCUMENT ME!
*
* @param attribEntityFindDef_
*/
public void setAttribEntityFindDef(String attribEntityFindDef_) {
attribEntityFindDef = attribEntityFindDef_;
}
/**
* DOCUMENT ME!
*
* @param attribEntityFindMethod_
*/
public void setAttribEntityFindMethod(String attribEntityFindMethod_) {
attribEntityFindMethod = attribEntityFindMethod_;
}
/**
* DOCUMENT ME!
*
* @param attribEntityOrderDef_
*/
public void setAttribEntityOrderDef(String attribEntityOrderDef_) {
attribEntityOrderDef = attribEntityOrderDef_;
}
/**
* DOCUMENT ME!
*
* @param attribEntityPkFindDef_
*/
public void setAttribEntityPkFindDef(String attribEntityPkFindDef_) {
attribEntityPkFindDef = attribEntityPkFindDef_;
}
/**
* DOCUMENT ME!
*
* @param attribEntityValueDef_
*/
public void setAttribEntityValueDef(String attribEntityValueDef_) {
attribEntityValueDef = attribEntityValueDef_;
}
/**
* DOCUMENT ME!
*
* @param attribEntitySearchDef_
*/
public void setAttribEntitySearchDef(String attribEntitySearchDef_) {
attribEntitySearchDef = attribEntitySearchDef_;
}
/**
* DOCUMENT ME!
*
* @param attribFixedValues_
*/
public void setAttribFixedValues(String attribFixedValues_) {
attribFixedValues = attribFixedValues_;
}
/**
* DOCUMENT ME!
*
* @param attribFillMethod_
*/
public void setAttribFillMethod(String attribFillMethod_) {
attribFillMethod = attribFillMethod_;
}
/**
* DOCUMENT ME!
*
* @param attribMaxLength_
*/
public void setAttribMaxLength(String attribMaxLength_) {
attribMaxLength = attribMaxLength_;
}
/**
* DOCUMENT ME!
*
* @param attribRows_
*/
public void setAttribRows(String attribRows_) {
attribRows = attribRows_;
}
/**
* DOCUMENT ME!
*
* @param attribSize_
*/
public void setAttribSize(String attribSize_) {
attribSize = attribSize_;
}
/**
* DOCUMENT ME!
*
* @param attribReadOnly_
*/
public void setAttribReadOnly(String attribReadOnly_) {
attribReadOnly = attribReadOnly_;
}
/**
* DOCUMENT ME!
*
* @param attribUncheckedDisplay_
*/
public void setAttribUncheckedDisplay(String attribUncheckedDisplay_) {
attribUncheckedDisplay = attribUncheckedDisplay_;
}
/**
* DOCUMENT ME!
*
* @param attribUncheckedValue_
*/
public void setAttribUncheckedValue(String attribUncheckedValue_) {
attribUncheckedValue = attribUncheckedValue_;
}
/**
* DOCUMENT ME!
*
* @param attribWrap_
*/
public void setAttribWrap(String attribWrap_) {
attribWrap = attribWrap_;
}
/**
* DOCUMENT ME!
*
* @param delegator_
*/
public void setDelegator(GenericDelegator delegator_) {
delegator = delegator_;
}
/**
* DOCUMENT ME!
*
* @throws GenericEntityException
*/
public void loadAttributes() throws GenericEntityException {
if (attributesLoaded) {
return;
}
UtilTimer timer = new UtilTimer();
if (TIMER) {
timer.timerString(4, "[UIDisplayObject.loadAttributes] Start");
}
attributesLoaded = true;
// Get all UI display object attributes' generic values from the database.
HashMap findMap = new HashMap();
findMap.put("displayObjectId", getDisplayObjectId());
ArrayList order = new ArrayList();
order.add("displayAttribId");
List uiDisplayObjectAttribL = getDelegator().findByAnd("UiDisplayObjectAttrib",
findMap, order);
Iterator uiDisplayObjectAttribI = uiDisplayObjectAttribL.iterator();
while (uiDisplayObjectAttribI.hasNext()) {
GenericValue uiDisplayObjectAttribGV = (GenericValue) uiDisplayObjectAttribI.next();
String displayAttribId = uiDisplayObjectAttribGV.getString(
"displayAttribId");
if (displayAttribId == null) {
displayAttribId = "";
}
String attributeValue = uiDisplayObjectAttribGV.getString(
"attributeValue");
if (attributeValue == null) {
attributeValue = "";
}
if (displayAttribId.equals("ALIGN")) {
setAttribAlign(attributeValue);
} else if (displayAttribId.equals("ANCHOR_HREF_DEF")) {
setAttribAnchorHrefDef(attributeValue);
} else if (displayAttribId.equals("ANCHOR_TARGET")) {
setAttribAnchorTarget(attributeValue);
} else if (displayAttribId.equals("CHECKED_DISPLAY")) {
setAttribCheckedDisplay(attributeValue);
} else if (displayAttribId.equals("CHECKED_VALUE")) {
setAttribCheckedValue(attributeValue);
} else if (displayAttribId.equals("CLASS")) {
setAttribClass(attributeValue);
} else if (displayAttribId.equals("COLS")) {
setAttribCols(attributeValue);
} else if (displayAttribId.equals("DISABLED")) {
setAttribDisabled(attributeValue);
} else if (displayAttribId.equals("DISPLAY_MASK")) {
setAttribDisplayMask(attributeValue);
} else if (displayAttribId.equals("EMPTY_FIRST")) {
setAttribEmptyFirst(attributeValue);
} else if (displayAttribId.equals("ENTITY")) {
setAttribEntity(attributeValue);
} else if (displayAttribId.equals("ENTITY_DISPLAY_DEF")) {
setAttribEntityDisplayDef(attributeValue);
} else if (displayAttribId.equals("EVENT_HANDLING")) {
setAttribEventHandling(attributeValue);
} else if (displayAttribId.equals("ENTITY_FIND_DEF")) {
setAttribEntityFindDef(attributeValue);
} else if (displayAttribId.equals("ENTITY_FIND_METHOD")) {
setAttribEntityFindMethod(attributeValue);
} else if (displayAttribId.equals("ENTITY_ORDER_DEF")) {
setAttribEntityOrderDef(attributeValue);
} else if (displayAttribId.equals("ENTITY_PK_FIND_DEF")) {
setAttribEntityPkFindDef(attributeValue);
} else if (displayAttribId.equals("ENTITY_VALUE_DEF")) {
setAttribEntityValueDef(attributeValue);
} else if (displayAttribId.equals("ENTITY_SEARCH_DEF")) {
setAttribEntitySearchDef(attributeValue);
} else if (displayAttribId.equals("FIXED_VALUES")) {
setAttribFixedValues(attributeValue);
} else if (displayAttribId.equals("FILL_METHOD")) {
setAttribFillMethod(attributeValue);
} else if (displayAttribId.equals("MAX_LENGTH")) {
setAttribMaxLength(attributeValue);
} else if (displayAttribId.equals("ROWS")) {
setAttribRows(attributeValue);
} else if (displayAttribId.equals("SIZE")) {
setAttribSize(attributeValue);
} else if (displayAttribId.equals("READ_ONLY")) {
setAttribReadOnly(attributeValue);
} else if (displayAttribId.equals("UNCHECKED_DISPLAY")) {
setAttribUncheckedDisplay(attributeValue);
} else if (displayAttribId.equals("UNCHECKED_VALUE")) {
setAttribUncheckedValue(attributeValue);
} else if (displayAttribId.equals("WRAP")) {
setAttribWrap(attributeValue);
}
}
if (TIMER) {
timer.timerString(4, "[UIDisplayObject.loadAttributes] End");
}
return;
}
}