001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.krad.uif.control;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.uif.view.View;
020import org.kuali.rice.krad.uif.component.Component;
021import org.kuali.rice.krad.uif.field.InputField;
022
023/**
024 * Represents a group control, which is a special control to handle
025 * the input of a KIM Group by group name
026 *
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029public class GroupControl extends TextControl {
030    private static final long serialVersionUID = 5598459655735440981L;
031
032    private String namespaceCodePropertyName;
033    private String groupIdPropertyName;
034
035    public GroupControl() {
036        super();
037    }
038
039    @Override
040    public void performApplyModel(View view, Object model, Component parent) {
041        super.performApplyModel(view, model, parent);
042
043        if (!(parent instanceof InputField)) {
044            return;
045        }
046
047        InputField field = (InputField) parent;
048
049        if (StringUtils.isNotBlank(groupIdPropertyName)) {
050            field.getHiddenPropertyNames().add(groupIdPropertyName);
051        }
052
053        if (StringUtils.isBlank(field.getFieldLookup().getDataObjectClassName())) {
054            field.getFieldLookup().setDataObjectClassName("org.kuali.rice.kim.impl.group.GroupBo");
055        }
056
057        if (field.getFieldLookup().getFieldConversions().isEmpty()) {
058            if (StringUtils.isNotBlank(groupIdPropertyName)) {
059                field.getFieldLookup().getFieldConversions().put("id", groupIdPropertyName);
060            }
061
062            field.getFieldLookup().getFieldConversions().put("name", field.getPropertyName());
063
064            if (StringUtils.isNotBlank(namespaceCodePropertyName)) {
065                field.getFieldLookup().getFieldConversions().put("namespaceCode", namespaceCodePropertyName);
066            }
067        }
068
069        if (field.getFieldLookup().getLookupParameters().isEmpty()) {
070            if (StringUtils.isNotBlank(namespaceCodePropertyName)) {
071                field.getFieldLookup().getLookupParameters().put(namespaceCodePropertyName, "namespaceCode");
072            }
073        }
074    }
075
076    /**
077     * The name of the property on the parent object that holds the group namespace
078     *
079     * @return String namespaceCodePropertyName
080     */
081    public String getNamespaceCodePropertyName() {
082        return namespaceCodePropertyName;
083    }
084
085    /**
086     * Setter for the name of the property on the parent object that holds the group namespace
087     *
088     * @param namespaceCodePropertyName
089     */
090    public void setNamespaceCodePropertyName(String namespaceCodePropertyName) {
091        this.namespaceCodePropertyName = namespaceCodePropertyName;
092    }
093
094    /**
095     * The name of the property on the parent object that holds the group id
096     *
097     * @return String groupIdPropertyName
098     */
099    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}