01: /*
02: * Copyright 2006-2007 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.romaframework.core.domain.wrapper;
17:
18: import java.util.Arrays;
19: import java.util.List;
20: import java.util.Set;
21:
22: import org.romaframework.aspect.core.annotation.AnnotationConstants;
23: import org.romaframework.aspect.view.annotation.ViewAction;
24: import org.romaframework.aspect.view.annotation.ViewField;
25: import org.romaframework.aspect.view.feature.ViewFieldFeatures;
26:
27: public class SelectWrapper<T> extends TableEditWrapper {
28: public SelectWrapper(Set<T> selectValues) {
29: values = selectValues.toArray((T[]) new Object[selectValues
30: .size()]);
31: }
32:
33: public SelectWrapper(Set<T> selectValues, T iInitialValue) {
34: values = selectValues.toArray((T[]) new Object[selectValues
35: .size()]);
36: selected = iInitialValue;
37: }
38:
39: @ViewField(label="",render="select",selectionField="selected",selectionMode=ViewFieldFeatures.SELECTION_MODE_VALUE)
40: protected T[] values;
41: @ViewField(visible=AnnotationConstants.FALSE)
42: protected T selected;
43:
44: public T getSelected() {
45: return selected;
46: }
47:
48: public void setSelected(T command) {
49: this .selected = command;
50: }
51:
52: public T[] getValues() {
53: return values;
54: }
55:
56: public void setValues(T[] commands) {
57: this .values = commands;
58: }
59:
60: @Override
61: public Object getFinalValue() {
62: return selected;
63: }
64:
65: @ViewAction(visible=AnnotationConstants.FALSE)
66: public void addElements(Set<T> iToAdd) {
67: List<T> aux = Arrays.asList(values);
68: aux.addAll(iToAdd);
69: values = aux.toArray((T[]) new Object[aux.size()]);
70: }
71: }
|