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.datadictionary; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import org.kuali.kfs.sys.businessobject.AccountingLine; 022 import org.kuali.kfs.sys.document.web.AccountingLineViewMultipleReadOnlyFields; 023 import org.kuali.kfs.sys.document.web.TableJoining; 024 import org.kuali.rice.kns.datadictionary.DataDictionaryDefinitionBase; 025 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException; 026 import org.kuali.rice.kns.util.FieldUtils; 027 import org.kuali.rice.kns.web.ui.Field; 028 029 /** 030 * The definition for an accounting line component which displays multiple fields from the command line, but 031 * all of them as read only, with their headers displayed first 032 */ 033 public class AccountingLineViewMultipleReadOnlyFieldsDefinition extends DataDictionaryDefinitionBase implements AccountingLineViewRenderableElementDefinition { 034 public List<String> fieldNames; 035 036 /** 037 * Makes sure that the number of fields set is greater than 0 038 * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class) 039 */ 040 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { 041 if (fieldNames.isEmpty()) { 042 throw new AttributeValidationException("Please specify one or more field names when defining AccountingLineViewMultipleReadOnlyFields "+getId()); 043 } 044 } 045 046 /** 047 * Creates a new AccountingLineViewMultipleReadOnlyField 048 * @see org.kuali.kfs.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement(java.lang.Class) 049 */ 050 public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) { 051 List<Field> fields = new ArrayList<Field>(); 052 for (String fieldName: fieldNames) { 053 fields.add(getKNSFieldForDefinition(accountingLineClass, fieldName)); 054 } 055 return new AccountingLineViewMultipleReadOnlyFields(this, fields); 056 } 057 058 /** 059 * Creates a KNS Field for an AccountingLineViewField definition 060 * @param accountingLineClass the class of the accounting line used by this definition 061 * @param fieldName the name of the field to initialize 062 * @return a properly initialized KNS field 063 */ 064 public Field getKNSFieldForDefinition(Class<? extends AccountingLine> accountingLineClass, String fieldName) { 065 Field realField = FieldUtils.getPropertyField(accountingLineClass, fieldName, false); 066 return realField; 067 } 068 069 /** 070 * @return the field names of fields to display in the cell 071 */ 072 public List<String> getFieldNames() { 073 return fieldNames; 074 } 075 076 /** 077 * Sets the field names to display in the field, in top-down order 078 * @param fieldNames the field names to display 079 */ 080 public void setFieldNames(List<String> fieldNames) { 081 this.fieldNames = fieldNames; 082 } 083 084 }