⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uientityeventprocessor.java

📁 国外的一套开源CRM
💻 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.customization;

import java.util.Iterator;

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

import com.sourcetap.sfa.event.DataMatrix;
import com.sourcetap.sfa.event.GenericEventProcessor;
import com.sourcetap.sfa.replication.GenericReplicator;
import com.sourcetap.sfa.util.StringHelper;
import com.sourcetap.sfa.util.UserInfo;


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

	private static String displayObjectText20 = "1";
	private static String displayObjectText60 = "2";
	private static String displayObjectDateTime = "17";
	private static String displayObjectDate = "18";
	private static String displayObjectTime = "19";
	private static String displayObjectCheckbox = "41";
	private static String displayObjectCurrency = "25";
	private static String displayObjectNumber = "26";
	private static String displayObjectSelectUser = "21";
	private static String displayObjectText255 = "34";
	private static String displayObjectTextArea = "55";
	
    /**
     * Create the default UIAttribute values by copying from fields from the Table Definition
     *
     * @param userInfo 
     * @param delegator 
     * @param dataMatrix 
     *
     * @return 
     */
    protected int postInsert(UserInfo userInfo, GenericDelegator delegator,
        DataMatrix dataMatrix) {

        // Get the current values.
        GenericValue uiEntityGV = dataMatrix.getCurrentBuffer()
                                                   .getGenericValue(0, 0);
		String entityId = uiEntityGV.getString("entityId");
		String entityName = uiEntityGV.getString("entityName");
		
		if ( ( entityId == null ) || ( entityName == null ) )
			return STATUS_CONTINUE;

		ModelEntity me = delegator.getModelEntity(entityName);
		if ( me == null)
			return STATUS_CONTINUE;

		ModelEntity uiAttributeME = delegator.getModelEntity("UiAttribute");
		
		Iterator fieldI = me.getFieldsIterator();
		int displayOrder = 0;
		
		while ( fieldI.hasNext())
		{
			ModelField fld = (ModelField) fieldI.next();
			
			String attrName = fld.getName();
			String colName  = fld.getName();
			String type = fld.getType();
			boolean isPK = fld.getIsPk();
			
			String displayType = "";
			String maxLength = "20";
			String editMask = "";
			String displayLogic = "";
			boolean isMandatory = fld.getIsPk();
			boolean isReadOnly = false;
			boolean isVisible = true;
			boolean isSearchable = true;
			boolean isExtension = false;
			displayOrder += 10;
			String displayLabel = StringHelper.javaNameToDescription(attrName);
			int colSpan = 1;
			int rowSpan = 1;
			boolean startOnNewRow = false;
			String displayObjectId = "0";
				
				
			if ( attrName.equals("createdBy") || attrName.equals("modifiedBy"))
			{
				displayObjectId = displayObjectSelectUser;
				maxLength = "60";
				
			}
			else if ( type.equals("date-time"))
			{
				displayObjectId = displayObjectDateTime;
			}
			else if ( type.equals("time"))
			{
				displayObjectId = displayObjectTime;
			}
			else if ( type.equals("date"))
			{
				displayObjectId = displayObjectDate;
			}
			else if ( type.equals("currency-amount"))
			{
				displayObjectId = displayObjectCurrency;	
			}
			else if ( type.equals("floating-point") || type.equals("numeric"))
			{
				displayObjectId = displayObjectNumber;
			}
			else if ( type.equals("id") || type.equals("id-ne"))
			{
				displayObjectId = displayObjectText20;
			}
			else if ( type.equals("id-long") || type.equals("short-varchar") || type.equals("id-long-ne") || type.equals("tel-number") )
			{
				displayObjectId = displayObjectText60;
				maxLength = "60";
			}
			else if ( type.equals("id-vlong") || type.equals("long-varchar") || type.equals("comment") || type.equals("description") || type.equals("value")
			           || type.equals("email") || type.equals("url") || type.equals("id-vlong-ne"))
			{
				displayObjectId = displayObjectText255;
				maxLength = "255";
			}
			else if ( type.equals("very-short"))
			{
				displayObjectId = displayObjectText20;
				maxLength = "10";
			}
			else if ( type.equals("indicator"))
			{
				displayObjectId = displayObjectCheckbox;
				maxLength = "1";
			}
			else if ( type.equals("very-long"))
			{
				displayObjectId = displayObjectTextArea;
				maxLength = "1000";
			}
			else if ( type.equals("name"))
			{
				displayObjectId = displayObjectText60;
				maxLength = "100";
			}
			else
			{
				displayObjectId = displayObjectText20;
				maxLength = "20";
			}
				
			if ( type.equals("id-ne") || type.equals("id-long-ne") || type.equals("id-vlong-ne"))
			{
				isMandatory = true;
			}
				
			String attributeId = GenericReplicator.getNextSeqId("UiAttribute", delegator);
			
			GenericValue uiAttributeGV = new GenericValue(uiAttributeME);
			uiAttributeGV.setDelegator(delegator);
			uiAttributeGV.set("attributeId", attributeId);
			uiAttributeGV.set("entityId", entityId);
			uiAttributeGV.set("attributeName", attrName);
			uiAttributeGV.set("description", displayLabel);
			uiAttributeGV.set("columnName", colName);
			uiAttributeGV.set("displayObjectId", displayObjectId);
			uiAttributeGV.set("maxLength", maxLength);
			uiAttributeGV.set("editMask", "");
			uiAttributeGV.set("displayLogic", "");
			uiAttributeGV.set("isMandatory", Boolean.valueOf(isMandatory));
			uiAttributeGV.set("isReadOnly", Boolean.valueOf(isReadOnly));
			uiAttributeGV.set("isVisible", Boolean.valueOf(isVisible));
			uiAttributeGV.set("isSearchable", Boolean.valueOf(isSearchable));
			uiAttributeGV.set("isExtension", Boolean.valueOf(isExtension));
			uiAttributeGV.set("displayOrder", new Integer(displayOrder));
			uiAttributeGV.set("displayLabel", displayLabel);
			uiAttributeGV.set("displayLength", maxLength);
			uiAttributeGV.set("colSpan", new Integer(colSpan));
			uiAttributeGV.set("rowSpan", new Integer(rowSpan));
			uiAttributeGV.set("startOnNewRow", Boolean.valueOf(startOnNewRow));
			

            // This is a copy of an existing screen section.

 
 			try {
            	delegator.create(uiAttributeGV);
 			}catch (GenericEntityException e)
            {
            	Debug.logError(e, module);
            }
		}

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param delegator 
     * @param originatingEntityName 
     * @param entityGV 
     *
     * @return 
     */
    public int deleteAllRelated(UserInfo userInfo, GenericDelegator delegator,
        String originatingEntityName, GenericValue entityGV) {

        int status = STATUS_CONTINUE;

        // Delete related screen section entities.
        status = deleteOneRelated(userInfo, delegator, entityGV, "",
                "UiAttribute", originatingEntityName,
                new GenericEventProcessor());

        return status;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -