Revision 281 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/dynfield/JComboBoxDynFieldComponent.java
JComboBoxDynFieldComponent.java | ||
---|---|---|
45 | 45 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
46 | 46 |
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener; |
47 | 47 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
48 |
import org.gvsig.tools.swing.spi.DelegatedJFieldComponent;
|
|
48 |
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
|
|
49 | 49 |
|
50 | 50 |
/** |
51 |
* @author <a href="mailto:reinhold@uji.es">cmartin</a> |
|
52 | 51 |
* |
52 |
* JDynFieldComponent that renders its available values in the form of a {@link JComboBox}. |
|
53 |
* |
|
54 |
* @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team |
|
55 |
* @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n </a> - gvSIG Team |
|
56 |
* @version $Id$ |
|
57 |
* |
|
53 | 58 |
*/ |
54 | 59 |
public class JComboBoxDynFieldComponent extends DelegatedJFieldComponent |
55 | 60 |
implements JDynFieldComponent, ItemListener { |
56 | 61 |
|
57 | 62 |
private JComboBox combo; |
63 |
|
|
58 | 64 |
private DynObjectValueItem[] items; |
59 | 65 |
private List<ValueChangedListener> listeners; |
60 | 66 |
|
61 | 67 |
/** |
68 |
* Constructor. |
|
69 |
* |
|
62 | 70 |
* @param component |
71 |
* the JDynFieldComponent object |
|
72 |
* |
|
73 |
* @param valueField |
|
74 |
* the ValueField object. |
|
63 | 75 |
*/ |
64 | 76 |
public JComboBoxDynFieldComponent(JDynFieldComponent component, |
65 |
DynField dynField) {
|
|
66 |
super(component, dynField);
|
|
77 |
ValueField valueField) {
|
|
78 |
super(component, valueField);
|
|
67 | 79 |
} |
68 | 80 |
|
69 | 81 |
/** |
70 | 82 |
* |
71 | 83 |
*/ |
72 | 84 |
protected void afterUI() { |
73 |
Object value = this.getFieldValue();
|
|
85 |
Object value = this.getInitialValue();
|
|
74 | 86 |
Object item; |
75 | 87 |
if (value != null) |
76 | 88 |
for (int i = 0; i < this.items.length; i++) { |
... | ... | |
217 | 229 |
* .Object) |
218 | 230 |
*/ |
219 | 231 |
|
220 |
public void setValue(Object value) { |
|
221 |
if (value == null) |
|
222 |
this.combo.setSelectedIndex(0); |
|
232 |
|
|
223 | 233 |
|
224 |
Object item; |
|
225 |
for (int i = 0; i < this.items.length; i++) { |
|
226 |
item = this.items[i].getValue(); |
|
227 |
if (item == null) |
|
228 |
continue; |
|
229 |
|
|
230 |
if (item.equals(value)) { |
|
231 |
this.combo.setSelectedIndex(i + 1); |
|
232 |
break; |
|
233 |
} |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 | 234 |
/* |
238 | 235 |
* (non-Javadoc) |
239 | 236 |
* |
... | ... | |
258 | 255 |
for (ValueChangedListener listener : this.listeners) |
259 | 256 |
listener.handleValueChanged(this); |
260 | 257 |
} |
258 |
|
|
259 |
@Override |
|
260 |
protected void setNonNullValue(Object value) { |
|
261 |
Object item; |
|
262 |
for (int i = 0; i < this.items.length; i++) { |
|
263 |
item = this.items[i].getValue(); |
|
264 |
if (item == null) |
|
265 |
continue; |
|
266 |
|
|
267 |
if (item.equals(value)) { |
|
268 |
this.combo.setSelectedIndex(i + 1); |
|
269 |
break; |
|
270 |
} |
|
271 |
} |
|
272 |
} |
|
273 |
|
|
274 |
@Override |
|
275 |
protected void setNullValue() { |
|
276 |
this.combo.setSelectedIndex(0); |
|
277 |
} |
|
261 | 278 |
} |
Also available in: Unified diff