001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 * Portions Copyright 2015 ForgeRock AS 026 */ 027 028package org.opends.guitools.controlpanel.ui.renderer; 029 030import java.awt.Component; 031 032import javax.swing.JList; 033 034import org.opends.guitools.controlpanel.datamodel.AbstractIndexDescriptor; 035import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; 036import org.opends.guitools.controlpanel.datamodel.IndexDescriptor; 037import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor; 038import org.opends.guitools.controlpanel.util.Utilities; 039 040/** 041 * The renderer to be used to render AbstractIndexDescriptor objects in a list. 042 * It marks the indexes that require to be rebuilt with a '*' character. 043 * 044 */ 045public class IndexCellRenderer extends CustomListCellRenderer 046{ 047 private ControlPanelInfo info; 048 049 /** 050 * Constructor of the index cell renderer. 051 * @param list the list whose contents will be rendered. 052 * @param info the control panel information. 053 */ 054 public IndexCellRenderer(JList list, ControlPanelInfo info) 055 { 056 super(list); 057 this.info = info; 058 } 059 060 /** {@inheritDoc} */ 061 public Component getListCellRendererComponent(JList list, Object value, 062 int index, boolean isSelected, boolean cellHasFocus) 063 { 064 boolean mustReindex = false; 065 if (value instanceof AbstractIndexDescriptor) 066 { 067 mustReindex = info.mustReindex((AbstractIndexDescriptor)value); 068 } 069 if (value instanceof IndexDescriptor) 070 { 071 String name = ((IndexDescriptor)value).getName(); 072 value = mustReindex ? name + " (*)" : name; 073 074 } else if (value instanceof VLVIndexDescriptor) 075 { 076 String name = 077 Utilities.getVLVNameInCellRenderer((VLVIndexDescriptor)value); 078 value = mustReindex ? name + " (*)" : name; 079 } 080 return super.getListCellRendererComponent( 081 list, value, index, isSelected, cellHasFocus); 082 } 083}