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 @ 270
History | View | Annotate | Download (3.31 KB)
1 |
/* 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 |
/*
|
73 |
* (non-Javadoc)
|
74 |
*
|
75 |
* @see
|
76 |
* org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getDefaultValue()
|
77 |
*/
|
78 |
public Object getDefaultValue() { |
79 |
return this.defaultValue; |
80 |
} |
81 |
|
82 |
/*
|
83 |
* (non-Javadoc)
|
84 |
*
|
85 |
* @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getValue()
|
86 |
*/
|
87 |
public Object getValue() { |
88 |
return this.items; |
89 |
} |
90 |
|
91 |
/*
|
92 |
* (non-Javadoc)
|
93 |
*
|
94 |
* @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getValue()
|
95 |
*/
|
96 |
public Object getValueItem(int index) { |
97 |
return this.items.get(index); |
98 |
} |
99 |
|
100 |
/*
|
101 |
* (non-Javadoc)
|
102 |
*
|
103 |
* @see
|
104 |
* org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setValue(java
|
105 |
* .lang.Object)
|
106 |
*/
|
107 |
public void setValue(Object value) { |
108 |
this.items = (List<Object>) value; |
109 |
} |
110 |
|
111 |
/*
|
112 |
* (non-Javadoc)
|
113 |
*
|
114 |
* @see
|
115 |
* org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#setValue(java
|
116 |
* .lang.Object)
|
117 |
*/
|
118 |
public void setValueItem(Object item, int index) { |
119 |
this.items.set(index, item);
|
120 |
} |
121 |
} |