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