001/* 002 * (C) Copyright 2010 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 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.forms.layout.api.impl; 020 021import java.io.Serializable; 022import java.util.HashMap; 023import java.util.Map; 024 025import org.nuxeo.ecm.platform.forms.layout.api.WidgetSelectOptions; 026 027/** 028 * @author Anahide Tchertchian 029 * @since 5.4.2 030 */ 031public class WidgetSelectOptionsImpl implements WidgetSelectOptions { 032 033 private static final long serialVersionUID = 1L; 034 035 protected Serializable value; 036 037 protected String var; 038 039 protected String itemLabel; 040 041 protected Map<String, String> labels; 042 043 protected String itemValue; 044 045 protected Serializable itemDisabled; 046 047 protected Serializable itemRendered; 048 049 protected String ordering; 050 051 protected Boolean caseSensitive; 052 053 // needed by GWT serialization 054 protected WidgetSelectOptionsImpl() { 055 super(); 056 } 057 058 public WidgetSelectOptionsImpl(Serializable value, String var, String itemLabel, String itemValue) { 059 this(value, var, itemLabel, itemValue, null, null); 060 } 061 062 public WidgetSelectOptionsImpl(Serializable value, String var, String itemLabel, String itemValue, 063 Serializable itemDisabled, Serializable itemRendered) { 064 this(value, var, itemLabel, itemValue, itemDisabled, itemRendered, null, null); 065 } 066 067 public WidgetSelectOptionsImpl(Serializable value, String var, String itemLabel, String itemValue, 068 Serializable itemDisabled, Serializable itemRendered, String ordering, Boolean caseSensitive) { 069 super(); 070 this.value = value; 071 this.var = var; 072 this.itemLabel = itemLabel; 073 this.itemValue = itemValue; 074 this.itemDisabled = itemDisabled; 075 this.itemRendered = itemRendered; 076 this.ordering = ordering; 077 this.caseSensitive = caseSensitive; 078 } 079 080 public Serializable getValue() { 081 return value; 082 } 083 084 public String getVar() { 085 return var; 086 } 087 088 public String getItemLabel() { 089 return itemLabel; 090 } 091 092 @Override 093 public String getItemLabel(String locale) { 094 return labels.get(locale); 095 } 096 097 @Override 098 public Map<String, String> getItemLabels() { 099 return labels; 100 } 101 102 public void setItemLabels(Map<String, String> labels) { 103 this.labels = labels; 104 } 105 106 public String getItemValue() { 107 return itemValue; 108 } 109 110 public Serializable getItemDisabled() { 111 return itemDisabled; 112 } 113 114 public Serializable getItemRendered() { 115 return itemRendered; 116 } 117 118 public String getOrdering() { 119 return ordering; 120 } 121 122 public Boolean getCaseSensitive() { 123 return caseSensitive; 124 } 125 126 @Override 127 public String getTagConfigId() { 128 StringBuilder builder = new StringBuilder(); 129 builder.append(value).append(";"); 130 builder.append(var).append(";"); 131 builder.append(itemLabel).append(";"); 132 if (labels != null) { 133 builder.append(labels.toString()); 134 } 135 builder.append(";"); 136 builder.append(itemValue).append(";"); 137 if (itemDisabled != null) { 138 builder.append(itemDisabled.toString()); 139 } 140 builder.append(";"); 141 if (itemRendered != null) { 142 builder.append(itemRendered.toString()); 143 } 144 builder.append(";"); 145 builder.append(ordering).append(";"); 146 builder.append(caseSensitive).append(";"); 147 148 Integer intValue = new Integer(builder.toString().hashCode()); 149 return intValue.toString(); 150 } 151 152 @Override 153 public WidgetSelectOptions clone() { 154 WidgetSelectOptionsImpl clone = new WidgetSelectOptionsImpl(value, var, itemLabel, itemValue, itemDisabled, 155 itemRendered, ordering, caseSensitive); 156 if (labels != null) { 157 clone.setItemLabels(new HashMap<String, String>(labels)); 158 } 159 return clone; 160 } 161 162 /** 163 * @since 7.2 164 */ 165 @Override 166 public boolean equals(Object obj) { 167 if (!(obj instanceof WidgetSelectOptionsImpl)) { 168 return false; 169 } 170 if (obj == this) { 171 return true; 172 } 173 WidgetSelectOptionsImpl w = (WidgetSelectOptionsImpl) obj; 174 return new EqualsBuilder().append(value, w.value).append(var, w.var).append(itemLabel, w.itemLabel).append( 175 labels, w.labels).append(itemValue, w.itemValue).append(itemDisabled, w.itemDisabled).append( 176 itemRendered, w.itemRendered).append(ordering, w.ordering).isEquals(); 177 } 178}