View Javadoc

1   package org.musicontroller.gui.admin;
2   
3   import java.util.List;
4   
5   import org.apache.tapestry.form.IPropertySelectionModel;
6   import org.musicontroller.security.Role;
7   
8   
9   /**
10   * Implements a Tapestry PropertySelectionModel for use as selector for Roles
11   * in the UserEditor.
12   * @author Varienaja
13   */
14  public class RoleSelectionModel implements IPropertySelectionModel {
15  	private List<Role> _itemList;
16  	
17  	public RoleSelectionModel(List<Role> roles) {
18  		_itemList = roles;
19  	}
20  	
21  	/*
22  	 * (non-Javadoc)
23  	 * @see org.apache.tapestry.form.IPropertySelectionModel#getLabel(int)
24  	 */
25  	public String getLabel(int index) {
26  		return ((Role) _itemList.get(index)).getName();
27  	}
28  	
29  	/*
30  	 * (non-Javadoc)
31  	 * @see org.apache.tapestry.form.IPropertySelectionModel#getOptionCount()
32  	 */
33  	public int getOptionCount() {
34  		return _itemList.size();
35  	}
36  
37  	/*
38  	 * (non-Javadoc)
39  	 * @see org.apache.tapestry.form.IPropertySelectionModel#translateValue(java.lang.String)
40  	 */
41  	public Role translateValue(String value) {
42  		int index = Integer.parseInt(value);
43  		return _itemList.get(index);
44  	}
45  	
46  	/*
47  	 * (non-Javadoc)
48  	 * @see org.apache.tapestry.form.IPropertySelectionModel#getOption(int)
49  	 */
50  	public Role getOption(int index) {
51  		return _itemList.get(index);
52  	}
53  	
54  	/*
55  	 * (non-Javadoc)
56  	 * @see org.apache.tapestry.form.IPropertySelectionModel#getValue(int)
57  	 */
58  	public String getValue(int index) {
59  		return Integer.valueOf(index).toString();
60  	}
61  
62  	/*
63  	 * (non-Javadoc)
64  	 * @see org.apache.tapestry.form.IPropertySelectionModel#isDisabled(int)
65  	 */
66  	public boolean isDisabled(int index) {
67  		return false;
68  	}
69  
70  }