001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 */ 016 017package org.opends.guitools.controlpanel.ui.renderer; 018 019import javax.swing.JComboBox; 020 021import org.opends.guitools.controlpanel.datamodel.CategorizedComboBoxElement; 022import org.opends.guitools.controlpanel.datamodel.IndexDescriptor; 023import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor; 024import org.opends.guitools.controlpanel.util.Utilities; 025 026/** 027 * The renderer to be used to render CategorizedComboBoxElement objects whose 028 * values are AbstraceIndexDescriptor objects. It can be used with combo 029 * boxes. 030 * 031 */ 032public class IndexComboBoxCellRenderer extends CustomListCellRenderer 033{ 034 /** 035 * Constructor of the index renderer. 036 * @param combo the combo whose contents will be rendered. 037 */ 038 public IndexComboBoxCellRenderer(JComboBox combo) 039 { 040 super(combo); 041 } 042 043 /** 044 * Returns the String value for a given CategorizedComboBoxElement. 045 * @param desc the combo box element. 046 * @return the String value for a given CategorizedComboBoxElement. 047 */ 048 protected String getStringValue(CategorizedComboBoxElement desc) 049 { 050 String v; 051 Object value = desc.getValue(); 052 if (value instanceof IndexDescriptor) 053 { 054 v = ((IndexDescriptor)value).getName(); 055 } 056 else if (value instanceof VLVIndexDescriptor) 057 { 058 v = Utilities.getVLVNameInCellRenderer((VLVIndexDescriptor)value); 059 } 060 else 061 { 062 v = super.getStringValue(desc); 063 } 064 return v; 065 } 066}