001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/mailtool/tags/sakai_2-4-1/mailtool/src/java/org/sakaiproject/tool/mailtool/SelectByUserTable.java $
003: * $Id: SelectByUserTable.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.Collections;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import javax.faces.model.DataModel;
028: import javax.faces.model.ListDataModel;
029:
030: /**
031: * SelectByUserTable, it's used both for Tree(Users by Role) and User views (commented by kimsooil@bu.edu)
032: *
033: * @author sgithens
034: *
035: */
036: public class SelectByUserTable {
037: public class TableEntry {
038: /* Two names per row */
039: protected EmailUser m_user1 = null;
040: protected EmailUser m_user2 = null;
041:
042: protected boolean m_selected1 = false;
043: protected boolean m_selected2 = false;
044:
045: public TableEntry() {
046: }
047:
048: public EmailUser getUser1() {
049: return m_user1;
050: }
051:
052: public EmailUser getUser2() {
053: return m_user2;
054: }
055:
056: public boolean isSelected1() {
057: return m_selected1;
058: }
059:
060: public boolean isSelected2() {
061: return m_selected2;
062: }
063:
064: public void setUser1(EmailUser user) {
065: m_user1 = user;
066: }
067:
068: public void setUser2(EmailUser user) {
069: m_user2 = user;
070: }
071:
072: public void setSelected1(boolean selected) {
073: m_selected1 = selected;
074: }
075:
076: public void setSelected2(boolean selected) {
077: m_selected2 = selected;
078: }
079:
080: public boolean isRender2() {
081: if (m_user2 == null)
082: return false;
083: else
084: return true;
085: }
086: }
087:
088: List /** TableEntry **/
089: m_tablerows = new ArrayList();
090:
091: /*
092: public SelectByUserTable(List users)
093: {
094: m_tablerows.clear();
095: Collections.sort(users);
096: for (Iterator i = users.iterator(); i.hasNext();)
097: {
098: EmailUser euser1 = (EmailUser) i.next();
099: TableEntry te = new TableEntry();
100: te.setUser1(euser1);
101:
102: if (i.hasNext())
103: {
104: EmailUser euser2 = (EmailUser) i.next();
105: te.setUser2(euser2);
106: }
107: m_tablerows.add(te);
108: }
109: }
110: */
111: public SelectByUserTable(List /* EmailUsers */users) {
112: m_tablerows.clear();
113: Collections.sort(users);
114: int num = users.size();
115: int half = (int) Math.ceil((double) num / 2.0);
116: //Iterator i = users.iterator();
117: for (int k = 0; k < half; k++) {
118: // EmailUser euser1 = (EmailUser) i.next();
119: EmailUser euser1 = (EmailUser) users.get(k);
120:
121: TableEntry te = new TableEntry();
122: te.setUser1(euser1);
123:
124: if ((k + half) < num) {
125: //EmailUser euser2 = (EmailUser) i.next();
126: EmailUser euser2 = (EmailUser) users.get(k + half);
127: te.setUser2(euser2);
128: }
129: m_tablerows.add(te);
130: }
131: }
132:
133: public DataModel getUserRows() {
134: DataModel returnmodel = new ListDataModel();
135: returnmodel.setWrappedData(m_tablerows);
136: return returnmodel;
137: }
138:
139: public List /* EmailUsers */getSelectedUsers() {
140: List returnusers = new ArrayList();
141: for (Iterator i = m_tablerows.iterator(); i.hasNext();) {
142: TableEntry te = (TableEntry) i.next();
143:
144: if (te.isSelected1())
145: returnusers.add(te.getUser1());
146:
147: if (te.isSelected2())
148: returnusers.add(te.getUser2());
149: }
150:
151: return returnusers;
152: }
153:
154: public void switchSelections(boolean allornot) {
155: for (Iterator i = m_tablerows.iterator(); i.hasNext();) {
156: TableEntry te = (TableEntry) i.next();
157:
158: te.setSelected1(allornot);
159: te.setSelected2(allornot);
160: }
161:
162: }
163: }
|