001/** 002 * Copyright 2005-2018 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.rice.krad.uif.container; 017 018import org.kuali.rice.core.api.mo.common.active.Inactivatable; 019import org.kuali.rice.krad.datadictionary.parse.BeanTag; 020import org.kuali.rice.krad.uif.view.View; 021import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; 022 023import java.util.ArrayList; 024import java.util.List; 025 026/** 027 * Collection filter that removes inactive lines from a collection whose line types 028 * implement the <code>Inactivatable</code> interface 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032@BeanTag(name = "activeCollectionFilter") 033public class ActiveCollectionFilter implements CollectionFilter { 034 private static final long serialVersionUID = 3273495753269940272L; 035 036 /** 037 * Iterates through the collection and if the collection line type implements <code>Inactivatable</code>, 038 * active indexes are added to the show indexes list 039 * 040 * {@inheritDoc} 041 */ 042 @Override 043 public List<Integer> filter(View view, Object model, CollectionGroup collectionGroup) { 044 // get the collection for this group from the model 045 List<Object> modelCollection = 046 ObjectPropertyUtils.getPropertyValue(model, collectionGroup.getBindingInfo().getBindingPath()); 047 048 // iterate through and add only active indexes 049 List<Integer> showIndexes = new ArrayList<Integer>(); 050 if (modelCollection != null) { 051 int lineIndex = 0; 052 for (Object line : modelCollection) { 053 if (line instanceof Inactivatable) { 054 boolean active = ((Inactivatable) line).isActive(); 055 if (active) { 056 showIndexes.add(lineIndex); 057 } 058 } 059 lineIndex++; 060 } 061 } 062 063 return showIndexes; 064 } 065}