001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/mailtool/tags/sakai_2-4-1/mailtool/src/java/org/sakaiproject/tool/mailtool/FoothillSelector.java $
003: * $Id: FoothillSelector.java 27662 2007-03-22 19:44:57Z kimsooil@bu.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006, 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.mailtool;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import javax.faces.model.DataModel;
027: import javax.faces.model.SelectItem;
028: import javax.faces.model.SelectItemGroup;
029:
030: /**
031: * FoothillSelector, it's renamed to "Scrolling list" (commented by kimsooil@bu.edu)
032: *
033: * @author sgithens
034: *
035: */
036: public class FoothillSelector implements RecipientSelector {
037: List /* EmailGroup */m_initialgroups = null;
038: int m_poscount = 0;
039:
040: public class ListboxEntry {
041: int m_position;
042: EmailUser m_user = null;
043: String m_label = "";
044: boolean m_selected = false;
045:
046: public ListboxEntry(int position, EmailUser user) {
047: m_position = position;
048: m_user = user;
049: m_label = user.getDisplayname();
050: }
051:
052: public int getPosition() {
053: return m_position;
054: }
055:
056: public String getLabel() {
057: return m_label;
058: }
059:
060: public EmailUser getEmailUser() {
061: return m_user;
062: }
063:
064: public void setSelected(boolean value) {
065: m_selected = value;
066: }
067:
068: public boolean isSelected() {
069: return m_selected;
070: }
071: }
072:
073: public class ListboxGroup {
074: String m_label = "";
075: List /* ListboxEntry */m_entries = new ArrayList();
076: EmailGroup m_emailgroup = null;
077:
078: public String getLabel() {
079: return m_label;
080: }
081:
082: public EmailGroup getEmailGroup() {
083: return m_emailgroup;
084: }
085:
086: public List /* ListboxEntry */getListboxEntries() {
087: return m_entries;
088: }
089:
090: public ListboxGroup(EmailGroup group) {
091: m_emailgroup = group;
092: m_label = group.getRolePlural();
093:
094: String rtype = group.getEmailrole().roletype;
095: if (rtype.equals("group")) {
096: m_label += "(G)";
097: } else if (rtype.equals("section")) {
098: m_label += "(S)";
099: }
100:
101: for (Iterator i = group.getEmailusers().iterator(); i
102: .hasNext();) {
103: EmailUser user = (EmailUser) i.next();
104: ListboxEntry entry = new ListboxEntry(m_poscount, user);
105: m_entries.add(entry);
106: m_poscount++;
107: }
108: }
109: }
110:
111: /* This is going to be a List of Lists of type ListboxGroup */
112: List m_listboxGroups = new ArrayList();
113:
114: public FoothillSelector() {
115:
116: }
117:
118: public void populate(List emailgroups) {
119: m_initialgroups = emailgroups;
120: m_listboxGroups.clear();
121:
122: for (Iterator i = emailgroups.iterator(); i.hasNext();) {
123: EmailGroup group = (EmailGroup) i.next();
124: ListboxGroup listgroup = new ListboxGroup(group);
125: m_listboxGroups.add(listgroup);
126: }
127:
128: }
129:
130: public List /* EmailUser */getSelectedUsers() {
131: List users = new ArrayList();
132:
133: for (Iterator i = this .m_listboxGroups.iterator(); i.hasNext();) {
134: ListboxGroup group = (ListboxGroup) i.next();
135: for (Iterator k = group.getListboxEntries().iterator(); k
136: .hasNext();) {
137: ListboxEntry entry = (ListboxEntry) k.next();
138: if (entry.isSelected() == true) {
139: users.add(entry.getEmailUser());
140: }
141: }
142: }
143:
144: return users;
145: }
146:
147: public List getSelectedUsersByGroup() {
148: // TODO Auto-generated method stub
149: return null;
150: }
151:
152: /** Methods for JSP Fragment **/
153: public List /* SelectItemGroup */getListbox() {
154: List selectItemGroups = new ArrayList();
155:
156: for (Iterator i = this .m_listboxGroups.iterator(); i.hasNext();) {
157: List itemsingroup = new ArrayList();
158: ListboxGroup group = (ListboxGroup) i.next();
159:
160: SelectItemGroup siGroup = new SelectItemGroup();
161: siGroup.setValue(group.getLabel());
162: siGroup.setLabel(group.getLabel());
163:
164: SelectItem[] /* SelectItems */selectitems = new SelectItem[group
165: .getListboxEntries().size()];
166:
167: for (int j = 0; j < group.getListboxEntries().size(); j++) {
168: ListboxEntry entry = (ListboxEntry) group
169: .getListboxEntries().get(j);
170: SelectItem item = new SelectItem();
171: item.setLabel(entry.getLabel());
172: item.setValue(Integer.toString(entry.getPosition()));
173: selectitems[j] = item;
174:
175: }
176:
177: siGroup.setSelectItems(selectitems);
178:
179: selectItemGroups.add(siGroup);
180: }
181:
182: return selectItemGroups;
183: }
184:
185: public List /* String */getSelectedItems() {
186: List items = new ArrayList();
187:
188: for (Iterator i = m_listboxGroups.iterator(); i.hasNext();) {
189: ListboxGroup group = (ListboxGroup) i.next();
190: for (Iterator j = group.getListboxEntries().iterator(); j
191: .hasNext();) {
192: ListboxEntry entry = (ListboxEntry) j.next();
193: if (entry.isSelected() == true) {
194: items.add(Integer.toString(entry.getPosition()));
195: }
196: }
197: }
198:
199: return items;
200: }
201:
202: public void setSelectedItems(List /* ? */items) {
203:
204: Iterator i = items.iterator();
205: String next;
206: if (i.hasNext() == true)
207: next = (String) i.next();
208: else
209: return;
210:
211: for (Iterator j = this .m_listboxGroups.iterator(); j.hasNext();) {
212: ListboxGroup group = (ListboxGroup) j.next();
213: for (Iterator k = group.getListboxEntries().iterator(); k
214: .hasNext();) {
215: ListboxEntry entry = (ListboxEntry) k.next();
216: if (next.equals(Integer.toString(entry.getPosition()))) {
217: entry.setSelected(true);
218: if (i.hasNext() == true)
219: next = (String) i.next();
220: else
221: return;
222: } else
223: entry.setSelected(false);
224:
225: }
226: }
227:
228: }
229:
230: public List /* String */getCheckedRoles() {
231: return new ArrayList();
232: }
233:
234: public void setCheckedRoles(List /* ? */items) {
235:
236: }
237:
238: public List /* SelectItem */getRolesChecklist() {
239: List selectItems = new ArrayList();
240:
241: for (Iterator i = this .m_initialgroups.iterator(); i.hasNext();) {
242: EmailGroup e = (EmailGroup) i.next();
243: SelectItem item = new SelectItem();
244: item.setLabel(e.getRolePlural());
245: selectItems.add(item);
246: }
247:
248: return selectItems;
249: }
250:
251: public String processSelectAll() {
252: for (Iterator i = this .m_listboxGroups.iterator(); i.hasNext();) {
253: ListboxGroup group = (ListboxGroup) i.next();
254: for (Iterator j = group.getListboxEntries().iterator(); j
255: .hasNext();) {
256: ListboxEntry entry = (ListboxEntry) j.next();
257: entry.setSelected(true);
258: }
259: }
260:
261: return "main";
262: }
263:
264: public String processSelectNone() {
265: for (Iterator i = this .m_listboxGroups.iterator(); i.hasNext();) {
266: ListboxGroup group = (ListboxGroup) i.next();
267: for (Iterator j = group.getListboxEntries().iterator(); j
268: .hasNext();) {
269: ListboxEntry entry = (ListboxEntry) j.next();
270: entry.setSelected(false);
271: }
272: }
273:
274: return "main";
275: }
276:
277: public DataModel getDataModel() {
278: return null;
279: }
280: }
|