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.datamodel; 019 020/** 021 * Class used in the combo box models. It is used to have special rendering in 022 * the combo boxes. 023 */ 024public class CategorizedComboBoxElement 025{ 026 private Object value; 027 private Type type; 028 private int hashCode; 029 030 /** 031 * The type of the element. 032 * 033 */ 034 public enum Type 035 { 036 /** 037 * Category type (in a combo box containing base DNs the backends are of 038 * type category, for instance). 039 */ 040 CATEGORY, 041 /** 042 * Regular type. 043 */ 044 REGULAR 045 } 046 047 /** 048 * Constructor. 049 * @param value the value of the element. 050 * @param type the type of the element. 051 */ 052 public CategorizedComboBoxElement(Object value, Type type) 053 { 054 this.value = value; 055 this.type = type; 056 this.hashCode = this.value.hashCode() + this.type.hashCode(); 057 } 058 059 /** 060 * Returns the value. 061 * @return the value. 062 */ 063 public Object getValue() 064 { 065 return value; 066 } 067 068 /** 069 * Returns the type of the element. 070 * @return the type of the element. 071 */ 072 public Type getType() 073 { 074 return type; 075 } 076 077 /** {@inheritDoc} */ 078 public boolean equals(Object o) 079 { 080 if (o instanceof CategorizedComboBoxElement) 081 { 082 CategorizedComboBoxElement desc = (CategorizedComboBoxElement)o; 083 return desc.getType() == getType() 084 && getValue().equals(desc.getValue()); 085 } 086 return false; 087 } 088 089 /** {@inheritDoc} */ 090 public int hashCode() 091 { 092 return hashCode; 093 } 094}