1 /*
2 * Copyright 2008 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.ole.sys.document.web;
17
18 import java.util.List;
19
20 import javax.servlet.jsp.JspException;
21 import javax.servlet.jsp.PageContext;
22 import javax.servlet.jsp.tagext.Tag;
23
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.ole.sys.document.web.renderers.PersistingTagRenderer;
27 import org.kuali.ole.sys.document.web.renderers.StringRenderer;
28 import org.kuali.rice.core.api.config.property.ConfigurationService;
29 import org.kuali.rice.kns.web.ui.Field;
30
31 /**
32 * A class to represent the rendering of a sequence number field
33 */
34 public class AccountingLineViewSequenceNumberField extends FieldTableJoiningWithHeader {
35 private String name = OLEConstants.AccountingLineViewStandardBlockNames.SEQUENCE_NUMBER_BLOCK;
36 private String newLineLabelProperty = "accounting.line.new.line.sequence.number";
37
38 /**
39 * Sequence numbers are always read only
40 * @see org.kuali.ole.sys.document.web.AccountingLineViewRenderableElementField#isReadOnly()
41 */
42 public boolean isReadOnly() {
43 return true;
44 }
45
46 /**
47 * Returns the name of this sequence number field
48 * @see org.kuali.ole.sys.document.web.TableJoining#getName()
49 */
50 public String getName() {
51 return name;
52 }
53
54 /**
55 * Sets the name of this sequence number field
56 * @param name the name to set
57 */
58 public void setName(String name) {
59 this.name = name;
60 }
61
62 /**
63 * @see org.kuali.ole.sys.document.web.TableJoiningWithHeader#getHeaderLabelProperty()
64 */
65 public String getHeaderLabelProperty() {
66 return this.name;
67 }
68
69 /**
70 * @see org.kuali.ole.sys.document.web.FieldTableJoining#createTableCell()
71 */
72 @Override
73 protected AccountingLineTableCell createTableCell() {
74 AccountingLineTableCell cell = super.createTableCell();
75 cell.setRendersAsHeader(true);
76 return cell;
77 }
78
79 /**
80 * @see org.kuali.ole.sys.document.web.RenderableElement#renderElement(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag, org.kuali.ole.sys.document.web.AccountingLineRenderingContext)
81 */
82 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
83 if (renderingContext.isNewLine()) {
84 StringRenderer renderer = new StringRenderer();
85 renderer.setStringToRender(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(newLineLabelProperty));
86 renderer.render(pageContext, parentTag);
87 renderer.clear();
88 } else {
89 PersistingTagRenderer renderer = new PersistingTagRenderer();
90 renderer.setStringToRender(getDisplaySequenceNumber(renderingContext));
91 renderer.setValueToPersist(renderingContext.getAccountingLine().getSequenceNumber().toString());
92 renderer.setPersistingProperty(renderingContext.getAccountingLinePropertyPath()+".sequenceNumber");
93 renderer.render(pageContext, parentTag);
94 renderer.clear();
95 }
96 }
97
98 /**
99 * 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.ole.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.ole.sys.document.web.RenderableElement#appendFieldNames(java.util.List)
117 *
118 * KRAD Conversion: Customization of adding the fields - No use of data dictionary
119 */
120 public void appendFields(List<Field> fields) {
121 // take a nap
122 }
123
124 /**
125 * Does nothing
126 * @see org.kuali.ole.sys.document.web.RenderableElement#populateWithTabIndexIfRequested(int[], int)
127 */
128 public void populateWithTabIndexIfRequested(int reallyHighIndex) { }
129 }