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    import java.util.Map;
020    import java.util.Set;
021    
022    import org.kuali.kfs.sys.businessobject.AccountingLine;
023    import org.kuali.kfs.sys.document.AccountingDocument;
024    import org.kuali.kfs.sys.document.service.AccountingLineFieldRenderingTransformation;
025    
026    /**
027     * Abstract class which contains functionality of table joining layout elements that will eventually render fields
028     */
029    public abstract class FieldTableJoining implements TableJoining, RenderableElement {
030    
031        /**
032         * Always returns 1 - any field can live within 1 row.
033         * @see org.kuali.kfs.sys.document.web.AccountingLineViewRenderableElement#getRequestedRowCount()
034         */
035        public int getRequestedRowCount() {
036            return 1;
037        }
038    
039        /**
040         * Creates a table cell that encapsulates this field
041         * @return the created table cell
042         */
043        protected AccountingLineTableCell createTableCell() {
044            AccountingLineTableCell cell = new AccountingLineTableCell();
045            cell.addRenderableElement(this);
046            return cell;
047        }
048    
049        /**
050         * @see org.kuali.kfs.sys.document.web.AccountingLineViewRenderableElement#joinTable(java.util.List)
051         */
052        public void joinTable(List<AccountingLineTableRow> rows) {
053            AccountingLineTableCell cell = createTableCell();
054            cell.setRowSpan(rows.size());
055            rows.get(0).addCell(cell);
056        }
057    
058        /**
059         * @see org.kuali.kfs.sys.document.web.TableJoining#removeAllActionBlocks()
060         */
061        public void removeAllActionBlocks() {
062            // do nothing - fields don't really have child action blocks (and action blocks which 
063            // extend this method can't really do much of anything)
064        }
065    
066        /**
067         * Default: assumes the field is not hidden
068         * @see org.kuali.kfs.sys.document.web.RenderableElement#isHidden()
069         */
070        public boolean isHidden() {
071            return false;
072        }
073    
074        /**
075         * We're going to go out on a limb and bet that this isn't an action block
076         * @see org.kuali.kfs.sys.document.web.RenderableElement#isActionBlock()
077         */
078        public boolean isActionBlock() {
079            return false;
080        }
081    
082        /**
083         * Joins ths field to the header row, spans the regular row
084         * @see org.kuali.kfs.sys.document.web.TableJoining#joinRow(org.kuali.kfs.sys.document.web.AccountingLineTableRow, org.kuali.kfs.sys.document.web.AccountingLineTableRow)
085         */
086        public void joinRow(AccountingLineTableRow headerLabelRow, AccountingLineTableRow row) {
087            AccountingLineTableCell cell = createTableCell();
088            cell.setRowSpan(2);
089            headerLabelRow.addCell(cell);
090        }
091    
092        /**
093         * This is a field.  It's never empty.
094         * @see org.kuali.kfs.sys.document.web.RenderableElement#isEmpty()
095         */
096        public boolean isEmpty() {
097            return false;
098        }
099    
100        /**
101         * This method really doesn't do much - it assumes there are no child fields to remove
102         * @see org.kuali.kfs.sys.document.web.TableJoining#removeUnviewableBlocks()
103         */
104        public void removeUnviewableBlocks(Set<String> unviewableBlocks) {
105            // take a nap
106        }
107        
108        /**
109         * Sets this to read only if possible
110         * @see org.kuali.kfs.sys.document.web.TableJoining#readOnlyizeReadOnlyBlocks(java.util.Set)
111         */
112        public void readOnlyizeReadOnlyBlocks(Set<String> readOnlyBlocks) {
113            if (this instanceof ReadOnlyable && readOnlyBlocks.contains(getName())) {
114                ((ReadOnlyable)this).readOnlyize();
115            }
116        }
117        
118        /**
119         * @see org.kuali.kfs.sys.document.web.TableJoining#setEditableBlocks(java.util.Set)
120         */
121        public void setEditableBlocks(Set<String> editableBlocks) {
122            if (this instanceof ReadOnlyable && editableBlocks.contains(getName())) {
123                ((ReadOnlyable)this).setEditable();
124            }
125        }
126    
127        /**
128         * @see org.kuali.kfs.sys.document.web.TableJoining#performFieldTransformation(org.kuali.kfs.sys.document.service.AccountingLineFieldRenderingTransformation, org.kuali.kfs.sys.businessobject.AccountingLine, java.util.Map, java.util.Map)
129         */
130        public void performFieldTransformations(List<AccountingLineFieldRenderingTransformation> fieldTransformations, AccountingLine accountingLine, Map unconvertedValues) {
131            // don't do nothing - we don't have no child fields        
132        }
133        
134    }