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.ArrayList;
019    import java.util.List;
020    
021    import javax.servlet.jsp.JspException;
022    import javax.servlet.jsp.PageContext;
023    import javax.servlet.jsp.tagext.Tag;
024    
025    import org.kuali.kfs.sys.KFSConstants;
026    import org.kuali.kfs.sys.KFSKeyConstants;
027    import org.kuali.kfs.sys.context.SpringContext;
028    import org.kuali.kfs.sys.document.web.renderers.ActionsRenderer;
029    import org.kuali.rice.kns.service.KualiConfigurationService;
030    import org.kuali.rice.kns.web.ui.Field;
031    
032    /**
033     * A field that can join tables and also be rendered, this represents a table cell
034     * that displays the actions available on an accounting line
035     */
036    public class AccountingLineViewActionsField extends FieldTableJoiningWithHeader {
037        private String name = KFSConstants.AccountingLineViewStandardBlockNames.ACTION_BLOCK;
038    
039        /**
040         * Returns the name of this actions field
041         * @see org.kuali.kfs.sys.document.web.TableJoining#getName()
042         */
043        public String getName() {
044            return name;
045        }
046        
047        /**
048         * Sets the name of this actions field
049         * @param name the name of this block
050         */
051        public void setName(String name) {
052            this.name = name;
053        }
054    
055        /**
056         * We are an action block.  For real, even
057         * @see org.kuali.kfs.sys.document.web.FieldTableJoining#isActionBlock()
058         */
059        @Override
060        public boolean isActionBlock() {
061            return true;
062        }
063    
064        /**
065         * @see org.kuali.kfs.sys.document.web.FieldTableJoiningWithHeader#joinTable(java.util.List)
066         */
067        @Override
068        public void joinTable(List<AccountingLineTableRow> rows) {
069            // 1. add header cell
070            AccountingLineTableCell headerCell = createHeaderLabelTableCell();
071            rows.get(0).addCell(headerCell);
072    
073            // 2. add blank cell to make sure this cell shows up on the bottom line
074            final int blankCellRowSpan = rows.size() - 2;
075            if (blankCellRowSpan > 0) {
076                AccountingLineTableCell blankCell = createBlankTableCell(blankCellRowSpan);
077                rows.get(1).addCell(blankCell);
078            }
079            // 3. add field cell
080            AccountingLineTableCell cell = createTableCell();
081            rows.get((rows.size()-1)).addCell(cell);
082        }
083        
084        /**
085         * Builds a blank cell for the action so the actions always appear below that
086         * @param rowSpan the row span of the blank cell
087         * @return the blank row-spanning table cell
088         */
089        protected AccountingLineTableCell createBlankTableCell(int rowSpan) {
090            AccountingLineTableCell blankCell = new AccountingLineTableCell();
091            blankCell.setNeverEmpty(true);
092            blankCell.setExtraStyle("border-bottom-style: none;");
093            if (rowSpan > 1) {
094                blankCell.setRowSpan(rowSpan);
095            }
096            return blankCell;
097        }
098    
099        /**
100         * @see org.kuali.kfs.sys.document.web.RenderableElement#renderElement(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
101         */
102        public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
103            ActionsRenderer renderer = new ActionsRenderer();
104            renderer.setActions(renderingContext.getActionsForLine());
105            renderer.render(pageContext, parentTag);
106            renderer.clear();
107        }
108    
109        /**
110         * @see org.kuali.kfs.sys.document.web.TableJoiningWithHeader#createHeaderLabel()
111         */
112        public HeaderLabel createHeaderLabel() {
113            return new LiteralHeaderLabel(SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.AccountingLineViewRendering.ACCOUNTING_LINE_ACTIONS_LABEL));
114        }
115    
116        /**
117         * This doesn't hold a field, so this imlementation does nothing
118         * @see org.kuali.kfs.sys.document.web.RenderableElement#appendFieldNames(java.util.List)
119         */
120        public void appendFields(List<Field> fields) { }
121    
122        /**
123         * Doesn't do anything
124         * @see org.kuali.kfs.sys.document.web.RenderableElement#populateWithTabIndexIfRequested(int[], int)
125         */
126        public void populateWithTabIndexIfRequested(int reallyHighIndex) {}
127        
128    }