View Javadoc

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.control;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.uif.view.View;
20  import org.kuali.rice.krad.uif.component.Component;
21  import org.kuali.rice.krad.uif.field.InputField;
22  
23  /**
24   * Represents a group control, which is a special control to handle
25   * the input of a KIM Group by group name
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class GroupControl extends TextControl {
30      private static final long serialVersionUID = 5598459655735440981L;
31  
32      private String namespaceCodePropertyName;
33      private String groupIdPropertyName;
34  
35      public GroupControl() {
36          super();
37      }
38  
39      @Override
40      public void performApplyModel(View view, Object model, Component parent) {
41          super.performApplyModel(view, model, parent);
42  
43          if (!(parent instanceof InputField)) {
44              return;
45          }
46  
47          InputField field = (InputField) parent;
48  
49          if (StringUtils.isNotBlank(groupIdPropertyName)) {
50              field.getHiddenPropertyNames().add(groupIdPropertyName);
51          }
52  
53          if (StringUtils.isBlank(field.getFieldLookup().getDataObjectClassName())) {
54              field.getFieldLookup().setDataObjectClassName("org.kuali.rice.kim.impl.group.GroupBo");
55          }
56  
57          if (field.getFieldLookup().getFieldConversions().isEmpty()) {
58              if (StringUtils.isNotBlank(groupIdPropertyName)) {
59                  field.getFieldLookup().getFieldConversions().put("id", groupIdPropertyName);
60              }
61  
62              field.getFieldLookup().getFieldConversions().put("name", field.getPropertyName());
63  
64              if (StringUtils.isNotBlank(namespaceCodePropertyName)) {
65                  field.getFieldLookup().getFieldConversions().put("namespaceCode", namespaceCodePropertyName);
66              }
67          }
68  
69          if (field.getFieldLookup().getLookupParameters().isEmpty()) {
70              if (StringUtils.isNotBlank(namespaceCodePropertyName)) {
71                  field.getFieldLookup().getLookupParameters().put(namespaceCodePropertyName, "namespaceCode");
72              }
73          }
74      }
75  
76      /**
77       * The name of the property on the parent object that holds the group namespace
78       *
79       * @return String namespaceCodePropertyName
80       */
81      public String getNamespaceCodePropertyName() {
82          return namespaceCodePropertyName;
83      }
84  
85      /**
86       * Setter for the name of the property on the parent object that holds the group namespace
87       *
88       * @param namespaceCodePropertyName
89       */
90      public void setNamespaceCodePropertyName(String namespaceCodePropertyName) {
91          this.namespaceCodePropertyName = namespaceCodePropertyName;
92      }
93  
94      /**
95       * The name of the property on the parent object that holds the group id
96       *
97       * @return String groupIdPropertyName
98       */
99      public String getGroupIdPropertyName() {
100         return groupIdPropertyName;
101     }
102 
103     /**
104      * Setter for the name of the property on the parent object that holds the group id
105      *
106      * @param groupIdPropertyName
107      */
108     public void setGroupIdPropertyName(String groupIdPropertyName) {
109         this.groupIdPropertyName = groupIdPropertyName;
110     }
111 }