001 /* 002 * Copyright 2011 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.kfs.sys.document.web; 017 018 import java.util.List; 019 020 import javax.servlet.jsp.JspException; 021 import javax.servlet.jsp.PageContext; 022 import javax.servlet.jsp.tagext.Tag; 023 024 import org.kuali.kfs.sys.KFSConstants; 025 import org.kuali.kfs.sys.context.SpringContext; 026 import org.kuali.kfs.sys.document.web.renderers.PersistingTagRenderer; 027 import org.kuali.kfs.sys.document.web.renderers.StringRenderer; 028 import org.kuali.rice.kns.service.KualiConfigurationService; 029 import org.kuali.rice.kns.web.ui.Field; 030 031 /** 032 * A class to represent the rendering of a sequence number field 033 */ 034 public class AccountingLineViewSequenceNumberField extends FieldTableJoiningWithHeader { 035 private String name = KFSConstants.AccountingLineViewStandardBlockNames.SEQUENCE_NUMBER_BLOCK; 036 private String newLineLabelProperty = "accounting.line.new.line.sequence.number"; 037 038 /** 039 * Sequence numbers are always read only 040 * @see org.kuali.kfs.sys.document.web.AccountingLineViewRenderableElementField#isReadOnly() 041 */ 042 public boolean isReadOnly() { 043 return true; 044 } 045 046 /** 047 * Returns the name of this sequence number field 048 * @see org.kuali.kfs.sys.document.web.TableJoining#getName() 049 */ 050 public String getName() { 051 return name; 052 } 053 054 /** 055 * Sets the name of this sequence number field 056 * @param name the name to set 057 */ 058 public void setName(String name) { 059 this.name = name; 060 } 061 062 /** 063 * @see org.kuali.kfs.sys.document.web.TableJoiningWithHeader#getHeaderLabelProperty() 064 */ 065 public String getHeaderLabelProperty() { 066 return this.name; 067 } 068 069 /** 070 * @see org.kuali.kfs.sys.document.web.FieldTableJoining#createTableCell() 071 */ 072 @Override 073 protected AccountingLineTableCell createTableCell() { 074 AccountingLineTableCell cell = super.createTableCell(); 075 cell.setRendersAsHeader(true); 076 return cell; 077 } 078 079 /** 080 * @see org.kuali.kfs.sys.document.web.RenderableElement#renderElement(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag, org.kuali.kfs.sys.document.web.AccountingLineRenderingContext) 081 */ 082 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException { 083 if (renderingContext.isNewLine()) { 084 StringRenderer renderer = new StringRenderer(); 085 renderer.setStringToRender(SpringContext.getBean(KualiConfigurationService.class).getPropertyString(newLineLabelProperty)); 086 renderer.render(pageContext, parentTag); 087 renderer.clear(); 088 } else { 089 PersistingTagRenderer renderer = new PersistingTagRenderer(); 090 renderer.setStringToRender(getDisplaySequenceNumber(renderingContext)); 091 renderer.setValueToPersist(renderingContext.getAccountingLine().getSequenceNumber().toString()); 092 renderer.setPersistingProperty(renderingContext.getAccountingLinePropertyPath()+".sequenceNumber"); 093 renderer.render(pageContext, parentTag); 094 renderer.clear(); 095 } 096 } 097 098 /** 099 * Given the rendering context, returns what the sequence number of the line to be rendered is 100 * @param renderingContext the rendering context which holds the accounting line 101 * @return the sequence number to render (not the one to store as a value) 102 */ 103 protected String getDisplaySequenceNumber(AccountingLineRenderingContext renderingContext) { 104 return renderingContext.getAccountingLine().getSequenceNumber().toString(); 105 } 106 107 /** 108 * @see org.kuali.kfs.sys.document.web.TableJoiningWithHeader#createHeaderLabel() 109 */ 110 public HeaderLabel createHeaderLabel() { 111 return new LiteralHeaderLabel(" "); 112 } 113 114 /** 115 * sequence number is never really related to lookups, so this implementation does nothing 116 * @see org.kuali.kfs.sys.document.web.RenderableElement#appendFieldNames(java.util.List) 117 */ 118 public void appendFields(List<Field> fields) { 119 // take a nap 120 } 121 122 /** 123 * Does nothing 124 * @see org.kuali.kfs.sys.document.web.RenderableElement#populateWithTabIndexIfRequested(int[], int) 125 */ 126 public void populateWithTabIndexIfRequested(int reallyHighIndex) { } 127 }