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 * Portions Copyright 2015 ForgeRock AS. 016 */ 017 018package org.opends.guitools.controlpanel.ui.renderer; 019 020import java.awt.Component; 021 022import javax.swing.JList; 023 024import org.opends.guitools.controlpanel.datamodel.AbstractIndexDescriptor; 025import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; 026import org.opends.guitools.controlpanel.datamodel.IndexDescriptor; 027import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor; 028import org.opends.guitools.controlpanel.util.Utilities; 029 030/** 031 * The renderer to be used to render AbstractIndexDescriptor objects in a list. 032 * It marks the indexes that require to be rebuilt with a '*' character. 033 * 034 */ 035public class IndexCellRenderer extends CustomListCellRenderer 036{ 037 private ControlPanelInfo info; 038 039 /** 040 * Constructor of the index cell renderer. 041 * @param list the list whose contents will be rendered. 042 * @param info the control panel information. 043 */ 044 public IndexCellRenderer(JList list, ControlPanelInfo info) 045 { 046 super(list); 047 this.info = info; 048 } 049 050 /** {@inheritDoc} */ 051 public Component getListCellRendererComponent(JList list, Object value, 052 int index, boolean isSelected, boolean cellHasFocus) 053 { 054 boolean mustReindex = false; 055 if (value instanceof AbstractIndexDescriptor) 056 { 057 mustReindex = info.mustReindex((AbstractIndexDescriptor)value); 058 } 059 if (value instanceof IndexDescriptor) 060 { 061 String name = ((IndexDescriptor)value).getName(); 062 value = mustReindex ? name + " (*)" : name; 063 064 } else if (value instanceof VLVIndexDescriptor) 065 { 066 String name = 067 Utilities.getVLVNameInCellRenderer((VLVIndexDescriptor)value); 068 value = mustReindex ? name + " (*)" : name; 069 } 070 return super.getListCellRendererComponent( 071 list, value, index, isSelected, cellHasFocus); 072 } 073}