001/** 002 * Copyright 2005-2017 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.krms.impl.validation; 017 018import org.kuali.rice.core.api.uif.RemotableAttributeField; 019import org.kuali.rice.core.api.uif.RemotableRadioButtonGroup; 020import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition; 021 022import java.util.ArrayList; 023import java.util.List; 024import java.util.Map; 025 026/** 027 * Utility for creating RemotableRadioButtonGroups given a {@link KrmsAttributeDefinition} and a Map<String, String> of (Radio Button) Values and Labels 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030public class RadioButtonTypeServiceUtil { 031 032 /** 033 * RemotableRadioButtonGroups given a {@link KrmsAttributeDefinition} and a Map<String, String> of (Radio Button) Values and Labels. 034 * @param krmsAttributeDefinition 035 * @param valueLabels 036 * @return RemotableAttributeField 037 */ 038 RemotableAttributeField translateTypeAttribute(KrmsAttributeDefinition krmsAttributeDefinition, Map<String, String> valueLabels) { 039 040 RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(krmsAttributeDefinition.getName()); 041 042 RemotableRadioButtonGroup.Builder controlBuilder = RemotableRadioButtonGroup.Builder.create(valueLabels); 043 044 builder.setLongLabel(krmsAttributeDefinition.getLabel()); 045 builder.setName(krmsAttributeDefinition.getName()); 046 builder.setRequired(true); 047 List<String> defaultValue = new ArrayList<String>(); 048 defaultValue.add((String) valueLabels.keySet().toArray()[0]); // First value 049// defaultValue.add(valueLabels.get(valueLabels.keySet().toArray()[0])); // First label 050// defaultValue.add("1"); // index 051 builder.setDefaultValues(defaultValue); 052 builder.setControl(controlBuilder); 053 054 return builder.build(); 055 } 056}