001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/OverviewBean.java $
003: * $Id: OverviewBean.java 20230 2007-01-10 01:13:02Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
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.section.jsf.backingbean;
021:
022: import java.io.Serializable;
023: import java.util.ArrayList;
024: import java.util.Comparator;
025: import java.util.HashSet;
026: import java.util.Iterator;
027: import java.util.List;
028: import java.util.Set;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.sakaiproject.section.api.SectionManager.ExternalIntegrationConfig;
033: import org.sakaiproject.tool.section.decorator.SectionDecorator;
034: import org.sakaiproject.tool.section.jsf.JsfUtil;
035:
036: /**
037: * Controls the overview page.
038: *
039: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
040: *
041: */
042: public class OverviewBean extends FilteredSectionListingBean implements
043: Serializable {
044:
045: private static final long serialVersionUID = 1L;
046: private static final Log log = LogFactory
047: .getLog(OverviewBean.class);
048:
049: private String instructions;
050: private boolean externallyManaged;
051:
052: private List<SectionDecorator> sectionsToDelete;
053:
054: public void init() {
055: super .init();
056: // Determine whether this course is externally managed
057: externallyManaged = getSectionManager().isExternallyManaged(
058: getCourse().getUuid());
059:
060: // Generate the instructions for this user for the app in its current state
061: if (externallyManaged) {
062: if (isSectionAssignable()) {
063: instructions = JsfUtil
064: .getLocalizedMessage("overview_instructions_auto_ta");
065: } else {
066: if (getApplicationConfiguration() == ExternalIntegrationConfig.AUTOMATIC_MANDATORY) {
067: instructions = JsfUtil
068: .getLocalizedMessage("overview_instructions_mandatory_auto_instructor");
069: } else {
070: instructions = JsfUtil
071: .getLocalizedMessage("overview_instructions_auto_instructor");
072: }
073: }
074: } else {
075: instructions = "";
076: }
077: }
078:
079: protected Comparator<SectionDecorator> getComparator() {
080: String sortColumn = getPrefs().getOverviewSortColumn();
081: boolean sortAscending = getPrefs().isOverviewSortAscending();
082:
083: if (sortColumn.equals("title")) {
084: return SectionDecorator.getTitleComparator(sortAscending);
085: } else if (sortColumn.equals("managers")) {
086: return SectionDecorator
087: .getManagersComparator(sortAscending);
088: } else if (sortColumn.equals("totalEnrollments")) {
089: return SectionDecorator.getEnrollmentsComparator(
090: sortAscending, false);
091: } else if (sortColumn.equals("available")) {
092: return SectionDecorator.getEnrollmentsComparator(
093: sortAscending, true);
094: } else if (sortColumn.equals("meetingDays")) {
095: return SectionDecorator.getDayComparator(sortAscending);
096: } else if (sortColumn.equals("meetingTimes")) {
097: return SectionDecorator.getTimeComparator(sortAscending);
098: } else if (sortColumn.equals("location")) {
099: return SectionDecorator
100: .getLocationComparator(sortAscending);
101: }
102: log.error("Invalid sort specified.");
103: return null;
104: }
105:
106: public String confirmDelete() {
107: sectionsToDelete = new ArrayList<SectionDecorator>();
108: for (Iterator<SectionDecorator> iter = sections.iterator(); iter
109: .hasNext();) {
110: SectionDecorator decoratedSection = iter.next();
111: if (decoratedSection.isFlaggedForRemoval()) {
112: sectionsToDelete.add(decoratedSection);
113: }
114: }
115: if (sectionsToDelete.isEmpty()) {
116: JsfUtil
117: .addErrorMessage(JsfUtil
118: .getLocalizedMessage("overview_delete_section_choose"));
119: return null; // Don't go anywhere
120: } else {
121: return "deleteSections";
122: }
123: }
124:
125: public String deleteSections() {
126: Set<String> set = new HashSet<String>();
127: for (Iterator<SectionDecorator> iter = sectionsToDelete
128: .iterator(); iter.hasNext();) {
129: set.add(iter.next().getUuid());
130: }
131: getSectionManager().disbandSections(set);
132: JsfUtil
133: .addRedirectSafeInfoMessage(JsfUtil
134: .getLocalizedMessage("overview_delete_section_success"));
135: return "overview";
136: }
137:
138: public boolean isDeleteRendered() {
139: return (!externallyManaged) && sections.size() > 0
140: && isSectionManagementEnabled();
141: }
142:
143: public boolean isExternallyManaged() {
144: return externallyManaged;
145: }
146:
147: public List getSectionsToDelete() {
148: return sectionsToDelete;
149: }
150:
151: @Override
152: public String getSortColumn() {
153: return getPrefs().getOverviewSortColumn();
154: }
155:
156: @Override
157: public boolean isSortAscending() {
158: return getPrefs().isOverviewSortAscending();
159: }
160:
161: @Override
162: public void setSortAscending(boolean sortAscending) {
163: getPrefs().setOverviewSortAscending(sortAscending);
164: }
165:
166: @Override
167: public void setSortColumn(String sortColumn) {
168: getPrefs().setOverviewSortColumn(sortColumn);
169: }
170:
171: @Override
172: public String getCategoryFilter() {
173: return getPrefs().getOverviewCategoryFilter();
174: }
175:
176: @Override
177: public String getMyFilter() {
178: return getPrefs().getOverviewMyFilter();
179: }
180:
181: @Override
182: public void setCategoryFilter(String categoryFilter) {
183: getPrefs().setOverviewCategoryFilter(categoryFilter);
184: }
185:
186: @Override
187: public void setMyFilter(String myFilter) {
188: getPrefs().setOverviewMyFilter(myFilter);
189: }
190:
191: public String getInstructions() {
192: return instructions;
193: }
194: }
|