001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/mailtool/tags/sakai_2-4-1/mailtool/src/java/org/sakaiproject/tool/mailtool/SelectByTree.java $
003: * $Id: SelectByTree.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.event.ActionEvent;
027: import javax.faces.model.DataModel;
028: import javax.faces.model.ListDataModel;
029: import javax.faces.context.FacesContext;
030: import javax.faces.event.ValueChangeEvent;
031: import javax.faces.event.PhaseId;
032:
033: /**
034: * SelectByTree, it's renamed to "Users by Role" (commented by kimsooil@bu.edu)
035: *
036: * @author sgithens
037: *
038: */
039: public class SelectByTree {
040: public class TableEntry {
041: private EmailGroup m_emailgroup = null; /* Keep this around for good measure */
042: private boolean m_collapsed = true;
043: private EmailRole m_emailrole = null;
044: private SelectByUserTable m_usertable = null;
045:
046: /* JSF Widgets */
047: private boolean m_allSelected = false;
048: private boolean m_groupAware = false;
049:
050: public TableEntry(EmailGroup emailgroup) {
051: m_emailgroup = emailgroup;
052: m_emailrole = emailgroup.getEmailrole();
053: m_usertable = new SelectByUserTable(emailgroup
054: .getEmailusers());
055: }
056:
057: public DataModel getUserTable() {
058: return m_usertable.getUserRows();
059: }
060:
061: public String getPluralRolename() {
062: return m_emailrole.getRoleplural();
063: }
064:
065: public String getSingularRolename() {
066: return m_emailrole.getRolesingular();
067: }
068:
069: public boolean isCollapsed() {
070: return m_collapsed;
071: }
072:
073: public void setCollapsed(boolean collapsed) {
074: m_collapsed = collapsed;
075: }
076:
077: public void actionExpand(ActionEvent event) {
078: m_collapsed = false;
079: }
080:
081: public void actionCollapse(ActionEvent event) {
082: m_collapsed = true;
083: }
084:
085: public void setAllSelected(boolean value) {
086: m_allSelected = value;
087: }
088:
089: public void processSelectAll(ValueChangeEvent event) {
090: PhaseId phaseId = event.getPhaseId();
091: if (phaseId.equals(PhaseId.ANY_PHASE)) {
092: event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
093: event.queue();
094: } else if (phaseId.equals(PhaseId.UPDATE_MODEL_VALUES)) {
095: // do you method here
096: boolean allornot = ((Boolean) event.getNewValue())
097: .booleanValue();
098: setAllSelected(allornot);
099: m_usertable.switchSelections(allornot);
100: // FacesContext.getCurrentInstance().renderResponse();
101:
102: }
103: }
104:
105: public boolean isAllSelected() {
106: return m_allSelected;
107: }
108:
109: public boolean isGroupAware() {
110: return m_groupAware;
111: }
112:
113: public void setGroupAware(boolean aware) {
114: m_groupAware = aware;
115: }
116: }
117:
118: // protected List /* TableEntry */ m_tablerows = new ArrayList();
119: public List /* TableEntry */m_tablerows = new ArrayList();
120:
121: public SelectByTree(List /* EmailGroup */groups) {
122: m_tablerows.clear();
123: for (Iterator i = groups.iterator(); i.hasNext();) {
124: EmailGroup egroup = (EmailGroup) i.next();
125: TableEntry te = new TableEntry(egroup);
126:
127: //te.m_groupAware = egroup.getRolePlural().equals("Students") ? true : false;
128: m_tablerows.add(te);
129: }
130: }
131:
132: public DataModel getRows() {
133: DataModel returnmodel = new ListDataModel();
134: returnmodel.setWrappedData(m_tablerows);
135: return returnmodel;
136: }
137:
138: public List /* EmailUser */getSelectedUsers() {
139: List /* EmailUser */selectedusers = new ArrayList();
140:
141: for (Iterator i = m_tablerows.iterator(); i.hasNext();) {
142: TableEntry te = (TableEntry) i.next();
143: // if ((te.isCollapsed() == true) && (te.isAllSelected() == true))
144: if (te.isAllSelected() == true) {
145: selectedusers.addAll(te.m_emailgroup.getEmailusers());
146: } else {
147: selectedusers.addAll(te.m_usertable.getSelectedUsers());
148: }
149: }
150:
151: return selectedusers;
152: }
153: }
|