01: /**********************************************************************************
02: *
03: * $Id: AssignmentPointsConverter.java 20001 2006-12-22 19:41:33Z ray@media.berkeley.edu $
04: *
05: ***********************************************************************************
06: *
07: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
08: *
09: * Licensed under the Educational Community License, Version 1.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.opensource.org/licenses/ecl1.php
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: *
21: **********************************************************************************/package org.sakaiproject.tool.gradebook.jsf;
22:
23: import javax.faces.component.UIComponent;
24: import javax.faces.context.FacesContext;
25:
26: import org.apache.commons.logging.Log;
27: import org.apache.commons.logging.LogFactory;
28: import org.sakaiproject.tool.gradebook.AbstractGradeRecord;
29: import org.sakaiproject.tool.gradebook.Assignment;
30: import org.sakaiproject.tool.gradebook.AssignmentGradeRecord;
31:
32: /**
33: * This formatting-only converver consolidates the rather complex formatting
34: * logic for assignment and assignment grade points. If the points are null,
35: * they should be displayed in a special way. If the points belong to an
36: * assignment which doesn't count toward the final grade, they should be
37: * displayed in a special way with a tooltip "title" attribute.
38: */
39: public class AssignmentPointsConverter extends PointsConverter {
40: private static final Log log = LogFactory
41: .getLog(AssignmentPointsConverter.class);
42:
43: public String getAsString(FacesContext context,
44: UIComponent component, Object value) {
45: if (log.isDebugEnabled())
46: log.debug("getAsString(" + context + ", " + component
47: + ", " + value + ")");
48:
49: String formattedScore;
50: boolean notCounted = false;
51: Object workingValue = value;
52:
53: if (value != null) {
54: if (value instanceof Assignment) {
55: Assignment assignment = (Assignment) value;
56: workingValue = assignment.getPointsPossible();
57: notCounted = assignment.isNotCounted();
58: } else if (value instanceof AbstractGradeRecord) {
59: workingValue = ((AbstractGradeRecord) value)
60: .getPointsEarned();
61: if (value instanceof AssignmentGradeRecord) {
62: notCounted = ((AssignmentGradeRecord) value)
63: .getAssignment().isNotCounted();
64: }
65: }
66: }
67: formattedScore = super .getAsString(context, component,
68: workingValue);
69: if (notCounted) {
70: formattedScore = FacesUtil
71: .getLocalizedString(
72: "score_not_counted",
73: new String[] {
74: formattedScore,
75: FacesUtil
76: .getLocalizedString("score_not_counted_tooltip") });
77: }
78: return formattedScore;
79: }
80: }
|