gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / dynobject / ListItemValueField.java @ 168
History | View | Annotate | Download (3.07 KB)
1 | 168 | cmartin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | /*
|
||
23 | * AUTHORS (In addition to CIT):
|
||
24 | * 2010 Institute of New Imaging Technologies (INIT):
|
||
25 | * http://www.init.uji.es
|
||
26 | * Geographic Information research group:
|
||
27 | * http://www.geoinfo.uji.es
|
||
28 | * Universitat Jaume I, Spain
|
||
29 | */
|
||
30 | |||
31 | /**
|
||
32 | *
|
||
33 | */
|
||
34 | package org.gvsig.tools.swing.impl.dynobject; |
||
35 | |||
36 | import java.util.ArrayList; |
||
37 | import java.util.List; |
||
38 | |||
39 | import org.gvsig.tools.dynobject.DynField; |
||
40 | import org.gvsig.tools.dynobject.DynObject; |
||
41 | import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField; |
||
42 | |||
43 | /**
|
||
44 | * @author <a href="mailto:reinhold@uji.es">cmartin</a>
|
||
45 | *
|
||
46 | */
|
||
47 | public class ListItemValueField implements ValueField { |
||
48 | |||
49 | private List<Object> items; |
||
50 | private Object defaultValue; |
||
51 | |||
52 | /**
|
||
53 | * @param dynObject
|
||
54 | * @param fieldName
|
||
55 | */
|
||
56 | public ListItemValueField(DynObject dynObject,String fieldName, int index) { |
||
57 | |||
58 | Object value = dynObject.getDynValue(fieldName);
|
||
59 | |||
60 | this.items = new ArrayList<Object>(); |
||
61 | if (value!=null){ |
||
62 | this.setValue(value);
|
||
63 | return;
|
||
64 | } |
||
65 | |||
66 | DynField fieldType = dynObject.getDynClass().getDynField(fieldName); |
||
67 | this.defaultValue = fieldType.getDefaultValue();
|
||
68 | if (defaultValue!=null) |
||
69 | this.setValue(defaultValue);
|
||
70 | } |
||
71 | |||
72 | /* (non-Javadoc)
|
||
73 | * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getDefaultValue()
|
||
74 | */
|
||
75 | public Object getDefaultValue() { |
||
76 | return this.defaultValue; |
||
77 | } |
||
78 | |||
79 | /* (non-Javadoc)
|
||
80 | * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getValue()
|
||
81 | */
|
||
82 | public Object getValue() { |
||
83 | return this.items; |
||
84 | } |
||
85 | |||
86 | /* (non-Javadoc)
|
||
87 | * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getValue()
|
||
88 | */
|
||
89 | public Object getValueItem(int index) { |
||
90 | return this.items.get(index); |
||
91 | } |
||
92 | |||
93 | |||
94 | /* (non-Javadoc)
|
||
95 | * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setValue(java.lang.Object)
|
||
96 | */
|
||
97 | public void setValue(Object value) { |
||
98 | this.items = (List<Object>) value; |
||
99 | } |
||
100 | |||
101 | /* (non-Javadoc)
|
||
102 | * @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setValue(java.lang.Object)
|
||
103 | */
|
||
104 | public void setValueItem(Object item, int index) { |
||
105 | this.items.set(index, item);
|
||
106 | } |
||
107 | } |