roleitem.java

来自「这是linux下ssl vpn的实现程序」· Java 代码 · 共 80 行

JAVA
80
字号
/*
 */
package com.sslexplorer.security;

import java.util.List;

import com.sslexplorer.table.TableItem;

/**
 * 
 * Implementation of {@link TableItem} suitable for display configured
 * <i>Groups</i> (previously known as <i>Roles</i>.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.8 $
 */
public class RoleItem implements TableItem {

    // Private instance variables
    
    private Role role;
    private List accounts;

    /**
     * Constructor.
     *
     * @param role role
     * @param accounts accounts
     */
    public RoleItem(Role role, List accounts) {
        this.role = role;
        this.accounts = accounts;
    }
    
    /**
     * Get the accounts ({@link User} objects attached to this
     * role
     */
    public List getAccounts() {
        return accounts;
    }
    
    /**
     * Get if there are multiple accounts attached to this role
     * 
     * @return accounts
     */
    public boolean getMultipleAccounts() {
        return accounts.size() > 1;
    }
    
    /**
     * Get the account name of the first user in this role
     * 
     * @return first account in role
     */
    public String getFirstAccountName() {
        return accounts.size() > 0 ? ((User)accounts.get(0)).getPrincipalName() : ""; 
    }

    /**
     * Get the role this item wraps
     * 
     * @return role
     */
    public Role getRole() {
        return role;
    }

    public Object getColumnValue(int col) {
        switch (col) {
            case 0:
                return role.getPrincipalName();
            default:
                return getFirstAccountName();
        }
    }

}

⌨️ 快捷键说明

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