Revision 2487 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.spi/src/main/java/org/gvsig/tools/dynform/spi/dynformfield/AbstractJDynFormFieldWithValueList.java
AbstractJDynFormFieldWithValueList.java | ||
---|---|---|
24 | 24 |
package org.gvsig.tools.dynform.spi.dynformfield; |
25 | 25 |
|
26 | 26 |
import java.awt.event.FocusListener; |
27 |
import java.awt.event.ItemEvent; |
|
27 | 28 |
import java.awt.event.KeyAdapter; |
28 | 29 |
import java.awt.event.KeyEvent; |
29 | 30 |
import java.util.Objects; |
... | ... | |
36 | 37 |
import javax.swing.JSpinner; |
37 | 38 |
import javax.swing.JTextField; |
38 | 39 |
import javax.swing.UIManager; |
40 |
import javax.swing.event.ChangeEvent; |
|
41 |
import javax.swing.event.DocumentEvent; |
|
42 |
import javax.swing.event.DocumentListener; |
|
39 | 43 |
import javax.swing.text.JTextComponent; |
40 | 44 |
import org.apache.commons.lang3.StringUtils; |
41 | 45 |
|
... | ... | |
103 | 107 |
this.dropDown = ToolsSwingLocator.getToolsSwingManager().createDropDown(combo); |
104 | 108 |
this.dropDown.setModel(new DefaultComboBoxModel(availableValues)); |
105 | 109 |
this.contents = combo; |
110 |
this.dropDown.addItemListener((ItemEvent e) -> { |
|
111 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
112 |
fireFieldChangedEvent(); |
|
113 |
} |
|
114 |
}); |
|
115 |
|
|
106 | 116 |
} else if (theFactory.containsJLabel(this.getDefinition(), "Ddn")) { |
107 | 117 |
JLabel label = this.getComponentsFactory().getJLabel(this.getDefinition(), "Ddn"); |
108 | 118 |
this.dropDown = ToolsSwingLocator.getToolsSwingManager().createDropDown(label); |
109 | 119 |
this.dropDown.setModel(new DefaultComboBoxModel(availableValues)); |
110 | 120 |
this.dropDown.setVisibleDropdownArrow(true); |
111 | 121 |
this.contents = label; |
122 |
this.dropDown.addItemListener((ItemEvent e) -> { |
|
123 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
124 |
fireFieldChangedEvent(); |
|
125 |
} |
|
126 |
}); |
|
127 |
|
|
112 | 128 |
} else if (theFactory.containsJSpinner(this.getDefinition(), null)) { |
113 |
this.contents = this.getComponentsFactory().getJSpinner(this.getDefinition(), null); |
|
129 |
JSpinner spinner = this.getComponentsFactory().getJSpinner(this.getDefinition(), null); |
|
130 |
this.contents = spinner; |
|
114 | 131 |
this.dropDown = null; |
132 |
spinner.addChangeListener((ChangeEvent e) -> { |
|
133 |
fireFieldChangedEvent(); |
|
134 |
}); |
|
135 |
|
|
115 | 136 |
} else if (theFactory.containsJTextField(this.getDefinition(), null)) { |
116 |
this.contents = theFactory.getJTextField(this.getDefinition(), null); |
|
137 |
JTextComponent text = theFactory.getJTextField(this.getDefinition(), null); |
|
138 |
this.contents = text; |
|
117 | 139 |
this.dropDown = null; |
140 |
text.getDocument().addDocumentListener(new DocumentListener() { |
|
141 |
@Override |
|
142 |
public void insertUpdate(DocumentEvent e) { |
|
143 |
fireFieldChangedEvent(); |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public void removeUpdate(DocumentEvent e) { |
|
148 |
fireFieldChangedEvent(); |
|
149 |
} |
|
150 |
|
|
151 |
@Override |
|
152 |
public void changedUpdate(DocumentEvent e) { |
|
153 |
fireFieldChangedEvent(); |
|
154 |
} |
|
155 |
}); |
|
118 | 156 |
} else { |
119 | 157 |
if (availableValues == null) { |
120 | 158 |
this.dropDown = null; |
121 |
this.contents = this.getComponentsFactory().getJTextField(this.getDefinition(), null); |
|
159 |
JTextComponent text = this.getComponentsFactory().getJTextField(this.getDefinition(), null); |
|
160 |
this.contents = text; |
|
161 |
text.getDocument().addDocumentListener(new DocumentListener() { |
|
162 |
@Override |
|
163 |
public void insertUpdate(DocumentEvent e) { |
|
164 |
fireFieldChangedEvent(); |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public void removeUpdate(DocumentEvent e) { |
|
169 |
fireFieldChangedEvent(); |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public void changedUpdate(DocumentEvent e) { |
|
174 |
fireFieldChangedEvent(); |
|
175 |
} |
|
176 |
}); |
|
122 | 177 |
} else { |
123 | 178 |
String dropdownType = this.getTagValueAsString(TAG_DYNFORM_DROPDOWN, |
124 | 179 |
availableValues.length <= 20 ? "label" : "combo" |
... | ... | |
145 | 200 |
break; |
146 | 201 |
} |
147 | 202 |
} |
203 |
this.dropDown.addItemListener((ItemEvent e) -> { |
|
204 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
205 |
fireFieldChangedEvent(); |
|
206 |
} |
|
207 |
}); |
|
148 | 208 |
} |
149 | 209 |
} |
150 | 210 |
this.contents.addFocusListener(this); |
151 | 211 |
this.setReadOnly(readOnly); // Forzamos a actualiza rel estado del component |
152 | 212 |
//component dont have support to set null values |
153 |
if (theFactory.containsJSpinner(this.getDefinition(), null) && this.assignedValue==null) {
|
|
213 |
if (theFactory.containsJSpinner(this.getDefinition(), null) && this.assignedValue == null) {
|
|
154 | 214 |
this.setValue(0); |
155 | 215 |
} else { |
156 | 216 |
this.setValue(this.assignedValue); |
... | ... | |
201 | 261 |
if (this.dropDown == null) { |
202 | 262 |
JTextField jtext = this.getJTextField(); |
203 | 263 |
if (jtext != null) { |
204 |
String s; |
|
205 |
if (value == null) { |
|
206 |
this.setTranslateEmptyToNull(true); |
|
207 |
value = this.getDefinition().getDefaultValue(); |
|
208 |
if (value == null) { |
|
209 |
s = this.getDefaultValue(); |
|
210 |
} else { |
|
211 |
s = value.toString(); |
|
212 |
} |
|
213 |
} else { |
|
214 |
this.setTranslateEmptyToNull(false); |
|
215 |
s = value.toString(); |
|
216 |
try { |
|
217 |
this.getDefinition().validate(value); |
|
218 |
this.problemIndicator().clear(); |
|
219 |
} catch (DynFieldValidateException e) { |
|
220 |
this.problemIndicator().set(e.getLocalizedMessage()); |
|
221 |
} |
|
222 |
} |
|
223 |
jtext.setText(s); |
|
264 |
this.setTranslateEmptyToNull(value == null); |
|
265 |
// String s; |
|
266 |
// if (value == null) { |
|
267 |
// this.setTranslateEmptyToNull(true); |
|
268 |
// value = this.getDefinition().getDefaultValue(); |
|
269 |
// if (value == null) { |
|
270 |
// s = this.getDefaultValue(); |
|
271 |
// } else { |
|
272 |
// s = value.toString(); |
|
273 |
// } |
|
274 |
// } else { |
|
275 |
// this.setTranslateEmptyToNull(false); |
|
276 |
// s = value.toString(); |
|
277 |
// try { |
|
278 |
// this.getDefinition().validate(value); |
|
279 |
// this.problemIndicator().clear(); |
|
280 |
// } catch (DynFieldValidateException e) { |
|
281 |
// this.problemIndicator().set(e.getLocalizedMessage()); |
|
282 |
// } |
|
283 |
// } |
|
284 |
jtext.setText(Objects.toString(value, "")); |
|
224 | 285 |
} else if (this.contents instanceof JSpinner) { |
225 | 286 |
JSpinner jspinner = this.getJSpinnerField(); |
226 | 287 |
if (value == null) { |
288 |
//FIXME: Como poner un nulo a un JSpinner |
|
227 | 289 |
this.setTranslateEmptyToNull(true); |
228 | 290 |
value = this.getDefinition().getDefaultValue(); |
229 | 291 |
if (value != null) { |
Also available in: Unified diff