📄 uilist.java
字号:
/*
*
* 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.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityComparisonOperator;
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.ModelEntity;
import org.ofbiz.entity.util.EntityListIterator;
import com.sourcetap.sfa.event.EventUtility;
import com.sourcetap.sfa.event.GenericEventProcessor;
import com.sourcetap.sfa.replication.GenericReplicator;
import com.sourcetap.sfa.security.SecurityLinkInfo;
import com.sourcetap.sfa.security.SecurityWrapper;
import com.sourcetap.sfa.util.QueryInfo;
import com.sourcetap.sfa.util.UserInfo;
public class UIList {
public static final String module = UIList.class.getName();
protected boolean primaryFieldsLoaded = false;
protected boolean relatedFieldsLoaded = false;
protected List primaryFields = null;
protected List relatedFields = null;
protected String listId = null;
protected String listName = null;
/**
* @return Returns the detailSectionId.
*/
public String getDetailSectionId() {
return detailSectionId;
}
/**
* @param detailSectionId The detailSectionId to set.
*/
public void setDetailSectionId(String detailSectionId) {
this.detailSectionId = detailSectionId;
}
/**
* @return Returns the listSectionId.
*/
public String getListSectionId() {
return listSectionId;
}
/**
* @param listSectionId The listSectionId to set.
*/
public void setListSectionId(String listSectionId) {
this.listSectionId = listSectionId;
}
protected String listSectionId = null;
protected String detailSectionId = null;
protected String partyId = null;
protected String queryId = null;
protected String listType = null;
protected List reportFields = null;
protected List reportCriteria = null;
protected List reportOrderBy = null;
private List selectFieldLabels = null;
private List selectFieldNames = null;
protected GenericDelegator delegator = null;
protected QueryInfo queryInfo = null;
protected GenericEventProcessor eventProcessor = null;
public UIList(GenericDelegator delegator_)
{
setDelegator(delegator_);
}
public UIList(String listId_, GenericDelegator delegator_)
{
setDelegator(delegator_);
loadList(listId_);
}
public void loadList(String listId_)
{
try
{
GenericValue listGV = delegator.findByPrimaryKey("UiList", UtilMisc.toMap("listId", listId_));
if ( listGV == null )
throw new IllegalArgumentException("Unable to find report with ID " + listId_ );
setListId(listId_);
setPartyId(listGV.getString("partyId"));
setListName(listGV.getString("listName"));
// the query was save with the screen section for the LIST screen section. Get the corresponding detail screen section
// which will have a more complete list of fields to choose from
String listSectionId = listGV.getString("sectionId");
String detailSectionId = listSectionId;
setListSectionId(listSectionId);
GenericValue sectionGV = delegator.findByPrimaryKey("UiScreenSection", UtilMisc.toMap("sectionId", listSectionId));
GenericValue screenGV = delegator.findByPrimaryKey("UiScreen", UtilMisc.toMap("screenId", sectionGV.getString("screenId")));
detailSectionId = screenGV.getString("detailSectionId");
if ( ( detailSectionId == null ) || (detailSectionId.length() < 1) )
detailSectionId = listSectionId;
setDetailSectionId(detailSectionId);
} catch (GenericEntityException e)
{
Debug.logError("Error getting report: " + e.getMessage(), module);
e.printStackTrace();
}
}
public void saveReport(String partyId, String listName)
{
setPartyId(partyId);
if ( !listName.equals(getListName()))
{
setListName(listName);
setListId(null);
}
saveList();
}
public void saveList()
{
try
{
String listId = getListId();
if ( listId == null )
{
listId = GenericReplicator.getNextSeqId("UiList", delegator);
setListId(listId);
}
else
{
// TODO need to delete old report info
}
List valuesToStore = new ArrayList();
GenericValue listGV = new GenericValue(delegator.getModelEntity("UiList"));
listGV.setDelegator(delegator);
listGV.set("listId", listId);
listGV.set("sectionId", getListSectionId());
listGV.set("partyId", getPartyId());
listGV.set("listName", getListName());
listGV.set("queryId", getQueryId());
listGV.set("listType", getListType());
valuesToStore.add(listGV);
delegator.storeAll(valuesToStore);
} catch (GenericEntityException e)
{
e.printStackTrace();
Debug.logError("error saving list" + e.getMessage(), module);
}
}
public static boolean deleteList(String listId, GenericDelegator delegator)
{
try
{
List valuesToBeRemoved = new ArrayList();
GenericValue gv = new GenericValue(delegator.getModelEntity("UiListItem"));
gv.set("listId", listId);
valuesToBeRemoved.add(gv);
gv = new GenericValue(delegator.getModelEntity("UiList"));
gv.set("listId", listId);
valuesToBeRemoved.add(gv);
delegator.removeAll(valuesToBeRemoved);
} catch (GenericEntityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
Debug.logError("unable to delete list: " + listId + " error:" + e.getMessage(), module);
return false;
}
return true;
}
public static List getLists(String companyId, String partyId, GenericDelegator delegator)
{
return getLists(null, companyId, partyId, delegator);
}
public static List getLists(String sectionId, String companyId, String partyId, GenericDelegator delegator)
{
try
{
Map condition = sectionId == null ? UtilMisc.toMap("partyId", "-1") : UtilMisc.toMap("sectionId", sectionId, "partyId", "-1");
List orderBy = UtilMisc.toList("reportName");
List reportList = delegator.findByAnd("UiReport", condition, orderBy);
if ( !partyId.equals("-1")) {
EntityCondition c1 = new EntityConditionList( UtilMisc.toList( new EntityExpr("partyId", EntityOperator.EQUALS, partyId),
new EntityExpr("partyId", EntityOperator.EQUALS, companyId)), EntityOperator.OR);
if ( sectionId != null )
c1 = new EntityConditionList( UtilMisc.toList( c1, new EntityExpr("sectionId", EntityOperator.EQUALS, sectionId)), EntityOperator.AND);
if ( reportList == null)
reportList = delegator.findByCondition("UiList", c1, null, orderBy);
else
reportList.addAll(delegator.findByCondition("UiList", c1, null, orderBy));
}
return reportList;
} catch (GenericEntityException e)
{
Debug.logError("Error getting reportList: " + e.getMessage(), module);
e.printStackTrace();
}
return null;
}
public List loadPrimarySectionFields()
{
try
{
List primaryFields = getDelegator().findByAnd("UiScreenSectionFields",
UtilMisc.toMap("sectionId", getDetailSectionId()),
UtilMisc.toList("displayOrder"));
setPrimaryFields(primaryFields);
return primaryFields;
} catch (GenericEntityException e)
{
Debug.logError("Unable to get Primary Screen Fields:" + e.getMessage(), module);
return null;
}
}
public List loadRelatedSectionQueryFields()
{
try
{
List relatedFields = getDelegator().findByAnd("UiRelatedSectionQueryFields",
UtilMisc.toMap("sectionId", getDetailSectionId(), "useInAdvancedQueries", "Y", "isSearchable", "Y"),
UtilMisc.toList("relatedSectionId", "displayOrder"));
setRelatedFields(relatedFields);
return relatedFields;
} catch (GenericEntityException e)
{
Debug.logError("Unable to get Related Screen Fields:" + e.getMessage(), module);
return null;
}
}
public String getSelectListAvailableOptions()
{
if (detailSectionId == null)
throw new IllegalArgumentException("section ID must be set before calling getConditionHtml");
StringBuffer displayHtml = new StringBuffer(5000);
List fieldList = getPrimaryFields();
int fieldListSize = fieldList.size();
StringBuffer fieldNameOptions = new StringBuffer(200);
// fieldNameOptions.append("<option value=''></option>");
for (int fieldNbr = 0; fieldNbr < fieldListSize; fieldNbr++) {
GenericValue fieldInfo = (GenericValue) fieldList.get(fieldNbr);
String isVisible = UtilFormatOut.checkNull(fieldInfo.getString("isVisible"));
if ( isVisible.equals("Y")) {
String htmlName = UIWebUtility.getHtmlName(fieldInfo.getString("sectionName"), fieldInfo.getString("entityName"), fieldInfo.getString("attributeName"),0);
String displayObjectId = fieldInfo.getString("displayObjectId");
String displayTypeId = fieldInfo.getString("displayTypeId");
String attributeId = fieldInfo.getString("attributeId");
String displayLabel = fieldInfo.getString("displayLabel");
String optValue = htmlName + ";" + attributeId + ";" + displayTypeId + ";" + displayObjectId + ";" + displayLabel;
fieldNameOptions.append("<option value='" + optValue + "'>" + displayLabel + "</option>");
}
}
List extendedFields = getRelatedFields();
if ( extendedFields != null )
{
int numFields = extendedFields.size();
for ( int i=0; i < numFields; i++)
{
GenericValue fieldInfo = (GenericValue) extendedFields.get(i);
String entityName = fieldInfo.getString("entityName");
String attributeId = fieldInfo.getString("attributeId");
String attributeName = fieldInfo.getString("attributeName");
String displayObjectId = fieldInfo.getString("displayObjectId");
String displayTypeId = fieldInfo.getString("displayTypeId");
String sectionName = fieldInfo.getString("sectionName");
String sectionDescription = fieldInfo.getString("sectionDescription");
String displayLabel = fieldInfo.getString("displayLabel");
String htmlName = UIWebUtility.getHtmlName( sectionName, entityName, attributeName, 0 );
String optValue = htmlName + ";" + attributeId + ";" + displayTypeId + ";" + displayObjectId + ";" + displayLabel;
displayLabel = sectionDescription + "." + displayLabel;
fieldNameOptions.append("<option value='" + optValue + "'>" + displayLabel + "</option>");
}
}
return fieldNameOptions.toString();
}
public boolean loadQueryInfo(HttpServletRequest request, HttpServletResponse response, UICache uiCache)
{
try
{
List primaryFields = loadPrimarySectionFields();
List uiScreenSectionEntityGVL = delegator.findByAnd("UiScreenSectionEntity",
UtilMisc.toMap("sectionId", detailSectionId), UtilMisc.toList("retrieveOrder"));
UIScreenSectionEntity primaryEntity = new UIScreenSectionEntity((GenericValue) uiScreenSectionEntityGVL.get(0), delegator, uiCache);
GenericValue screenSectionGV = delegator.findByPrimaryKey("UiScreenSection", UtilMisc.toMap("sectionId", detailSectionId));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -