Package com.sourcetap.sfa.ui

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

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

import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilTimer;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.model.ModelEntity;

import com.sourcetap.sfa.event.DataBuffer;
import com.sourcetap.sfa.event.DataMatrix;
import com.sourcetap.sfa.util.DelimitedPairDecoder;
import com.sourcetap.sfa.util.Preference;
import com.sourcetap.sfa.util.UserInfo;


/**
* DOCUMENT ME!
*
*/
public abstract class UIScreenSection {
  public static final String module = UIScreenSection.class.getName();
    private static final boolean TIMER = false;
    public static final int LAYOUT_TYPE_UNDEFINED = 0;
    public static final int LAYOUT_TYPE_FREEFORM = 1;
    public static final int LAYOUT_TYPE_TABULAR = 2;
    public static final int LAYOUT_TYPE_CROSSTAB = 3;
    public static final int LAYOUT_TYPE_SELECT = 4;
    public static final int LAYOUT_TYPE_COMPOSITE = 5;

    //  public static final int LAYOUT_TYPE_FREEFORM2 = 6;
    public static final String ACTION_BUTTON = "button";
    public static final String ACTION_COPY = "copy";
    public static final String ACTION_DELETE = "delete";
    public static final String ACTION_INSERT = "insert";
    public static final String ACTION_NONE = "none";
    public static final String ACTION_QUERY = "query";
    public static final String ACTION_QUERY_UPDATE = "queryUpdate";
    public static final String ACTION_QUERY_ALL = "queryAll";
    public static final String ACTION_UPDATE = "update";
    public static final String ACTION_UPDATE_SELECT = "updateSelect";
    public static final String ACTION_SHOW = "show";
    public static final String ACTION_SHOW_COPY = "showCopy";
    public static final String ACTION_SHOW_INSERT = "showInsert";
    public static final String ACTION_SHOW_QUERY = "showQuery";
    public static final String ACTION_SHOW_QUERY_REPORT = "showQueryReport";
    public static final String ACTION_SHOW_REPORT = "showReport";
    public static final String ACTION_SHOW_SELECT = "showSelect";
    public static final String ACTION_SHOW_UPDATE = "showUpdate";
    public static final String PREFERENCE_ROWS_PER_PAGE = "ROWS_PER_PAGE";
    protected int rowsPerPage = 0;
    protected String sectionId = "";
    protected String screenId = "";
    protected String sectionName = "";
    protected String sectionDescription = "";
    protected int layoutTypeId = 0;
    protected int displayOrder = 0;
    protected int columnCount = 0;
    protected int rowCount = 0;
    protected String buttonKeys = "";
    protected String sendQueryParameterList = "";
    protected String useQueryParameterList = "";
    protected HashMap sendQueryParameterMap = null;
    protected HashMap useQueryParameterMap = null;
    protected String titleDef = "";
    protected String sortDef = "";
    protected String searchAttributeId = "";
    protected String buttonAction = "";
    protected String buttonTarget = "";
    protected String detailButtonAction = "";
    protected String detailButtonTarget = "";
    protected String searchAction = "";
    protected String searchTarget = "";
    protected String newButtonAction = "";
    protected String newButtonTarget = "";
    protected String editButtonAction = "";
    protected String editButtonTarget = "";
    protected String hideButtons = "";
    protected String selectNameDef = "";
    protected boolean isUpdateable = false;
    protected UserInfo userInfo = null;
    protected GenericDelegator delegator;
    UIScreen uiScreen = null;
    List uiFieldList = new ArrayList();
    List uiScreenSectionEntityList = new ArrayList();

    public UIScreenSection(UserInfo userInfo, String screenName,
        String sectionName, GenericDelegator delegator, UICache uiCache)
        throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(1, "[UIScreenSection.UIScreenSection] Start");
        }

        Debug.logVerbose( "-->[UIScreenSection.UIScreenSection] screenName: " + screenName, module);
        Debug.logVerbose( "-->[UIScreenSection.UIScreenSection] sectionName: " + sectionName, module);

        if (userInfo == null) {
            throw new GenericEntityException(
                "UserInfo passed in was null for UIScreenSection.");
        } else {
            setUserInfo(userInfo);
        }

        if (delegator == null) {
            throw new GenericEntityException(
                "GenericDelegator passed in was null for UIScreenSection.");
        } else {
            setDelegator(delegator);
        }

        if (screenName == null) {
            throw new GenericEntityException(
                "ScreenName passed in was null for UIScreenSection.");
        }

        if (sectionName == null) {
            throw new GenericEntityException(
                "SectionName passed in was null for UIScreenSection.");
        }

        // Get the uiScreen object.
        if (TIMER) {
            timer.timerString(1,
                "[UIScreenSection.UIScreenSection] Looking for UIScreen in cache.");
        }

        UIScreen uiScreen = uiCache.getUiScreen(screenName);

        if (uiScreen == null) {
            if (TIMER) {
                timer.timerString(1,
                    "[UIScreenSection.UIScreenSection] UIScreen not found in cache. Creating a new one.");
            }

            uiScreen = new UIScreen(screenName, delegator);
            uiCache.putUiScreen(screenName, uiScreen);
        } else {
            if (TIMER) {
                timer.timerString(1,
                    "[UIScreenSection.UIScreenSection] Found UIScreen in cache.");
            }
        }

        setUiScreen(uiScreen);

        if (TIMER) {
            timer.timerString(1, "[UIScreenSection.UIScreenSection] Got screen");
        }

        // Get the uiScreenSection object.

        HashMap findHashMap = new HashMap();
        findHashMap.put("screenId", getUiScreen().getScreenId());
        findHashMap.put("sectionName", sectionName);

        List uiScreenSectionGVL = delegator.findByAnd("UiScreenSection",
                findHashMap, null);

        if (uiScreenSectionGVL.size() == 0) {
            throw new GenericEntityException("No screen section with name \"" +
                sectionName + "\" for screen \"" + screenName +
                "\" was found in database.");
        }

        if (uiScreenSectionGVL.size() > 1) {
            throw new GenericEntityException(
                "More than one screen section found with name \"" +
                sectionName + "\" for screen \"" + screenName + "\".");
        }

        Iterator uiScreenSectionGVI = uiScreenSectionGVL.iterator();
        GenericValue uiScreenSectionGV = (GenericValue) uiScreenSectionGVI.next();

        if (uiScreenSectionGV.get("layoutTypeId") == null) {
            throw new GenericEntityException(
                "Layout type not set for screen section \"" + sectionName +
                "\".");
        }

        setSectionId(uiScreenSectionGV.getString("sectionId"));
        setScreenId(uiScreenSectionGV.getString("screenId"));
        setSectionName(uiScreenSectionGV.getString("sectionName"));
        setSectionDescription(uiScreenSectionGV.getString("sectionDescription"));
        setLayoutTypeId(uiScreenSectionGV.getString("layoutTypeId"));
        setDisplayOrder(uiScreenSectionGV.getString("displayOrder"));
        setColumnCount(uiScreenSectionGV.getString("columnCount"));
        setRowCount(uiScreenSectionGV.getString("rowCount"));
        setButtonKeys(uiScreenSectionGV.getString("buttonKeys"));
        setTitleDef(uiScreenSectionGV.getString("titleDef"));
        setSortDef(uiScreenSectionGV.getString("sortDef"));
        setSearchAttributeId(uiScreenSectionGV.getString("searchAttributeId"));
        setButtonAction(uiScreenSectionGV.getString("buttonAction"));
        setButtonTarget(uiScreenSectionGV.getString("buttonTarget"));
        setDetailButtonAction(uiScreenSectionGV.getString("detailButtonAction"));
        setDetailButtonTarget(uiScreenSectionGV.getString("detailButtonTarget"));
        setSearchAction(uiScreenSectionGV.getString("searchAction"));
        setSearchTarget(uiScreenSectionGV.getString("searchTarget"));
        setNewButtonAction(uiScreenSectionGV.getString("newButtonAction"));
        setNewButtonTarget(uiScreenSectionGV.getString("newButtonTarget"));
        setEditButtonAction(uiScreenSectionGV.getString("editButtonAction"));
        setEditButtonTarget(uiScreenSectionGV.getString("editButtonTarget"));
        setHideButtons(uiScreenSectionGV.getString("hideButtons"));
        setSelectNameDef(uiScreenSectionGV.getString("selectNameDef"));
        setSendQueryParameterList(uiScreenSectionGV.getString("sendQueryParameterList"));
        setUseQueryParameterList(uiScreenSectionGV.getString("useQueryParameterList"));

        /* add after value added to screen settings
                        setRowsPerPage(uiScreenSectionGV.getString("rowsPerPage"));

        */
        rowsPerPage = 0;
        uiScreenSectionGVI = null;

        if (TIMER) {
            timer.timerString(1, "[UIScreenSection.UIScreenSection] Got section");
        }

        // if rowsPerPage = 0, then use the global prefernece ROWS_PER_PAGE.
        if (rowsPerPage <= 0) {
            Preference pref = Preference.getInstance(delegator);
            rowsPerPage = pref.getPreference(userInfo.getPartyId(),
                    userInfo.getAccountId(), PREFERENCE_ROWS_PER_PAGE, 20);
        }

        // Get the uiScreenSectionEntity entities.

        findHashMap = new HashMap();
        findHashMap.put("sectionId", getSectionId());

        ArrayList orderBy = new ArrayList();
        orderBy.add("retrieveOrder");

        List uiScreenSectionEntityGVL = delegator.findByAnd("UiScreenSectionEntity",
                findHashMap, orderBy);

        if ((uiScreenSectionEntityGVL == null) ||
                (uiScreenSectionEntityGVL.size() == 0)) {
            throw new GenericEntityException(
                "No screen section entities were found in database for screen section \"" +
                sectionName + "\" and screen \"" + screenName + "\".");
        }

        Iterator uiScreenSectionEntityGVI = uiScreenSectionEntityGVL.iterator();

        while (uiScreenSectionEntityGVI.hasNext()) {

            GenericValue uiScreenSectionEntityGV = (GenericValue) uiScreenSectionEntityGVI.next();
            String entityId = uiScreenSectionEntityGV.getString("entityId");

            if (TIMER) {
                timer.timerString(1,
                    "[UIScreenSection.UIScreenSection] Looking for a UIScreenSectionEntity in cache.");
            }

            UIScreenSectionEntity uiScreenSectionEntity = uiCache.getUiScreenSectionEntity(getSectionId(),
                    entityId);

            if (uiScreenSectionEntity == null) {
                if (TIMER) {
                    timer.timerString(1,
                        "[UIScreenSection.UIScreenSection] UIScreenSectionEntity not found in cache. Creating a new one.");
                }

                uiScreenSectionEntity = new UIScreenSectionEntity(uiScreenSectionEntityGV,
                        delegator, uiCache);
                uiCache.putUiScreenSectionEntity(getSectionId(), entityId,
                    uiScreenSectionEntity);
            } else {
                if (TIMER) {
                    timer.timerString(1,
                        "[UIScreenSection.UIScreenSection] Found UIScreenSectionEntity in cache.");
                }
            }

            uiScreenSectionEntityList.add(uiScreenSectionEntity);

            if (TIMER) {
                timer.timerString(1,
                    "[UIScreenSection.UIScreenSection] Got a UIScreenSectionEntity.");
            }

            if (uiScreenSectionEntity.getIsUpdateable()) {
                setIsUpdateable(true);
            }
        }

        uiScreenSectionEntityGVI = null; // Reset the iterator for next time.

        Debug.logVerbose("-->[UIScreenSection.UIScreenSection] Finished getting the UiScreenSectionEntity's for sectionId " + getSectionId(), module);
        Debug.logVerbose("-->[UIScreenSection.UIScreenSection] uiScreenSectionEntityList: " + uiScreenSectionEntityList.toString(), module);
    
        if (TIMER) {
            timer.timerString(1,
                "[UIScreenSection.UIScreenSection] Calling getDisplayFields");
        }

        setUiFieldList(getDisplayFields(uiCache));

        if (TIMER) {
            timer.timerString(1, "[UIScreenSection.UIScreenSection] End");
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param sectionId_
     */
    public void setSectionId(String sectionId_) {
        sectionId = (sectionId_ == null) ? "" : sectionId_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSectionId() {
        return sectionId;
    }

    /**
     * DOCUMENT ME!
     *
     * @param screenId_
     */
    public void setScreenId(String screenId_) {
        screenId = (screenId_ == null) ? "" : screenId_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getScreenId() {
        return screenId;
    }

    /**
     * DOCUMENT ME!
     *
     * @param sectionName_
     */
    public void setSectionName(String sectionName_) {
        sectionName = (sectionName_ == null) ? "" : sectionName_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSectionName() {
        return sectionName;
    }

    /**
     * DOCUMENT ME!
     *
     * @param sectionDescription_
     */
    public void setSectionDescription(String sectionDescription_) {
        sectionDescription = (sectionDescription_ == null) ? ""
                                                           : sectionDescription_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSectionDescription() {
        return sectionDescription;
    }

    /**
     * DOCUMENT ME!
     *
     * @param layoutTypeId_
     */
    public void setLayoutTypeId(int layoutTypeId_) {
        layoutTypeId = layoutTypeId_;
    }

    /**
     * DOCUMENT ME!
     *
     * @param layoutTypeId_
     */
    public void setLayoutTypeId(String layoutTypeId_) {
        layoutTypeId = (layoutTypeId_ == null) ? 0
                                               : Integer.valueOf(layoutTypeId_)
                                                        .intValue();
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public int getLayoutTypeId() {
        return layoutTypeId;
    }

    /**
     * DOCUMENT ME!
     *
     * @param displayOrder_
     */
    public void setDisplayOrder(int displayOrder_) {
        displayOrder = displayOrder_;
    }

    /**
     * DOCUMENT ME!
     *
     * @param displayOrder_
     */
    public void setDisplayOrder(String displayOrder_) {
        displayOrder = (displayOrder_ == null) ? 0
                                               : Integer.valueOf(displayOrder_)
                                                        .intValue();
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public int getDisplayOrder() {
        return displayOrder;
    }

    /**
     * DOCUMENT ME!
     *
     * @param columnCount_
     */
    public void setColumnCount(int columnCount_) {
        columnCount = columnCount_;
    }

    /**
     * DOCUMENT ME!
     *
     * @param columnCount_
     */
    public void setColumnCount(String columnCount_) {
        columnCount = (columnCount_ == null) ? 0
                                             : Integer.valueOf(columnCount_)
                                                      .intValue();
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public int getColumnCount() {
        return columnCount;
    }

    /**
     * DOCUMENT ME!
     *
     * @param rowCount_
     */
    public void setRowCount(int rowCount_) {
        rowCount = rowCount_;
    }

    /**
     * DOCUMENT ME!
     *
     * @param rowCount_
     */
    public void setRowCount(String rowCount_) {
        rowCount = (rowCount_ == null) ? 0 : Integer.valueOf(rowCount_)
                                                    .intValue();
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public int getRowCount() {
        return rowCount;
    }

    /**
     * DOCUMENT ME!
     *
     * @param rowsPerPage_
     */
    public void setRowsPerPage(int rowsPerPage_) {
        rowsPerPage = rowsPerPage_;
    }

    /**
     * DOCUMENT ME!
     *
     * @param rowsPerPage_
     */
    public void setRowsPerPage(String rowsPerPage_) {
        rowsPerPage = (rowsPerPage_ == null) ? 0
                                             : Integer.valueOf(rowsPerPage_)
                                                      .intValue();
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public int getRowsPerPage() {
        return rowsPerPage;
    }

    /**
     * DOCUMENT ME!
     *
     * @param buttonKeys_
     */
    public void setButtonKeys(String buttonKeys_) {
        buttonKeys = (buttonKeys_ == null) ? "" : buttonKeys_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getButtonKeys() {
        return buttonKeys;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public HashMap getButtonKeyMap() throws GenericEntityException {
        DelimitedPairDecoder buttonKeysDecoder = new DelimitedPairDecoder(getButtonKeys());
        HashMap buttonKeyMap = buttonKeysDecoder.decode();
        buttonKeysDecoder = null;

        return buttonKeyMap;
    }

    /**
     * DOCUMENT ME!
     *
     * @param sendQueryParameterList_
     */
    public void setSendQueryParameterList(String sendQueryParameterList_) {
        sendQueryParameterList = sendQueryParameterList_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSendQueryParameterList() {
        return sendQueryParameterList;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public HashMap getSendQueryParameterMap() throws GenericEntityException {
        DelimitedPairDecoder sendQueryParameterDecoder = new DelimitedPairDecoder(getSendQueryParameterList());
        HashMap sendQueryParameterMap = sendQueryParameterDecoder.decode();
        sendQueryParameterDecoder = null;

        return sendQueryParameterMap;
    }

    /**
     * DOCUMENT ME!
     *
     * @param sendQueryParameterMap_
     */
    public void setSendQueryParameterValueMap(HashMap sendQueryParameterMap_) {
        sendQueryParameterMap = sendQueryParameterMap_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public HashMap getSendQueryParameterValueMap() {
        return sendQueryParameterMap;
    }

    /**
     * DOCUMENT ME!
     *
     * @param useQueryParameterList_
     */
    public void setUseQueryParameterList(String useQueryParameterList_) {
        useQueryParameterList = useQueryParameterList_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getUseQueryParameterList() {
        return useQueryParameterList;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public HashMap getUseQueryParameterMap() throws GenericEntityException {
        DelimitedPairDecoder useQueryParameterDecoder = new DelimitedPairDecoder(getUseQueryParameterList());
        HashMap useQueryParameterMap = useQueryParameterDecoder.decode();
        useQueryParameterDecoder = null;

        return useQueryParameterMap;
    }

    /**
     * DOCUMENT ME!
     *
     * @param useQueryParameterMap_
     */
    public void setUseQueryParameterValueMap(HashMap useQueryParameterMap_) {
        useQueryParameterMap = useQueryParameterMap_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public HashMap getUseQueryParameterValueMap() {
        return useQueryParameterMap;
    }

    /**
     * DOCUMENT ME!
     *
     * @param titleDef_
     */
    public void setTitleDef(String titleDef_) {
        titleDef = (titleDef_ == null) ? "" : titleDef_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getTitleDef() {
        return titleDef;
    }

    /**
     * DOCUMENT ME!
     *
     * @param sortDef_
     */
    public void setSortDef(String sortDef_) {
        sortDef = (sortDef_ == null) ? "" : sortDef_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSortDef() {
        return sortDef;
    }

    /**
     * DOCUMENT ME!
     *
     * @param searchAttributeId_
     */
    public void setSearchAttributeId(String searchAttributeId_) {
        searchAttributeId = (searchAttributeId_ == null) ? "" : searchAttributeId_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSearchAttributeId() {
        return searchAttributeId;
    }

    /**
     * DOCUMENT ME!
     *
     * @param buttonAction_
     */
    public void setButtonAction(String buttonAction_) {
        buttonAction = (buttonAction_ == null) ? "" : buttonAction_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getButtonAction() {
        return buttonAction;
    }

    /**
     * DOCUMENT ME!
     *
     * @param buttonTarget_
     */
    public void setButtonTarget(String buttonTarget_) {
        buttonTarget = (buttonTarget_ == null) ? "" : buttonTarget_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getButtonTarget() {
        return buttonTarget;
    }

    /**
     * DOCUMENT ME!
     *
     * @param detailButtonAction_
     */
    public void setDetailButtonAction(String detailButtonAction_) {
        detailButtonAction = (detailButtonAction_ == null) ? ""
                                                           : detailButtonAction_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getDetailButtonAction() {
        return detailButtonAction;
    }

    /**
     * DOCUMENT ME!
     *
     * @param detailButtonTarget_
     */
    public void setDetailButtonTarget(String detailButtonTarget_) {
        detailButtonTarget = (detailButtonTarget_ == null) ? ""
                                                           : detailButtonTarget_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getDetailButtonTarget() {
        return detailButtonTarget;
    }

    /**
     * DOCUMENT ME!
     *
     * @param searchAction_
     */
    public void setSearchAction(String searchAction_) {
        searchAction = (searchAction_ == null) ? "" : searchAction_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSearchAction() {
        return searchAction;
    }

    /**
     * DOCUMENT ME!
     *
     * @param searchTarget_
     */
    public void setSearchTarget(String searchTarget_) {
        searchTarget = (searchTarget_ == null) ? "" : searchTarget_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSearchTarget() {
        return searchTarget;
    }

    /**
     * DOCUMENT ME!
     *
     * @param newButtonAction_
     */
    public void setNewButtonAction(String newButtonAction_) {
        newButtonAction = (newButtonAction_ == null) ? "" : newButtonAction_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getNewButtonAction() {
        return newButtonAction;
    }

    /**
     * DOCUMENT ME!
     *
     * @param newButtonTarget_
     */
    public void setNewButtonTarget(String newButtonTarget_) {
        newButtonTarget = (newButtonTarget_ == null) ? "" : newButtonTarget_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getNewButtonTarget() {
        return newButtonTarget;
    }

    /**
     * DOCUMENT ME!
     *
     * @param editButtonAction_
     */
    public void setEditButtonAction(String editButtonAction_) {
        editButtonAction = (editButtonAction_ == null) ? "" : editButtonAction_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getEditButtonAction() {
        return editButtonAction;
    }

    /**
     * DOCUMENT ME!
     *
     * @param editButtonTarget_
     */
    public void setEditButtonTarget(String editButtonTarget_) {
        editButtonTarget = (editButtonTarget_ == null) ? "" : editButtonTarget_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getEditButtonTarget() {
        return editButtonTarget;
    }

    /**
     * DOCUMENT ME!
     *
     * @param hideButtons_
     */
    public void setHideButtons(String hideButtons_) {
        hideButtons = (hideButtons_ == null) ? "" : hideButtons_.toLowerCase();
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getHideButtons() {
        return hideButtons;
    }

    /**
     * DOCUMENT ME!
     *
     * @param selectNameDef_
     */
    public void setSelectNameDef(String selectNameDef_) {
        selectNameDef = (selectNameDef_ == null) ? "" : selectNameDef_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public String getSelectNameDef() {
        return selectNameDef;
    }

    /**
     * DOCUMENT ME!
     *
     * @param isUpdateable_
     */
    public void setIsUpdateable(boolean isUpdateable_) {
        isUpdateable = isUpdateable_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public boolean getIsUpdateable() {
        return isUpdateable;
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator_
     */
    public void setDelegator(GenericDelegator delegator_) {
        delegator = delegator_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public GenericDelegator getDelegator() {
        return delegator;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo_
     */
    public void setUserInfo(UserInfo userInfo_) {
        userInfo = userInfo_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public UserInfo getUserInfo() {
        return userInfo;
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiScreen_
     */
    public void setUiScreen(UIScreen uiScreen_) {
        uiScreen = uiScreen_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public UIScreen getUiScreen() {
        return uiScreen;
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiFieldList_
     */
    public void setUiFieldList(List uiFieldList_) {
        uiFieldList = uiFieldList_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public List getUiFieldList() {
        return uiFieldList;
    }

    /**
     * DOCUMENT ME!
     *
     * @param fieldNumber
     *
     * @return
     */
    public UIFieldInfo getUiField(int fieldNumber) {
        return (UIFieldInfo) uiFieldList.get(fieldNumber);
    }

    /**
     * DOCUMENT ME!
     *
     * @param entityName
     * @param attributeName
     *
     * @return
     */
    public UIFieldInfo getUiField(String entityName, String attributeName) {
        for (int fieldNbr = 0; fieldNbr < uiFieldList.size(); fieldNbr++) {
            UIFieldInfo uiFieldInfo = getUiField(fieldNbr);

            if (uiFieldInfo.getUiAttribute().getUiEntity().getEntityName()
                               .equals(entityName) &&
                    uiFieldInfo.getUiAttribute().getAttributeName().equals(attributeName)) {
                return uiFieldInfo;
            }
        }

        return null;
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiScreenSectionEntityList_
     */
    public void setUiScreenSectionEntityList(List uiScreenSectionEntityList_) {
        uiScreenSectionEntityList = uiScreenSectionEntityList_;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public List getUiScreenSectionEntityList() {
        return uiScreenSectionEntityList;
    }

    /**
     * DOCUMENT ME!
     *
     * @param entityNumber
     *
     * @return
     */
    public UIScreenSectionEntity getUiScreenSectionEntity(int entityNumber) {
        return (UIScreenSectionEntity) uiScreenSectionEntityList.get(entityNumber);
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     */
    public Vector getEntityParamVector() {

        // Construct a vector of info about the entities in this screen section to be
        // passed to the data matrix so it will be independent of the UI.
        Vector entityParamVector = new Vector();
        int entityCount = getUiScreenSectionEntityList().size();

        for (int entityNbr = 0; entityNbr < entityCount; entityNbr++) {
            UIEntity uiEntity = getUiScreenSectionEntity(entityNbr).getUiEntity();
            String entityName = uiEntity.getEntityName();
            Vector attributeVector = new Vector();

            for (int attributeNbr = 0;
                    attributeNbr < uiEntity.getUiAttributeList().size();
                    attributeNbr++) {
                String attributeName = uiEntity.getUiAttribute(attributeNbr)
                                               .getAttributeName();
                attributeVector.add(attributeName);
            }

            Boolean hasSequenceKey = new Boolean(getUiScreenSectionEntity(
                        entityNbr).getHasSequenceKey());
            Boolean isUpdateable = new Boolean(getUiScreenSectionEntity(
                        entityNbr).getIsUpdateable());
            HashMap parameterMap = new HashMap();
            parameterMap.put("entityName", entityName);
            parameterMap.put("attributeVector", attributeVector);
            parameterMap.put("hasSequenceKey", hasSequenceKey);
            parameterMap.put("isUpdateable", isUpdateable);
            entityParamVector.add(parameterMap);
        }

        return entityParamVector;
    }

    /**
     * DOCUMENT ME!
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public List getEntityNameList() throws GenericEntityException {
        List entityNameList = new LinkedList();
        Iterator uiScreenSectionEntityI = getUiScreenSectionEntityList()
                                              .iterator();

        while (uiScreenSectionEntityI.hasNext()) {
            UIScreenSectionEntity uiScreenSectionEntity = (UIScreenSectionEntity) uiScreenSectionEntityI.next();
            entityNameList.add(uiScreenSectionEntity.getUiEntity()
                                                    .getEntityName());
        }

        return entityNameList;
    }

    /**
     * DOCUMENT ME!
     *
     * @param dataMatrix
     * @param action
     * @param queryId
     * @param isSubsection
     * @param tabOffset
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public String display(DataMatrix dataMatrix, String action, String queryId,
        boolean isSubsection, int tabOffset) throws GenericEntityException {

        if ((getLayoutTypeId() == LAYOUT_TYPE_FREEFORM) &&
                ((dataMatrix.getCurrentBuffer().getContents() == null) ||
                (dataMatrix.getCurrentBuffer().getContents().size() < 1))) {
            // This is a free form section, and there is no data. Create an empty entity so the section will show up.

            dataMatrix.getCurrentBuffer().addEmptyRow();
        }

        //    Vector genericValueVector = dataMatrix.getCurrentBuffer().getContentsRow(0);
        //    GenericValue primaryEntityGV = dataMatrix.getCurrentBuffer().getGenericValue(0, 0);
        String primaryEntityTitle = "";

        if ((dataMatrix.getCurrentBuffer().getContents() == null) ||
                (dataMatrix.getCurrentBuffer().getContents().size() < 1)) {
            // No rows in data matrix.  Set the title using an empty string.
            DataBuffer tempBuffer = new DataBuffer(delegator, dataMatrix);
            primaryEntityTitle = UIWebUtility.decodeEntityDisplayDef(titleDef,
                    tempBuffer.createEmptyRow(), "");
        } else {
            // There is data in the data matrix.  Use the first row to set the title.
            primaryEntityTitle = UIWebUtility.decodeEntityDisplayDef(titleDef,
                    dataMatrix.getCurrentBuffer().getContentsRow(0), "");
        }

        String titleBar = ((primaryEntityTitle != null) ? primaryEntityTitle : "");

        switch (getLayoutTypeId()) {
        case LAYOUT_TYPE_FREEFORM:
            return displayFreeFormSection(dataMatrix, action,
                getFreeFormSectionTitle(action, titleBar), isSubsection,
                tabOffset);

        case LAYOUT_TYPE_TABULAR:
            return displayTabularSection(dataMatrix, action, titleBar, queryId);

        case LAYOUT_TYPE_CROSSTAB:
            throw new GenericEntityException(
                "Crosstab layout type not implemented yet.");

        case LAYOUT_TYPE_SELECT:
            return displaySelectSection(dataMatrix, action, titleBar, queryId);

        case LAYOUT_TYPE_COMPOSITE:

            //        return displayCompositeSection(
            //          dataMatrix,
            //          action,
            //          titleBar,
            //          queryId);
            throw new GenericEntityException(
                "Composite layout type not implemented yet.");

        default:
            throw new GenericEntityException("Invalid layout type.");
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param dataMatrix
     * @param action
     * @param sectionTitle
     * @param isSubsection
     * @param tabOffset
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public abstract String displayFreeFormSection(DataMatrix dataMatrix,
        String action, String sectionTitle, boolean isSubsection, int tabOffset)
        throws GenericEntityException;

    /**
     * DOCUMENT ME!
     *
     * @param dataMatrix
     * @param action
     * @param sectionTitle
     * @param queryId
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public abstract String displayTabularSection(DataMatrix dataMatrix,
        String action, String sectionTitle, String queryId)
        throws GenericEntityException;

    /**
     * DOCUMENT ME!
     *
     * @param action
     * @param sectionTitle
     * @param queryId
     * @param rows
     * @param sendQueryParams
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public abstract String displayTabularSectionHeader(String action,
        String sectionTitle, String queryId, int rows, String sendQueryParams)
        throws GenericEntityException;

    /**
     * DOCUMENT ME!
     *
     * @param row
     * @param rows
     * @param entityDetailsVector
     * @param action
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public abstract String displayTabularSectionRow(int row, int rows,
        Vector entityDetailsVector, String action)
        throws GenericEntityException;

    /**
     * DOCUMENT ME!
     *
     * @param action
     * @param sendQueryParams
     *
     * @return
     */
    public abstract String displayTabularSectionFooter(String action,
        String sendQueryParams, String queryId);

    /**
     * DOCUMENT ME!
     *
     * @param dataMatrix
     * @param action
     * @param sectionTitle
     * @param queryId
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public abstract String displaySelectSection(DataMatrix dataMatrix,
        String action, String sectionTitle, String queryId)
        throws GenericEntityException;

    /**
     * DOCUMENT ME!
     *
     * @param fieldInfo
     * @param entityDetailsVector
     * @param action
     * @param row
     * @param isSubsection
     * @param tabOffset
     *
     * @return
     */
    public abstract String displayField(UIFieldInfo fieldInfo,
        Vector entityDetailsVector, String action, int row,
        boolean isSubsection, int tabOffset);

    /**
     * DOCUMENT ME!
     *
     * @param uiCache
     *
     * @return
     *
     * @throws GenericEntityException
     */
    public List getDisplayFields(UICache uiCache) throws GenericEntityException {
        UtilTimer timer = new UtilTimer();

        if (TIMER) {
            timer.timerString(2, "[UIScreenSection.getDisplayFields] Start");
        }

        ArrayList uiFields = new ArrayList();
        boolean gotFields = false;

        // Get the primary key names for the primary entity.
        UIScreenSectionEntity primaryUiScreenSectionEntity = (UIScreenSectionEntity) (getUiScreenSectionEntityList()
                                                                                          .get(0));
        UIEntity primaryUiEntity = primaryUiScreenSectionEntity.getUiEntity();
        String primaryEntityName = primaryUiEntity.getEntityName();
        ModelEntity primaryModelEntity = primaryUiScreenSectionEntity.getUiEntity()
                                                                     .getModelEntity();
        List primaryPrimaryKeyFieldNameList = primaryModelEntity.getPkFieldNames();

        boolean[] primaryKeyIncluded = new boolean[20];

        for (int keyFieldNbr = 0;
                keyFieldNbr < primaryPrimaryKeyFieldNameList.size();
                keyFieldNbr++) {
            primaryKeyIncluded[keyFieldNbr] = false;
        }

        for (int i = 0; i < 3; i++) {
            String partyId = getUserInfo().getPartyId();

            if (i == 1) {
                partyId = getUserInfo().getAccountId(); //search for the company settings the second time through the loop
            }

            if (i == 2) {
                partyId = "-1"; //search for default party the last time through the loop
            }

            HashMap findMap = new HashMap();
            findMap.put("sectionId", sectionId);
            findMap.put("partyId", partyId);

            ArrayList orderBy = new ArrayList();
            orderBy.add("displayOrder");

            List uiFieldInfoL = getDelegator().findByAnd("UiScreenSectionInfo",
                    findMap, orderBy);

            int numRows = 0;

            Iterator uiFieldInfoI = uiFieldInfoL.iterator();

            while (uiFieldInfoI.hasNext()) {
                numRows++;

                GenericValue uiScreenSectionInfoGV = (GenericValue) uiFieldInfoI.next();
                int displayOrder = (uiScreenSectionInfoGV.get("displayOrder") == null)
                    ? 0
                    : Integer.valueOf(uiScreenSectionInfoGV.getString(
                            "displayOrder")).intValue();

                if (displayOrder > 0) {
                    // Only fields with display order > 0 get displayed.
                    String attributeId = (uiScreenSectionInfoGV.getString(
                            "attributeId") == null) ? ""
                                                    : uiScreenSectionInfoGV.getString(
                            "attributeId");

                    if (TIMER) {
                        timer.timerString(2,
                            "[UIScreenSection.getDisplayFields] Processing field with attribute ID " +
                            attributeId);
                    }

                    if (TIMER) {
                        timer.timerString(1,
                            "[UIScreenSection.getDisplayFields] Looking for UIScreenSectionInfo in cache.");
                    }

                    UIFieldInfo uiFieldInfo = uiCache.getUiFieldInfo(sectionId,
                            partyId, attributeId);

                    if (uiFieldInfo == null) {
                        if (TIMER) {
                            timer.timerString(1,
                                "[UIScreenSection.getDisplayFields] UIScreenSectionInfo not found in cache. Creating a new one.");
                        }

                        uiFieldInfo = new UIFieldInfo(uiScreenSectionInfoGV,
                                getDelegator(), uiCache);
                        uiCache.putUiFieldInfo(sectionId, partyId, attributeId,
                            uiFieldInfo);
                    } else {
                        if (TIMER) {
                            timer.timerString(1,
                                "[UIScreenSection.getDisplayFields] Found UIScreenSectionInfo in cache.");
                        }
                    }

                    uiFields.add(uiFieldInfo);

                    String attributeName = uiFieldInfo.getUiAttribute()
                                                      .getAttributeName();

                    for (int keyFieldNbr = 0;
                            keyFieldNbr < primaryPrimaryKeyFieldNameList.size();
                            keyFieldNbr++) {
                        if (attributeName.equals(
                                    primaryPrimaryKeyFieldNameList.get(
                                        keyFieldNbr))) {
                            primaryKeyIncluded[keyFieldNbr] = true;
                        }
                    }
                }
            }

            if (numRows > 0) {
                break;
            }
        }

        // Make sure all the primary key fields of the primary entity were included.
        for (int keyFieldNbr = 0;
                keyFieldNbr < primaryPrimaryKeyFieldNameList.size();
                keyFieldNbr++) {
            if (!primaryKeyIncluded[keyFieldNbr]) {
                throw new GenericEntityException(
                    "[UIScreenSection.getDisplayFields]: All primary key fields of the primary entity must be included in the field list.");
            }
        }

        if (TIMER) {
            timer.timerString(2, "[UIScreenSection.getDisplayFields] End");
        }

        return uiFields;
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiFields
     *
     * @return
     */
    public static List getDisplayLabels(List uiFields) {
        List fields = new ArrayList();

        for (int i = 0; i < uiFields.size(); i++) {
            UIFieldInfo fldInfo = (UIFieldInfo) uiFields.get(i);
            fields.add(fldInfo.getDisplayLabel());
        }

        return fields;
    }

    /**
     * DOCUMENT ME!
     *
     * @param uiFields
     *
     * @return
     */
    public static int getRowWidth(List uiFields) {
        int width = 0;

        for (int i = 0; i < uiFields.size(); i++) {
            UIFieldInfo fldInfo = (UIFieldInfo) uiFields.get(i);

            if (fldInfo.getIsVisible()) {
                width += fldInfo.getDisplayLength();
            }
        }

        return width;
    }

    /**
     * DOCUMENT ME!
     *
     * @param action
     * @param defaultTitle
     *
     * @return
     */
    public String getFreeFormSectionTitle(String action, String defaultTitle) {
        if (action.equals(ACTION_SHOW_INSERT) ||
                action.equals(ACTION_SHOW_COPY) ||
                action.equals(ACTION_DELETE)) {
            //      return "New " + getUiScreenSectionEntity(0).getUiEntity().getDescription();
            return defaultTitle + " New";
        } else if (action.equals(ACTION_SHOW_QUERY)) {
            //      return getUiScreenSectionEntity(0).getUiEntity().getDescription() + " Query";
            return defaultTitle + " Query";
        } else {
            return defaultTitle;
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param action
     *
     * @return
     */
    public String getNextAction(String action) {

        String nextAction = "";

        if (action.equals(ACTION_INSERT)) {
            // A record was just inserted.  The screen will be displayed in read only mode this time, so the Save
            // button won't be visible.  No action will be required for the Save button.
            nextAction = ACTION_NONE;
        } else if (action.equals(ACTION_DELETE)) {
            // A record was just deleted.  The screen will be displayed in insert mode this time,
            // so next time Save is pushed, need to insert a new record, and then show the screen in update mode.
            nextAction = ACTION_INSERT;
        } else if (action.equals(ACTION_QUERY)) {
            // A query was just executed.  The screen will be displayed in read only mode this time, so the Save
            // button won't be visible.  No action will be required for the Save button.
            nextAction = ACTION_NONE;
        } else if (action.equals(ACTION_QUERY_UPDATE)) {
            // A query was just executed.  The screen will be displayed in update mode this time,
            // so next time Save is pushed, need to update and then show the screen in update mode the next time.
            nextAction = ACTION_UPDATE;
        } else if (action.equals(ACTION_SHOW_COPY)) {
            // The Copy button was just pushed.  The screen will be displayed in insert mode this time,
            // so next time Save is pushed, need to insert a new record, and then show the screen in update mode.
            nextAction = ACTION_INSERT;
        } else if (action.equals(ACTION_SHOW_INSERT)) {
            // The Insert button was just pushed.  The screen will be displayed in insert mode this time,
            // so next time Save is pushed, need to insert a new record, and then show the screen in update mode.
            nextAction = ACTION_INSERT;
        } else if (action.equals(ACTION_SHOW_QUERY)) {
            // The Query button was just pushed.  The screen will be displayed in query mode this time,
            // so next time Save is pushed, need to execute the query, and show the query results in read only mode.
            nextAction = ACTION_QUERY;
        } else if (action.equals(ACTION_SHOW_QUERY_REPORT)) {
            // The menu item for a report was just pushed.  The screen will be displayed in query_report mode this time,
            // and the Save button will submit the form with a next action of ACTION_SHOW_REPORT to show the report results.
            nextAction = ACTION_SHOW_REPORT;
        } else if (action.equals(ACTION_SHOW_REPORT)) {
            // A report was just displayed.  The screen will be displayed in query report mode again this time so the user
            // can change the criteria and re-submit the report.  The Save button will submit the form with a next action
            // of ACTION_SHOW_REPORT to show the report results again next time.
            nextAction = ACTION_SHOW_REPORT;
        } else if (action.equals(ACTION_SHOW_SELECT)) {
            // The Select button was just pushed.  The screen will be displayed in select mode this time,
            // so next time Save is pushed, need to update and then show screen in select mode again.
            nextAction = ACTION_UPDATE_SELECT;
        } else if (action.equals(ACTION_SHOW_UPDATE)) {
            // The screen will be displayed in update mode this time,
            // so next time Save is pushed, need to update and then show the screen in update mode the next time.
            nextAction = ACTION_UPDATE;
        } else if (action.equals(ACTION_UPDATE)) {
            // A record was just updated.  The screen will be displayed in read only mode this time, so the Save
            // button won't be visible.  No action will be required for the Save button.
            nextAction = ACTION_NONE;
        } else if (action.equals(ACTION_UPDATE_SELECT)) {
            // Select list was saved last time.  The screen will be displayed in select mode this time.
            // If the user pushes Save next time, need to update and put screen in select mode again.
            nextAction = ACTION_UPDATE_SELECT;
        }

        return nextAction;
    }

    /**
     * DOCUMENT ME!
     *
     * @param action
     *
     * @return
     */
    public boolean getProtect(String action) {
        if (action.equals(ACTION_SHOW) || action.equals(ACTION_INSERT) ||
                action.equals(ACTION_UPDATE) || action.equals(ACTION_QUERY) ||
                action.equals("") || (action == null)) {
            return true;
        } else {
            return false;
        }
    }
}
TOP

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

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.