package com.fr.design.roleAuthority;

import com.fr.base.FRContext;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.design.gui.itree.refreshabletree.loader.ChildrenNodesLoader;
import com.fr.general.Inter;

import java.util.ArrayList;
import java.util.List;

/**
 * 将权限细粒度的角色数据包装一下，区分报表平台管理角色和数据决策系统角色
 * <p/>
 * Author : daisy
 * Date: 13-8-30
 * Time: 下午3:42
 */
public class RoleDataWrapper implements ChildrenNodesLoader {

	List<String> rolelist = new ArrayList<String>();

	private String roleTypename = null;

	public RoleDataWrapper(String roleName) {
		roleTypename = roleName;
	}


	/**
	 * 在此计算并获得与管理类型相对应的
	 */

	private void calculateRoleList() {
		this.rolelist.addAll(FRContext.getCurrentEnv().getAllRole4Privilege(
				roleTypename != Inter.getLocText("M_Server-Platform_Manager")));
	}

	//加载所有的角色列表
	public ExpandMutableTreeNode[] load() {
		calculateRoleList();
		return this.load(this.rolelist);
	}
	
	//从workbook中读取的角色列表
	public ExpandMutableTreeNode[] load(List<String> rolelist) {
		this.rolelist = rolelist;
		ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[rolelist.size()];
		for (int i = 0; i < res.length; i++) {
			res[i] = new ExpandMutableTreeNode(rolelist.get(i));
		}
		
		return res;
	}

	public  String getRoleTypename(){
		return roleTypename;
	}
}