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-2016 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 */
034public class IndexCellRenderer extends CustomListCellRenderer
035{
036  private ControlPanelInfo info;
037
038  /**
039   * Constructor of the index cell renderer.
040   * @param list the list whose contents will be rendered.
041   * @param info the control panel information.
042   */
043  public IndexCellRenderer(JList list, ControlPanelInfo info)
044  {
045    super(list);
046    this.info = info;
047  }
048
049  @Override
050  public Component getListCellRendererComponent(JList list, Object value,
051      int index, boolean isSelected, boolean cellHasFocus)
052  {
053    boolean mustReindex = false;
054    if (value instanceof AbstractIndexDescriptor)
055    {
056      mustReindex = info.mustReindex((AbstractIndexDescriptor)value);
057    }
058    if (value instanceof IndexDescriptor)
059    {
060      String name = ((IndexDescriptor)value).getName();
061      value = mustReindex ? name + " (*)" : name;
062
063    } else if (value instanceof VLVIndexDescriptor)
064    {
065      String name =
066        Utilities.getVLVNameInCellRenderer((VLVIndexDescriptor)value);
067      value = mustReindex ? name + " (*)" : name;
068    }
069    return super.getListCellRendererComponent(
070        list, value, index, isSelected, cellHasFocus);
071  }
072}