001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.ui.web.directory; 023 024import javax.faces.model.SelectItem; 025 026import org.apache.commons.lang.StringUtils; 027 028/** 029 * @author <a href="mailto:glefter@nuxeo.com">George Lefter</a> 030 */ 031public class DirectorySelectItem extends SelectItem { 032 033 private static final long serialVersionUID = 1L; 034 035 private String localizedLabel; 036 037 private String displayedLabel; 038 039 private long ordering; 040 041 public DirectorySelectItem(Object value, String label) { 042 this(value, label, 0); 043 } 044 045 public DirectorySelectItem(Object value, String label, long ordering) { 046 super(value, label); 047 if (value == null) { 048 throw new IllegalArgumentException("value is null"); 049 } 050 if (label == null) { 051 setLabel(""); 052 } 053 054 try { 055 this.ordering = ordering; 056 } catch (NumberFormatException nfe) { 057 this.ordering = 0; 058 } 059 } 060 061 public DirectorySelectItem(Object value, String label, long ordering, boolean disabled, boolean escape) { 062 this(value, label, ordering); 063 setDisabled(disabled); 064 setEscape(escape); 065 } 066 067 /** 068 * Gets the label as it should be displayed. 069 * 070 * @deprecated as of 6.0, use {@link #getLabel()} instead. 071 */ 072 @Deprecated 073 public String getDisplayedLabel() { 074 return displayedLabel; 075 } 076 077 /** 078 * @deprecated as of 6.0, use {@link #setLabel(String)} instead. 079 */ 080 @Deprecated 081 public void setDisplayedLabel(String displayedLabel) { 082 this.displayedLabel = displayedLabel; 083 } 084 085 /** 086 * Gets the label as it should be displayed. 087 * 088 * @deprecated as of 6.0, use {@link #getLabel()} instead. 089 */ 090 @Deprecated 091 public String getLocalizedLabel() { 092 return localizedLabel; 093 } 094 095 /** 096 * @deprecated as of 6.0, use {@link #setLabel(String)} instead. 097 */ 098 @Deprecated 099 public void setLocalizedLabel(String localizedLabel) { 100 this.localizedLabel = localizedLabel; 101 } 102 103 public long getOrdering() { 104 return ordering; 105 } 106 107 /** 108 * @deprecated since 6.0, seems useless 109 */ 110 @Deprecated 111 public String getSortLabel() { 112 return StringUtils.isBlank(localizedLabel) ? displayedLabel : localizedLabel; 113 } 114 115}