001 /** 002 * Copyright 2005-2013 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.rice.krad.uif.modifier; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.krad.datadictionary.parse.BeanTag; 020 import org.kuali.rice.krad.uif.container.Group; 021 import org.kuali.rice.krad.uif.view.View; 022 import org.kuali.rice.krad.uif.component.Component; 023 import org.kuali.rice.krad.uif.field.Field; 024 025 import java.util.ArrayList; 026 import java.util.HashSet; 027 import java.util.List; 028 import java.util.Set; 029 030 /** 031 * Pulls <code>Label</code> instances out of a contained field so they will 032 * be placed separately in the <code>LayoutManager</code> 033 * 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 */ 036 @BeanTag(name = "labelSeparator-modifier-bean", parent = "Uif-LabelSeparator-Modifier") 037 public class LabelSeparateModifier extends ComponentModifierBase { 038 private static final long serialVersionUID = -4304947796868636298L; 039 040 public LabelSeparateModifier() { 041 super(); 042 } 043 044 /** 045 * Iterates through the <code>Group</code> items and if the label field is 046 * not null and should be rendered, adds it to the new field list 047 * immediately before the <code>Field</code> item the label applies to. 048 * Finally the new list of components is set on the group 049 * 050 * @see org.kuali.rice.krad.uif.modifier.ComponentModifier#performModification(org.kuali.rice.krad.uif.view.View, 051 * java.lang.Object, org.kuali.rice.krad.uif.component.Component) 052 */ 053 @Override 054 public void performModification(View view, Object model, Component component) { 055 if ((component != null) && !(component instanceof Group)) { 056 throw new IllegalArgumentException("Compare field initializer only support Group components, found type: " 057 + component.getClass()); 058 } 059 060 if (component == null) { 061 return; 062 } 063 064 // list that will be built 065 List<Component> groupFields = new ArrayList<Component>(); 066 067 Group group = (Group) component; 068 for (Component item : group.getItems()) { 069 if (item instanceof Field) { 070 Field field = (Field) item; 071 072 // pull out label field 073 if (field.getFieldLabel() != null && field.getFieldLabel().isRender()) { 074 field.getFieldLabel().addStyleClass("displayWith-" + field.getId()); 075 if (!field.isRender() && StringUtils.isBlank(field.getProgressiveRender())) { 076 field.getFieldLabel().setRender(false); 077 } 078 else if(!field.isRender() && StringUtils.isNotBlank(field.getProgressiveRender())){ 079 field.getFieldLabel().setRender(true); 080 String prefixStyle = ""; 081 if(StringUtils.isNotBlank(field.getFieldLabel().getStyle())){ 082 prefixStyle = field.getFieldLabel().getStyle(); 083 } 084 field.getFieldLabel().setStyle(prefixStyle + ";" + "display: none;"); 085 } 086 087 groupFields.add(field.getFieldLabel()); 088 089 // set boolean to indicate label field should not be 090 // rendered with the attribute 091 field.setLabelRendered(true); 092 } 093 } 094 095 groupFields.add(item); 096 } 097 098 // update group 099 group.setItems(groupFields); 100 } 101 102 /** 103 * @see org.kuali.rice.krad.uif.modifier.ComponentModifier#getSupportedComponents() 104 */ 105 @Override 106 public Set<Class<? extends Component>> getSupportedComponents() { 107 Set<Class<? extends Component>> components = new HashSet<Class<? extends Component>>(); 108 components.add(Group.class); 109 110 return components; 111 } 112 113 }