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