001 /** 002 * Copyright 2004-2013 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.TKUtils; 024 import org.kuali.hr.time.util.TkConstants; 025 import org.kuali.hr.time.workarea.WorkArea; 026 027 import java.util.ArrayList; 028 import java.util.List; 029 030 /** 031 * Render helper to handle timeblock and time hour details display 032 */ 033 public class TimeBlockRenderer { 034 035 private TimeBlock timeBlock; 036 private List<TimeHourDetailRenderer> detailRenderers = new ArrayList<TimeHourDetailRenderer>(); 037 private String assignmentClass; 038 private String lunchLabel; 039 private String lunchLabelId; 040 041 public TimeBlockRenderer(TimeBlock b) { 042 this.timeBlock = b; 043 for (TimeHourDetail detail : timeBlock.getTimeHourDetails()) { 044 detailRenderers.add(new TimeHourDetailRenderer(detail)); 045 } 046 } 047 048 public List<TimeHourDetailRenderer> getDetailRenderers() { 049 return detailRenderers; 050 } 051 052 public TimeBlock getTimeBlock() { 053 return timeBlock; 054 } 055 056 public String getTimeRange() { 057 StringBuilder b = new StringBuilder(); 058 if(StringUtils.equals(timeBlock.getEarnCodeType(), TkConstants.EARN_CODE_TIME)) { 059 b.append(timeBlock.getBeginTimeDisplay().toString(TkConstants.DT_BASIC_TIME_FORMAT)); 060 b.append(" - "); 061 b.append(timeBlock.getEndTimeDisplay().toString(TkConstants.DT_BASIC_TIME_FORMAT)); 062 } 063 064 return b.toString(); 065 } 066 067 public String getTitle() { 068 StringBuilder b = new StringBuilder(); 069 070 WorkArea wa = TkServiceLocator.getWorkAreaService().getWorkArea(timeBlock.getWorkArea(), TKUtils.getCurrentDate()); 071 b.append(wa.getDescription()); 072 Task task = TkServiceLocator.getTaskService().getTask(timeBlock.getTask(), timeBlock.getBeginDate()); 073 if(task != null) { 074 // do not display task description if the task is the default one 075 // default task is created in getTask() of TaskService 076 if(!task.getDescription().equals(TkConstants.TASK_DEFAULT_DESP)) { 077 b.append("-" + task.getDescription()); 078 } 079 } 080 return b.toString(); 081 } 082 083 public String getAmount() { 084 if(StringUtils.equals(timeBlock.getEarnCodeType(), TkConstants.EARN_CODE_AMOUNT)) { 085 if(timeBlock.getAmount() != null) { 086 return timeBlock.getEarnCode() + ": $" + timeBlock.getAmount().toString(); 087 } else { 088 return timeBlock.getEarnCode() + ": $0.00"; 089 } 090 } 091 return ""; 092 } 093 094 public String getEarnCodeType() { 095 return timeBlock.getEarnCodeType(); 096 } 097 098 public String getAssignmentClass() { 099 return assignmentClass; 100 } 101 102 public void setAssignmentClass(String assignmentClass) { 103 this.assignmentClass = assignmentClass; 104 } 105 106 public String getLunchLabel() { 107 return lunchLabel; 108 } 109 110 public void setLunchLabel(String lunchLabel) { 111 this.lunchLabel = lunchLabel; 112 } 113 114 public String getLunchLabelId() { 115 return lunchLabelId; 116 } 117 118 public void setLunchLabelId(String lunchLabelId) { 119 this.lunchLabelId = lunchLabelId; 120 } 121 }