View Javadoc

1   /**
2    * Copyright 2005-2013 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.modifier;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.uif.container.Group;
20  import org.kuali.rice.krad.uif.view.View;
21  import org.kuali.rice.krad.uif.component.Component;
22  import org.kuali.rice.krad.uif.field.Field;
23  
24  import java.util.ArrayList;
25  import java.util.HashSet;
26  import java.util.List;
27  import java.util.Set;
28  
29  /**
30   * Pulls <code>LabelField</code> instances out of a contained field so they will
31   * be placed separately in the <code>LayoutManager</code>
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class LabelFieldSeparateModifier extends ComponentModifierBase {
36  	private static final long serialVersionUID = -4304947796868636298L;
37  
38  	public LabelFieldSeparateModifier() {
39  		super();
40  	}
41  
42  	/**
43  	 * Iterates through the <code>Group</code> items and if the label field is
44  	 * not null and should be rendered, adds it to the new field list
45  	 * immediately before the <code>Field</code> item the label applies to.
46  	 * Finally the new list of components is set on the group
47  	 * 
48  	 * @see org.kuali.rice.krad.uif.modifier.ComponentModifier#performModification(org.kuali.rice.krad.uif.view.View,
49  	 *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
50  	 */
51  	@Override
52  	public void performModification(View view, Object model, Component component) {
53  		if ((component != null) && !(component instanceof Group)) {
54  			throw new IllegalArgumentException("Compare field initializer only support Group components, found type: "
55  					+ component.getClass());
56  		}
57  
58  		if (component == null) {
59  			return;
60  		}
61  
62  		// list that will be built
63  		List<Component> groupFields = new ArrayList<Component>();
64  
65  		Group group = (Group) component;
66  		for (Component item : group.getItems()) {
67  			if (item instanceof Field) {
68  				Field field = (Field) item;
69  
70  				// pull out label field
71  				if (field.getLabelField() != null && field.getLabelField().isRender()) {
72  				    field.getLabelField().addStyleClass("displayWith-" + field.getId());
73                      if (!field.isRender() && StringUtils.isBlank(field.getProgressiveRender())) {
74                         field.getLabelField().setRender(false);
75                      }
76                      else if(!field.isRender() && StringUtils.isNotBlank(field.getProgressiveRender())){
77                         field.getLabelField().setRender(true);
78                         String prefixStyle = "";
79                         if(StringUtils.isNotBlank(field.getLabelField().getStyle())){
80                             prefixStyle = field.getLabelField().getStyle();
81                         }
82                         field.getLabelField().setStyle(prefixStyle + ";" + "display: none;");
83                      }
84  
85  					groupFields.add(field.getLabelField());
86  
87  					// set boolean to indicate label field should not be
88  					// rendered with the attribute
89  					field.setLabelFieldRendered(true);
90  				}
91  			}
92  
93  			groupFields.add(item);
94  		}
95  
96  		// update group
97  		group.setItems(groupFields);
98  	}
99  
100 	/**
101 	 * @see org.kuali.rice.krad.uif.modifier.ComponentModifier#getSupportedComponents()
102 	 */
103 	@Override
104 	public Set<Class<? extends Component>> getSupportedComponents() {
105 		Set<Class<? extends Component>> components = new HashSet<Class<? extends Component>>();
106 		components.add(Group.class);
107 
108 		return components;
109 	}
110 
111 }