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

📄 roletreenode.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.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;


/**
 * DOCUMENT ME!
 *
 */
public class RoleTreeNode extends BasicTreeNode {
	public static final String module = RoleTreeNode.class.getName();
    public RoleTreeNode() {
        super();
    }

    public RoleTreeNode(Object userObject) {
        super(userObject);
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator 
     *
     * @return 
     *
     * @throws GenericEntityException 
     * @throws ClassNotFoundException 
     * @throws LinkageError 
     * @throws ExceptionInInitializerError 
     * @throws InstantiationException 
     * @throws IllegalAccessException 
     */
    public static BasicTreeNode createTree(GenericDelegator delegator)
        throws GenericEntityException, ClassNotFoundException, LinkageError, 
            ExceptionInInitializerError, InstantiationException, 
            IllegalAccessException {
        return createTree(delegator, "Role", "roleId", "roleParentId",
            "com.sourcetap.sfa.ui.RoleTreeNode");
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator 
     * @param accountId 
     *
     * @return 
     *
     * @throws GenericEntityException 
     * @throws ClassNotFoundException 
     * @throws LinkageError 
     * @throws ExceptionInInitializerError 
     * @throws InstantiationException 
     * @throws IllegalAccessException 
     */
    public static BasicTreeNode createTree(GenericDelegator delegator,
        String accountId)
        throws GenericEntityException, ClassNotFoundException, LinkageError, 
            ExceptionInInitializerError, InstantiationException, 
            IllegalAccessException {
        ArrayList orderBy = new ArrayList();
        orderBy.add("roleParentId");

        HashMap acctMap = new HashMap();
        acctMap.put("accountId", accountId);

        List rows = delegator.findByLike("Role", acctMap, orderBy);
        GenericValue[] genericValue = (GenericValue[]) rows.toArray(new GenericValue[0]);

        return createTree(genericValue, "roleId", "roleParentId",
            "com.sourcetap.sfa.ui.RoleTreeNode");
    }

    /**
     * DOCUMENT ME!
     *
     * @return 
     */
    public String getDisplayText() {
        Object o = getUserObject();

        String name = "";
        String assignments = "";
        String roleId = "";

        if (o instanceof String) {
            name = (String) o;

            if (name.equals("PLACEHOLDER")) {
                name = "";
            }
        } else if (o instanceof GenericValue) {
            GenericValue gv = (GenericValue) o;
            name = (String) gv.get("roleName");
            roleId = (String) gv.get("roleId");

            try {
                GenericDelegator delegator = gv.getDelegator();

                //find contacts for role
                Vector contactFields = new Vector();
                Vector contactValueVector = new Vector();
                Vector contactOps = new Vector();

                contactFields.add(new EntityExpr("roleId",
                        EntityOperator.EQUALS, roleId));

                List contacts = delegator.findByAnd("Contact", contactFields,
                        null);
                GenericValue[] contactValues = (GenericValue[]) contacts.toArray(new GenericValue[0]);

                for (int i = 0; i < contactValues.length; i++) {
                    GenericValue contactValue = contactValues[i];
                    String firstName = contactValue.getString("firstName");
                    String lastName = contactValue.getString("lastName");

                    if (assignments.length() > 0) {
                        assignments = assignments + "<BR>";
                    }

                    assignments = assignments + "<nobr>" + firstName + " " +
                        lastName + "</nobr>";
                }
            } catch (Exception e) {
            }
        }

        String html = "<div align=top><font color=#003399><b><center>" + name +
            "</center></b></div>\n";

        if (assignments.length() > 0) {
            html += ("<br><br><font color=#009933><center>" + assignments +
            "</center>");
        } else {
            html += "<br><br><font color=#993300><center><i>Unassigned</i></center></font>";
        }

        // add buttons
        html = html + "<br><div class=freeFormSectionTitleTable>" +
            "<FORM NAME=TerritoryFormButton STYLE=\"BORDER:0; MARGIN:0; PADDING:0; \" METHOD=post ACTION=territoryEdit TARGET=contentFrame>" +
            "<INPUT TYPE=hidden NAME=roleId VALUE=" + roleId + ">" +
            "<INPUT TYPE=hidden NAME=action VALUE=button>" +
            "<INPUT CLASS=titleBarImageButton TYPE=image NAME=newButton TITLE=\"Create a new record\" SRC=/sfaimages/New24.gif>" +
            "<INPUT CLASS=titleBarImageButton TYPE=image NAME=editButton TITLE=\"Edit the current record\" SRC=/sfaimages/Edit24.gif>" +
            "<INPUT CLASS=titleBarImageButton TYPE=image NAME=deleteButton TITLE=\"Delete the current record\" SRC=/sfaimages/Delete24.gif>" +
            "</FORM></div>";

        return html;
    }
}

⌨️ 快捷键说明

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