001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared.value;
034:
035: import com.flexive.shared.CacheAdmin;
036: import com.flexive.shared.structure.FxSelectList;
037: import com.flexive.shared.structure.FxSelectListItem;
038:
039: import java.io.Serializable;
040: import java.util.Map;
041:
042: /**
043: * FxValue implementation for FxSelectList items with one selectable item
044: *
045: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
046: */
047: public class FxSelectOne extends FxValue<FxSelectListItem, FxSelectOne>
048: implements Serializable {
049:
050: private static final long serialVersionUID = 5125426376824746602L;
051:
052: final static FxSelectListItem EMPTY = FxSelectListItem.EMPTY;
053: private FxSelectList list = null;
054:
055: /**
056: * Constructor
057: *
058: * @param multiLanguage multilanguage value?
059: * @param defaultLanguage the default language
060: * @param translations HashMap containing language->translation mapping
061: */
062: public FxSelectOne(boolean multiLanguage, long defaultLanguage,
063: Map<Long, FxSelectListItem> translations) {
064: super (multiLanguage, defaultLanguage, translations);
065: }
066:
067: /**
068: * Constructor
069: *
070: * @param defaultLanguage the default language
071: * @param translations HashMap containing language->translation mapping
072: */
073: public FxSelectOne(long defaultLanguage,
074: Map<Long, FxSelectListItem> translations) {
075: super (defaultLanguage, translations);
076: }
077:
078: /**
079: * Constructor
080: *
081: * @param multiLanguage multilanguage value?
082: * @param translations HashMap containing language->translation mapping
083: */
084: public FxSelectOne(boolean multiLanguage,
085: Map<Long, FxSelectListItem> translations) {
086: super (multiLanguage, translations);
087: }
088:
089: /**
090: * Constructor
091: *
092: * @param translations HashMap containing language->translation mapping
093: */
094: public FxSelectOne(Map<Long, FxSelectListItem> translations) {
095: super (translations);
096: }
097:
098: /**
099: * Constructor - create value from an array of translations
100: *
101: * @param translations HashMap containing language->translation mapping
102: * @param pos position (index) in the array to use
103: */
104: public FxSelectOne(Map<Long, FxSelectListItem[]> translations,
105: int pos) {
106: super (translations, pos);
107: }
108:
109: /**
110: * Constructor
111: *
112: * @param multiLanguage multilanguage value?
113: * @param defaultLanguage the default language
114: * @param value single initializing value
115: */
116: public FxSelectOne(boolean multiLanguage, long defaultLanguage,
117: FxSelectListItem value) {
118: super (multiLanguage, defaultLanguage, value);
119: list = value.getList();
120: }
121:
122: /**
123: * Constructor
124: *
125: * @param defaultLanguage the default language
126: * @param value single initializing value
127: */
128: public FxSelectOne(long defaultLanguage, FxSelectListItem value) {
129: super (defaultLanguage, value);
130: list = value.getList();
131: }
132:
133: /**
134: * Constructor
135: *
136: * @param multiLanguage multilanguage value?
137: * @param value single initializing value
138: */
139: public FxSelectOne(boolean multiLanguage, FxSelectListItem value) {
140: super (multiLanguage, value);
141: list = value.getList();
142: }
143:
144: /**
145: * Constructor
146: *
147: * @param value single initializing value
148: */
149: public FxSelectOne(FxSelectListItem value) {
150: super (value);
151: list = value.getList();
152: }
153:
154: /**
155: * Constructor
156: *
157: * @param clone original FxValue to be cloned
158: */
159: public FxSelectOne(FxValue<FxSelectListItem, FxSelectOne> clone) {
160: super (clone);
161: list = ((FxSelectOne) clone).getSelectList();
162: }
163:
164: /**
165: * {@inheritDoc}
166: */
167: @Override
168: public Class<FxSelectListItem> getValueClass() {
169: return FxSelectListItem.class;
170: }
171:
172: /**
173: * {@inheritDoc}
174: */
175: @Override
176: public FxSelectListItem fromString(String value) {
177: list = null;
178: return CacheAdmin.getEnvironment().getSelectListItem(
179: Long.parseLong(value));
180: }
181:
182: /**
183: * {@inheritDoc}
184: */
185: @Override
186: public FxSelectOne copy() {
187: return new FxSelectOne(this );
188: }
189:
190: /**
191: * Return true if T is immutable (e.g. java.lang.String). This prevents cloning
192: * of the translations in copy constructors.
193: *
194: * @return true if T is immutable (e.g. java.lang.String)
195: */
196: @Override
197: public boolean isImmutableValueType() {
198: return true;
199: }
200:
201: /**
202: * Get the SelectList for this SelectOne
203: *
204: * @return SelectList
205: */
206: public FxSelectList getSelectList() {
207: if (list == null) {
208: if (this.isMultiLanguage()) {
209: list = this.getBestTranslation().getList();
210: } else
211: list = this.singleValue.getList();
212: }
213: return list;
214: }
215: }
|