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 static org.opends.messages.AdminToolMessages.*;
021
022import java.awt.Component;
023
024import javax.swing.JList;
025import javax.swing.ListCellRenderer;
026
027import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1;
028import org.opends.guitools.controlpanel.datamodel.VLVSortOrder;
029
030/** Class used to render elements of the class VLVSortOrder. */
031public class VLVSortOrderRenderer implements ListCellRenderer
032{
033  private ListCellRenderer defaultRenderer;
034
035  /**
036   * Constructor of the renderer.
037   * @param list the list whose elements must be rendered.
038   */
039  public VLVSortOrderRenderer(JList list)
040  {
041    this.defaultRenderer = list.getCellRenderer();
042  }
043
044  @Override
045  public Component getListCellRendererComponent(JList list, Object value,
046      int index, boolean isSelected, boolean cellHasFocus)
047  {
048    if (value instanceof VLVSortOrder)
049    {
050      VLVSortOrder v = (VLVSortOrder)value;
051      Arg1<Object> arg = v.isAscending()
052          ? INFO_CTRL_PANEL_VLV_ASCENDING_VLV_INDEX
053          : INFO_CTRL_PANEL_VLV_DESCENDING_VLV_INDEX;
054      value = arg.get(v.getAttributeName()).toString();
055    }
056    return defaultRenderer.getListCellRendererComponent(
057        list, value, index, isSelected, cellHasFocus);
058  }
059}