Kawai Wiki

Rev

Rev 149 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.kawai.model;

import org.mentawai.list.ListData;
import org.mentawai.list.SimpleListData;

/**
 * Enum Group.
 *
 * @author Sergio Oliveira
 *
 */

public enum Group {

    ADMIN(1, "Admin"), EDITOR(2, "Editor");

    /** Attribute id of Group. */
    private int id;
    /** Attribute name of Group. */
    private String name;

    private Group(int code, String name) {
        this.id = code;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public static Group fromId(int id) {
        for(Group g : Group.values()) {
            if (g.getId() == id) {
                return g;
            }
        }
        return null;
    }

    public static ListData getListData() {
        SimpleListData list = new SimpleListData("groups");
        for(Group g : Group.values()) {
            list.add(g.getId(), g.getName());
        }
        return list;
    }
}