001 /**
002 * Copyright 2004-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.calendar;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.hr.time.service.base.TkServiceLocator;
020 import org.kuali.hr.time.task.Task;
021 import org.kuali.hr.time.timeblock.TimeBlock;
022 import org.kuali.hr.time.timeblock.TimeHourDetail;
023 import org.kuali.hr.time.util.TkConstants;
024 import org.kuali.hr.time.workarea.WorkArea;
025
026 import java.util.ArrayList;
027 import java.util.List;
028
029 /**
030 * Render helper to handle timeblock and time hour details display
031 */
032 public class TimeBlockRenderer {
033
034 private TimeBlock timeBlock;
035 private List<TimeHourDetailRenderer> detailRenderers = new ArrayList<TimeHourDetailRenderer>();
036 private String assignmentClass;
037 private String lunchLabel;
038 private String lunchLabelId;
039
040 public TimeBlockRenderer(TimeBlock b) {
041 this.timeBlock = b;
042 for (TimeHourDetail detail : timeBlock.getTimeHourDetails()) {
043 detailRenderers.add(new TimeHourDetailRenderer(detail));
044 }
045 }
046
047 public List<TimeHourDetailRenderer> getDetailRenderers() {
048 return detailRenderers;
049 }
050
051 public TimeBlock getTimeBlock() {
052 return timeBlock;
053 }
054
055 public String getTimeRange() {
056 StringBuilder b = new StringBuilder();
057 if(StringUtils.equals(timeBlock.getEarnCodeType(), TkConstants.EARN_CODE_TIME)) {
058 b.append(timeBlock.getBeginTimeDisplay().toString(TkConstants.DT_BASIC_TIME_FORMAT));
059 b.append(" - ");
060 b.append(timeBlock.getEndTimeDisplay().toString(TkConstants.DT_BASIC_TIME_FORMAT));
061 }
062
063 return b.toString();
064 }
065
066 public String getTitle() {
067 StringBuilder b = new StringBuilder();
068
069 WorkArea wa = TkServiceLocator.getWorkAreaService().getWorkArea(timeBlock.getTkWorkAreaId());
070 b.append(wa.getDescription());
071 Task task = TkServiceLocator.getTaskService().getTask(timeBlock.getTask(), timeBlock.getBeginDate());
072 if(task != null) {
073 // do not display task description if the task is the default one
074 // default task is created in getTask() of TaskService
075 if(!task.getDescription().equals(TkConstants.TASK_DEFAULT_DESP)) {
076 b.append("-" + task.getDescription());
077 }
078 }
079 return b.toString();
080 }
081
082 public String getAmount() {
083 if(StringUtils.equals(timeBlock.getEarnCodeType(), TkConstants.EARN_CODE_AMOUNT)) {
084 if(timeBlock.getAmount() != null) {
085 return timeBlock.getEarnCode() + ": $" + timeBlock.getAmount().toString();
086 } else {
087 return timeBlock.getEarnCode() + ": $0.00";
088 }
089 }
090 return "";
091 }
092
093 public String getEarnCodeType() {
094 return timeBlock.getEarnCodeType();
095 }
096
097 public String getAssignmentClass() {
098 return assignmentClass;
099 }
100
101 public void setAssignmentClass(String assignmentClass) {
102 this.assignmentClass = assignmentClass;
103 }
104
105 public String getLunchLabel() {
106 return lunchLabel;
107 }
108
109 public void setLunchLabel(String lunchLabel) {
110 this.lunchLabel = lunchLabel;
111 }
112
113 public String getLunchLabelId() {
114 return lunchLabelId;
115 }
116
117 public void setLunchLabelId(String lunchLabelId) {
118 this.lunchLabelId = lunchLabelId;
119 }
120 }