View Javadoc

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