Revision 2548 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformfield/Boolean/JDynFormFieldBoolean.java
JDynFormFieldBoolean.java | ||
---|---|---|
26 | 26 |
import java.awt.event.FocusListener; |
27 | 27 |
import java.awt.event.ItemEvent; |
28 | 28 |
import java.awt.event.ItemListener; |
29 |
import java.util.Objects; |
|
29 | 30 |
|
30 | 31 |
import javax.swing.JCheckBox; |
32 |
import org.apache.commons.lang3.StringUtils; |
|
33 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
31 | 34 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
32 | 35 |
|
33 | 36 |
import org.gvsig.tools.dynform.JDynFormField; |
... | ... | |
51 | 54 |
super(serviceManager, componentsFactory, factory, definition, value); |
52 | 55 |
} |
53 | 56 |
|
54 |
@Override |
|
55 |
public Object getAssignedValue() { |
|
56 |
return this.assignedValue; |
|
57 |
} |
|
58 |
|
|
59 | 57 |
protected JCheckBox getJCheckBox() { |
60 | 58 |
return (JCheckBox) this.contents; |
61 | 59 |
} |
... | ... | |
73 | 71 |
if (this.getDefinition().isReadOnly()) { |
74 | 72 |
this.getJCheckBox().setEnabled(false); |
75 | 73 |
} |
76 |
this.setValue(this.assignedValue);
|
|
74 |
this.setValue(this.getAssignedValue());
|
|
77 | 75 |
} else { |
78 | 76 |
super.initComponent(); |
79 | 77 |
} |
... | ... | |
125 | 123 |
} |
126 | 124 |
} |
127 | 125 |
|
128 |
// /** |
|
129 |
// * |
|
130 |
// * @return |
|
131 |
// */ |
|
132 |
// @SuppressWarnings("unused") |
|
133 |
// @Override |
|
134 |
// public boolean hasValidValue() { |
|
135 |
// try { |
|
136 |
// Object value = this.getValue(); |
|
137 |
// } catch(Exception e) { |
|
138 |
// return false; |
|
139 |
// } |
|
140 |
// return true; |
|
141 |
// } |
|
142 |
// |
|
143 |
// @Override |
|
144 |
// public void focusGained(FocusEvent arg0) { |
|
145 |
// fireFieldEnterEvent(); |
|
146 |
// this.problemIndicator().restore(); |
|
147 |
// } |
|
148 |
// |
|
149 |
// @Override |
|
150 |
// public void focusLost(FocusEvent arg0) { |
|
151 |
// if( this.hasValidValue() ) { |
|
152 |
// this.problemIndicator().clear(); |
|
153 |
// } else { |
|
154 |
// try { |
|
155 |
// Object value = this.getValue(); |
|
156 |
// } catch(Exception e) { |
|
157 |
// this.problemIndicator().set(e.getLocalizedMessage()); |
|
158 |
// } |
|
159 |
// } |
|
160 |
// fireFieldExitEvent(); |
|
161 |
// } |
|
126 |
@Override |
|
127 |
public boolean isModified() { |
|
128 |
Boolean assigned = (Boolean) getAssignedValue(); |
|
129 |
if (this.contents instanceof JCheckBox) { |
|
130 |
boolean value = getJCheckBox().isSelected(); |
|
131 |
if(!value && assigned == null){ |
|
132 |
return false; |
|
133 |
} |
|
134 |
return !Objects.equals(value, assigned); |
|
135 |
} |
|
136 |
|
|
137 |
String s = this.getValueFromJComponent(); |
|
138 |
if (StringUtils.isBlank(s)) { |
|
139 |
return assigned != null; |
|
140 |
} |
|
141 |
|
|
142 |
try { |
|
143 |
Object value = this.getDefinition().coerce(s); |
|
144 |
return !Objects.equals(value, assigned); |
|
145 |
} catch (CoercionException e) { |
|
146 |
return true; |
|
147 |
} |
|
148 |
|
|
149 |
} |
|
150 |
|
|
162 | 151 |
} |
Also available in: Unified diff