Package com.sourcetap.sfa.ui

Source Code of com.sourcetap.sfa.ui.UIAttributeDropDown

/*
*
* 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.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.DynamicViewEntity;
import org.ofbiz.entity.model.ModelKeyMap;

import com.sourcetap.sfa.util.EntityHelper;
import com.sourcetap.sfa.util.UserInfo;


/**
* DOCUMENT ME!
*
*/
public class UIAttributeDropDown extends UIDropDown {
  public static final String module = UIAttributeDropDown.class.getName();

    public UIAttributeDropDown() {
    }

    /**
     * Return a list of values for a drop down using a UI Display Object defined in the data base.
     * This method overrides the parent class.  Note: This
     * method is only used when the screen is first drawn.  If the drop down list is updated dynamically, the
     * getDropDownValuesDynamic method is used.
     *
     * @see #getDropDownValuesDynamic(GenericDelegator, Map, UserInfo)
     *
     * @author John Nutting
     *
     * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
     * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
     * @param orderDef List of fields defining the sort order of the drop down values
     * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
     * @param fieldInfo Reference to field info object containing attributes of the current field
     * @param userInfo Reference to user info object containing information about the currently logged-in user
     *
     * @return List of generic values to be displayed in the drop down.  This will be null if an error occurs.
     */
    public List getDropDownValues(GenericDelegator delegator,
        UIDisplayObject uiDisplayObject, ArrayList orderDef,
        Vector entityDetailsVector, UIFieldInfo fieldInfo, UserInfo userInfo) {
        String sectionId = UIUtility.getAttributeValue(entityDetailsVector,
                "UiScreenSectionInfo", "sectionId");

        HashMap map = new HashMap();
        map.put("sectionId", sectionId);

        return getDropDownValuesDynamic(delegator, map, userInfo);
    }

    /**
     * Return a list of values based on filter criteria.  This is used by the dynamic filtered drop downs
     * which are modified via DHTML.  This method overrides the standard method.<BR><BR>Note: This method
     * is only used when the drop down is updated dynamically.
     * When the screen is first displayed, the getDropDownValues method is used.
     *
     * @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
     *
     * @author John Nutting
     *
     * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
     * @param filterValues Map containing field/value pairs to be used for filtering the drop down list
     * @param userInfo Reference to user info object containing information about the currently logged-in user
     *
     * @return List of generic values to be displayed in the drop down.  This will be null if an error occurs.
     */
    public List getDropDownValuesDynamic(GenericDelegator delegator,
        Map filterValues, UserInfo userInfo) {
        ArrayList orderBy = new ArrayList();
        orderBy.add("attributeName");

        ArrayList findClauses = new ArrayList();

        String sectionId = (String) filterValues.get("sectionId");

        if ((sectionId != null)) {

      // Find the last query used by this party ID for this screen section.
      // select X from ui_attribute a, ui_screen_section_entity sse where a.entity_id = sse.entity_id and sse.section_id = <sectionId> order by attribute_name
      DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "UiAttribute");
      dve.addMemberEntity("UiScreenSectionEntity", "UiScreenSectionEntity");
      dve.addViewLink("UiAttribute", "UiScreenSectionEntity", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("entityId", "entityId")));
      dve.addAlias("UiScreenSectionEntity", "sectionId", null, null, null, null, null);
    
      EntityCondition condition = new EntityConditionList(UtilMisc.toList(
          new EntityExpr("sectionId", EntityOperator.EQUALS, sectionId)),
          EntityOperator.AND);

            try {
                return EntityHelper.findByCondition( delegator, dve, condition, orderBy);
            } catch (GenericEntityException e) {
                Debug.logError(
                    "[UIAttributeDropDown.getDropDownValues] Error retrieving the dropdown values: ", module);
                Debug.logError(e.getLocalizedMessage(), module);

                return new LinkedList();
            }
        } else {
            try {
                return delegator.findAll("UiAttribute", orderBy);
            } catch (GenericEntityException e) {
                Debug.logError(
                    "[UIAttributeDropDown.getDropDownValues] Error retrieving the dropdown values: ", module);
                Debug.logError(e.getLocalizedMessage(), module);

                return new LinkedList();
            }
        }
    }
}
TOP

Related Classes of com.sourcetap.sfa.ui.UIAttributeDropDown

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.