| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ActiveCollectionFilter |
|
| 5.0;5 |
| 1 | /** | |
| 2 | * Copyright 2005-2011 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl2.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.krad.uif.container; | |
| 17 | ||
| 18 | import org.kuali.rice.core.api.mo.common.active.Inactivatable; | |
| 19 | import org.kuali.rice.krad.uif.view.View; | |
| 20 | import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; | |
| 21 | ||
| 22 | import java.util.ArrayList; | |
| 23 | import java.util.List; | |
| 24 | ||
| 25 | /** | |
| 26 | * Collection filter that removes inactive lines from a collection whose line types | |
| 27 | * implement the <code>Inactivatable</code> interface | |
| 28 | * | |
| 29 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 30 | */ | |
| 31 | 0 | public class ActiveCollectionFilter implements CollectionFilter { |
| 32 | private static final long serialVersionUID = 3273495753269940272L; | |
| 33 | ||
| 34 | /** | |
| 35 | * Iterates through the collection and if the collection line type implements <code>Inactivatable</code>, | |
| 36 | * active indexes are added to the show indexes list | |
| 37 | * | |
| 38 | * @see CollectionFilter#filter(org.kuali.rice.krad.uif.view.View, Object, org.kuali.rice.krad.uif.container.CollectionGroup) | |
| 39 | */ | |
| 40 | @Override | |
| 41 | public List<Integer> filter(View view, Object model, CollectionGroup collectionGroup) { | |
| 42 | // get the collection for this group from the model | |
| 43 | 0 | List<Object> modelCollection = |
| 44 | ObjectPropertyUtils.getPropertyValue(model, collectionGroup.getBindingInfo().getBindingPath()); | |
| 45 | ||
| 46 | // iterate through and add only active indexes | |
| 47 | 0 | List<Integer> showIndexes = new ArrayList<Integer>(); |
| 48 | 0 | if (modelCollection != null) { |
| 49 | 0 | int lineIndex = 0; |
| 50 | 0 | for (Object line : modelCollection) { |
| 51 | 0 | if (line instanceof Inactivatable) { |
| 52 | 0 | boolean active = ((Inactivatable) line).isActive(); |
| 53 | 0 | if (active) { |
| 54 | 0 | showIndexes.add(lineIndex); |
| 55 | } | |
| 56 | } | |
| 57 | 0 | lineIndex++; |
| 58 | } | |
| 59 | } | |
| 60 | ||
| 61 | 0 | return showIndexes; |
| 62 | } | |
| 63 | } |