📄 datamatrix.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.event;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
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.GenericPK;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityComparisonOperator;
import com.sourcetap.sfa.ui.UIDisplayObject;
import com.sourcetap.sfa.ui.UIFieldInfo;
import com.sourcetap.sfa.ui.UIScreenSection;
import com.sourcetap.sfa.ui.UIScreenSectionEntity;
import com.sourcetap.sfa.ui.UIWebUtility;
import com.sourcetap.sfa.util.DelimitedPairDecoder;
import com.sourcetap.sfa.util.DelimitedValueDecoder;
import com.sourcetap.sfa.util.QueryInfo;
import com.sourcetap.sfa.util.StringHelper;
import com.sourcetap.sfa.util.UserInfo;
/**
* DOCUMENT ME!
*
*/
public class DataMatrix {
public static final String module = DataMatrix.class.getName();
private static final boolean TIMER = false;
protected DataBuffer currentBuffer = null;
protected DataBuffer originalBuffer = null;
protected ArrayList deleteFlags = new ArrayList();
protected Vector entityParamVector = null;
protected GenericDelegator delegator = null;
protected int rowCount = 0;
public DataMatrix(GenericDelegator delegator, Vector entityParamVector) {
setDelegator(delegator);
currentBuffer = new DataBuffer(delegator, this);
originalBuffer = new DataBuffer(delegator, this);
setEntityParamVector(entityParamVector);
}
/**
* DOCUMENT ME!
*
* @return
*/
public DataBuffer getCurrentBuffer() {
return currentBuffer;
}
/**
* DOCUMENT ME!
*
* @return
*/
public DataBuffer getOriginalBuffer() {
return originalBuffer;
}
/**
* DOCUMENT ME!
*
* @param isDeleted
*/
public void addDeleteFlag(boolean isDeleted) {
deleteFlags.add(new Boolean(isDeleted));
}
/**
* DOCUMENT ME!
*
* @return
*/
public Vector getEntityParamVector() {
return entityParamVector;
}
/**
* DOCUMENT ME!
*
* @param entityParamVector_
*/
public void setEntityParamVector(Vector entityParamVector_) {
entityParamVector = entityParamVector_;
}
/**
* DOCUMENT ME!
*
* @param entityName
* @param hasSequenceKey
* @param isUpdateable
*/
public void addEntity(String entityName, boolean hasSequenceKey,
boolean isUpdateable) {
// Vector attributeVector = new Vector();
// for (int attributeNbr = 0; attributeNbr < uiEntity.getUiAttributeList().size(); attributeNbr++) {
// String attributeName = uiEntity.getUiAttribute(attributeNbr).getAttributeName();
// attributeVector.add(attributeName);
// }
HashMap parameterMap = new HashMap();
parameterMap.put("entityName", entityName);
parameterMap.put("attributeVector", new Vector());
parameterMap.put("hasSequenceKey", new Boolean(hasSequenceKey));
parameterMap.put("isUpdateable", new Boolean(isUpdateable));
Debug.logVerbose("[DataMatrix.addEntity] parameterMap: " +
parameterMap.toString(), module);
Debug.logVerbose("[DataMatrix.addEntity] entityParamVector: " +
entityParamVector.toString(), module);
getEntityParamVector().add(parameterMap);
}
/**
* DOCUMENT ME!
*
* @param entityNbr
*
* @return
*/
public String getEntityName(int entityNbr) {
HashMap parameterMap = (HashMap) getEntityParamVector().get(entityNbr);
String entityName = (String) parameterMap.get("entityName");
return entityName;
}
/**
* DOCUMENT ME!
*
* @param entityNbr
*
* @return
*/
public boolean getHasSequenceKey(int entityNbr) {
HashMap parameterMap = (HashMap) getEntityParamVector().get(entityNbr);
Boolean hasSequenceKey = (Boolean) parameterMap.get("hasSequenceKey");
return hasSequenceKey.booleanValue();
}
/**
* DOCUMENT ME!
*
* @param entityNbr
*
* @return
*/
public boolean getIsUpdateable(int entityNbr) {
HashMap parameterMap = (HashMap) getEntityParamVector().get(entityNbr);
Boolean isUpdateable = (Boolean) parameterMap.get("isUpdateable");
return isUpdateable.booleanValue();
}
/**
* DOCUMENT ME!
*
* @param entityNbr
*
* @return
*/
public Vector getAttributeVector(int entityNbr) {
HashMap parameterMap = (HashMap) getEntityParamVector().get(entityNbr);
Vector attributeVector = (Vector) parameterMap.get("attributeVector");
return attributeVector;
}
/**
* DOCUMENT ME!
*
* @param entityNbr
* @param attributeNbr
*
* @return
*/
public String getAttributeName(int entityNbr, int attributeNbr) {
HashMap parameterMap = (HashMap) getEntityParamVector().get(entityNbr);
Vector attributeVector = (Vector) parameterMap.get("attributeVector");
String attributeName = (String) attributeVector.get(attributeNbr);
return attributeName;
}
/**
* DOCUMENT ME!
*
* @return
*/
public Vector getEntityNameVector() {
Vector entityNameVector = new Vector();
for (int entityNbr = 0; entityNbr < getEntityParamVector().size();
entityNbr++) {
entityNameVector.add(getEntityName(entityNbr));
}
return entityNameVector;
}
/**
* DOCUMENT ME!
*
* @return
*/
public GenericDelegator getDelegator() {
return delegator;
}
/**
* DOCUMENT ME!
*
* @param delegator_
*/
public void setDelegator(GenericDelegator delegator_) {
delegator = delegator_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public int getRowCount() {
return rowCount;
}
/**
* DOCUMENT ME!
*
* @param rowCount_
*/
public void setRowCount(int rowCount_) {
rowCount = rowCount_;
}
//-------------------------------------------------------------------------
// Put values from the screen into the value matrix
//-------------------------------------------------------------------------
public int fillFromHtml(HttpServletRequest request,
UIScreenSection uiScreenSection) throws GenericEntityException {
UtilTimer utilTimer = new UtilTimer();
if (TIMER) {
utilTimer.timerString(3, "[DataMatrix.fillFromHTML] Start");
}
// Get the row count.
if (request.getParameter("rowCount") == null) {
throw new GenericEntityException(
"rowCount parameter not found in request object.");
}
if (request.getParameter("rowCount").equals("")) {
throw new GenericEntityException(
"rowCount parameter is empty in request object.");
}
try {
setRowCount(Integer.valueOf(request.getParameter("rowCount"))
.intValue());
} catch (NumberFormatException e) {
throw new GenericEntityException(
"rowCount parameter in request object does not contain a number.");
}
for (int row = 0; row < getRowCount(); row++) {
// Create an array list of empty generic values to hold the values from the screen for one row.
addRowFromHTML(row, request, uiScreenSection);
}
if (TIMER) {
utilTimer.timerString(3, "[DataMatrix.fillFromHTML] End");
}
return getRowCount();
}
/**
* DOCUMENT ME!
*
* @param row
* @param request
* @param uiScreenSection
*
* @throws GenericEntityException
*/
public void addRowFromHTML(int row, HttpServletRequest request,
UIScreenSection uiScreenSection) throws GenericEntityException {
UtilTimer utilTimer = new UtilTimer();
if (TIMER) {
utilTimer.timerString(4, "[DataMatrix.addRowFromHTML] Start");
}
// Create an empty row to be updated and stored in the current and original buffers.
Vector currentRow = getCurrentBuffer().createEmptyRow();
// Vector originalRow = (Vector)currentRow.clone(); -- This didn't really create a new object. It caused
// all operations on originalRow to be done on the currentRow also.
Vector originalRow = getOriginalBuffer().createEmptyRow();
// Loop through the entities and attributes for the current screen section, and get the value
// from the request object for each one, and store it in the contents.
for (int entityNbr = 0; entityNbr < getEntityParamVector().size();
entityNbr++) {
String entityName = getEntityName(entityNbr);
if (TIMER) {
utilTimer.timerString(4,
"[DataMatrix.addRowFromHTML] Start processing entity " +
String.valueOf(entityNbr) + " (" + entityName + ")");
}
// Get references to the orginal and current generic values for this entity.
GenericValue currentGV = (GenericValue) (currentRow.get(entityNbr));
GenericValue originalGV = (GenericValue) (originalRow.get(entityNbr));
// Process each attribute for this entity.
for (int attributeNbr = 0;
attributeNbr < getAttributeVector(entityNbr).size();
attributeNbr++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -