Revision 1405 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/AbstractJDynFormField.java

View differences:

AbstractJDynFormField.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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 3
9
 * of the License, or (at your option) any later version.
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10 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.
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15 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.
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
package org.gvsig.tools.dynform.spi.dynformfield;
25 24

  
......
51 50
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
52 51
import org.gvsig.tools.dynobject.DynField_v2;
53 52
import org.gvsig.tools.dynobject.DynObject;
53
import org.gvsig.tools.dynobject.Tags;
54 54
import org.gvsig.tools.service.Manager;
55 55
import org.gvsig.tools.service.spi.ServiceManager;
56 56
import org.slf4j.Logger;
57 57
import org.slf4j.LoggerFactory;
58 58

  
59 59
@SuppressWarnings({"rawtypes", "unchecked"})
60
public abstract class AbstractJDynFormField implements JDynFormField{
60
public abstract class AbstractJDynFormField implements JDynFormField {
61 61

  
62
	protected static final Logger logger = LoggerFactory
63
			.getLogger(AbstractJDynFormField.class);
64
	
65
	private DynFormSPIManager manager = null;
66
	private DynFormFieldDefinition definition = null;
67
	private JLabel jlabel = null;
68
	private JPanel jlabelpanel = null;
69
	private Set listeners = null;
70
	private JProblemIndicator problemIndicator = null;
62
    protected static final Logger logger = LoggerFactory
63
            .getLogger(AbstractJDynFormField.class);
71 64

  
72
	protected DynObject parameters = null;
73
	protected JComponent contents = null;
65
    private DynFormSPIManager manager = null;
66
    private DynFormFieldDefinition definition = null;
67
    private JLabel jlabel = null;
68
    private JPanel jlabelpanel = null;
69
    private Set listeners = null;
70
    private JProblemIndicator problemIndicator = null;
74 71

  
75
	private boolean readOnly = false;
76
	private List customActions;
77
	protected boolean emptyToNull = false;
72
    protected DynObject parameters = null;
73
    protected JComponent contents = null;
74

  
75
    private boolean readOnly = false;
76
    private final List customActions;
77
    protected boolean emptyToNull = false;
78 78
    private JDynForm form;
79 79

  
80
    public AbstractJDynFormField(DynObject parameters,
81
            ServiceManager serviceManager) {
82
        this.parameters = parameters;
83
        this.manager = (DynFormSPIManager) serviceManager;
84
        this.definition = this.getDefinition();
85
        this.listeners = new HashSet();
86
        this.readOnly = this.definition.isReadOnly();
87
        this.problemIndicator = this.manager.createProblemIndicator(this);
88
        this.customActions = new ArrayList<>();
89
        this.loadDefaultValuesFromTags(definition.getTags());
90
    }
80 91

  
81
	public AbstractJDynFormField(DynObject parameters,
82
			ServiceManager serviceManager) {
83
		this.parameters = parameters;
84
		this.manager = (DynFormSPIManager) serviceManager;
85
		this.definition = this.getDefinition();
86
		this.listeners = new HashSet();
87
		this.readOnly = this.definition.isReadOnly();
88
		this.problemIndicator = this.manager.createProblemIndicator(this);
89
		this.customActions = new ArrayList<Action>();
90
	}
92
    public void loadDefaultValuesFromTags(Tags tags) {
93
        try {
94
            this.readOnly = tags.getBoolean(DynFormSPIManager.TAG_DYNFORM_READONLY);
95
        } catch (CoercionException ex) {
96
        }
97
        try {
98
            this.emptyToNull = tags.getBoolean(DynFormSPIManager.TAG_DYNFORM_TRANSLATE_EMPTY_TO_NULL);
99
        } catch (CoercionException ex) {
100
        }
101
    }
91 102

  
92
	public abstract void initComponent();
93
	public abstract Object getAssignedValue();
103
    public abstract void initComponent();
94 104

  
95
	public Object getParameterValue() {
96
		return this.parameters.getDynValue(DynFormSPIManager.FIELD_VALUE);
97
	}
105
    public abstract Object getAssignedValue();
98 106

  
99
	public JComponent asJComponent() {
100
		if (this.contents == null) {
101
			this.initComponent();
102
			if(!this.customActions.isEmpty()){
103
				addPopupComponents();
104
			}
105
			if( this.readOnly ) {
106
				this.setReadOnly(readOnly);
107
			}
108
		}
109
		return this.contents;
110
	}
107
    public Object getParameterValue() {
108
        return this.parameters.getDynValue(DynFormSPIManager.FIELD_VALUE);
109
    }
111 110

  
112
	public String getName() {
113
		return this.definition.getName();
114
	}
111
    @Override
112
    public JComponent asJComponent() {
113
        if (this.contents == null) {
114
            this.initComponent();
115
            if (!this.customActions.isEmpty()) {
116
                addPopupComponents();
117
            }
118
            if (this.readOnly) {
119
                this.setReadOnly(readOnly);
120
            }
121
        }
122
        return this.contents;
123
    }
115 124

  
116
	public String getLabel() {
117
		if(definition.getLabel() != null)
118
			return definition.getLabel();
119
		else
120
			return this.getName();
121
	}
125
    public String getName() {
126
        return this.definition.getName();
127
    }
122 128

  
123
	public JComponent getJLabel() {
124
		if (this.jlabel == null) {
125
                        if( getTagValueAsBoolean("dynform.label.empty", false) ) {
126
                            this.jlabel = new JLabel("");
127
                        } else {
128
                            this.jlabel = new JLabel(this.getLabel());
129
                        }
130
			this.jlabel.setLabelFor(this.contents);
131
			if( this.getDefinition().isMandatory() ) {
132
				this.jlabel.setForeground(Color.red.darker());
133
			}
134
			this.jlabelpanel = new JPanel();
135
			this.jlabelpanel.setLayout(new BorderLayout());
136
			this.jlabelpanel.add(jlabel,BorderLayout.CENTER);
137
			this.jlabelpanel.add(problemIndicator.asJComponent(), BorderLayout.LINE_END);
138
		}
139
		return this.jlabelpanel;
140
	}
129
    public String getLabel() {
130
        if (definition.getLabel() != null) {
131
            return definition.getLabel();
132
        } else {
133
            return this.getName();
134
        }
135
    }
141 136

  
142
	public DynFormFieldDefinition getDefinition() {
143
		return (DynFormFieldDefinition) this.parameters
144
				.getDynValue(DynFormSPIManager.FIELD_FIELDDEFINITION);
145
	}
137
    public JComponent getJLabel() {
138
        if (this.jlabel == null) {
139
            if (getTagValueAsBoolean(DynFormSPIManager.TAG_DYNFORM_LABEL_EMPTY, false)) {
140
                this.jlabel = new JLabel("");
141
            } else {
142
                this.jlabel = new JLabel(this.getLabel());
143
            }
144
            this.jlabel.setLabelFor(this.contents);
145
            if (this.getDefinition().isMandatory()) {
146
                this.jlabel.setForeground(Color.red.darker());
147
            }
148
            this.jlabelpanel = new JPanel();
149
            this.jlabelpanel.setLayout(new BorderLayout());
150
            this.jlabelpanel.add(jlabel, BorderLayout.CENTER);
151
            this.jlabelpanel.add(problemIndicator.asJComponent(), BorderLayout.LINE_END);
152
        }
153
        return this.jlabelpanel;
154
    }
146 155

  
147
	public Manager getManager() {
148
		return this.manager;
149
	}
150
	
151
	public DynFormSPIManager getServiceManager(){
152
		return this.manager;
153
	}
156
    public DynFormFieldDefinition getDefinition() {
157
        return (DynFormFieldDefinition) this.parameters
158
                .getDynValue(DynFormSPIManager.FIELD_FIELDDEFINITION);
159
    }
154 160

  
155
	public void addListener(JDynFormFieldListener listener) {
156
		this.listeners.add(listener);
157
	}
161
    public Manager getManager() {
162
        return this.manager;
163
    }
158 164

  
159
	public void removeListener(JDynFormFieldListener listener) {
160
		this.listeners.remove(listener);
161
	}
162
	
163
	protected void fireFieldChangedEvent() {
164
		Iterator it = this.listeners.iterator();
165
		while (it.hasNext()) {
166
			JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
167
			try {
168
				listener.fieldChanged(this);
169
			} catch (Exception ex) {
170
				logger.info("Error calling listener " + listener.toString()
171
						+ "(" + listener.getClass().getName() + ") from "
172
						+ this.toString() + "(" + this.getClass().getName()
173
						+ ").", ex);
174
			}
175
		}
176
	}
165
    public DynFormSPIManager getServiceManager() {
166
        return this.manager;
167
    }
177 168

  
178
	protected void fireFieldEnterEvent() {
179
		Iterator it = this.listeners.iterator();
180
		while (it.hasNext()) {
181
			JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
182
			try {
183
				listener.fieldEnter(this);
184
			} catch (Exception ex) {
185
				logger.info("Error calling listener " + listener.toString()
186
						+ "(" + listener.getClass().getName() + ") from "
187
						+ this.toString() + "(" + this.getClass().getName()
188
						+ ").", ex);
189
			}
190
		}
191
	}
169
    public void addListener(JDynFormFieldListener listener) {
170
        this.listeners.add(listener);
171
    }
192 172

  
193
	protected void fireFieldExitEvent() {
194
		Iterator it = this.listeners.iterator();
195
		while (it.hasNext()) {
196
			JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
197
			try {
198
				listener.fieldExit(this);
199
			} catch (Exception ex) {
200
				logger.info("Error calling listener " + listener.toString()
201
						+ "(" + listener.getClass().getName() + ") from "
202
						+ this.toString() + "(" + this.getClass().getName()
203
						+ ").", ex);
204
			}
205
		}
206
	}
207
	
208
	public void fireMessageEvent(String message) {
209
		Iterator it = this.listeners.iterator();
210
		while (it.hasNext()) {
211
			JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
212
			try {
213
				listener.message(this, message);
214
			} catch (Exception ex) {
215
				logger.info("Error calling listener " + listener.toString()
216
						+ "(" + listener.getClass().getName() + ") from "
217
						+ this.toString() + "(" + this.getClass().getName()
218
						+ ").", ex);
219
			}
220
		}
221
	}
173
    public void removeListener(JDynFormFieldListener listener) {
174
        this.listeners.remove(listener);
175
    }
222 176

  
223
	public boolean isReadOnly() {
224
		return this.readOnly ;
225
	}
226
	
227
	public void setReadOnly(boolean readonly) {
177
    protected void fireFieldChangedEvent() {
178
        Iterator it = this.listeners.iterator();
179
        while (it.hasNext()) {
180
            JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
181
            try {
182
                listener.fieldChanged(this);
183
            } catch (Exception ex) {
184
                logger.info("Error calling listener " + listener.toString()
185
                        + "(" + listener.getClass().getName() + ") from "
186
                        + this.toString() + "(" + this.getClass().getName()
187
                        + ").", ex);
188
            }
189
        }
190
    }
191

  
192
    protected void fireFieldEnterEvent() {
193
        Iterator it = this.listeners.iterator();
194
        while (it.hasNext()) {
195
            JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
196
            try {
197
                listener.fieldEnter(this);
198
            } catch (Exception ex) {
199
                logger.info("Error calling listener " + listener.toString()
200
                        + "(" + listener.getClass().getName() + ") from "
201
                        + this.toString() + "(" + this.getClass().getName()
202
                        + ").", ex);
203
            }
204
        }
205
    }
206

  
207
    protected void fireFieldExitEvent() {
208
        Iterator it = this.listeners.iterator();
209
        while (it.hasNext()) {
210
            JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
211
            try {
212
                listener.fieldExit(this);
213
            } catch (Exception ex) {
214
                logger.info("Error calling listener " + listener.toString()
215
                        + "(" + listener.getClass().getName() + ") from "
216
                        + this.toString() + "(" + this.getClass().getName()
217
                        + ").", ex);
218
            }
219
        }
220
    }
221

  
222
    public void fireMessageEvent(String message) {
223
        Iterator it = this.listeners.iterator();
224
        while (it.hasNext()) {
225
            JDynFormFieldListener listener = (JDynFormFieldListener) it.next();
226
            try {
227
                listener.message(this, message);
228
            } catch (Exception ex) {
229
                logger.info("Error calling listener " + listener.toString()
230
                        + "(" + listener.getClass().getName() + ") from "
231
                        + this.toString() + "(" + this.getClass().getName()
232
                        + ").", ex);
233
            }
234
        }
235
    }
236

  
237
    public boolean isReadOnly() {
238
        return this.readOnly;
239
    }
240

  
241
    public void setReadOnly(boolean readonly) {
228 242
		// FIXME: Implememtacion por defecto, sobreescribirla en las subclases
229
		// segun convenga para cada componente.
230
		JTextComponent x = null;
231
				
232
		this.readOnly = readonly;
233
		if(jlabel != null){
234
			this.jlabel.setEnabled(!readonly);
235
		}
236
		if( this.contents != null ) {
237
			if( this.contents instanceof JTextComponent ) {
238
				x = (JTextComponent) this.contents;
239
				x.setEditable(!readonly);
240
			} else if( this.contents instanceof JScrollPane ) {
241
				try {
242
					JViewport port = ((JScrollPane)this.contents).getViewport();
243
					x = (JTextComponent)  port.getView();
244
					x.setEditable(!readonly);
245
				} catch(Exception ex) {
246
					this.contents.setEnabled(!readOnly);
247
				}
248
			} else {
249
				this.contents.setEnabled(!readOnly);
250
			}
251
		}
252
	}
243
        // segun convenga para cada componente.
244
        JTextComponent x = null;
253 245

  
254
	public JProblemIndicator problemIndicator() {
255
		return this.problemIndicator;
256
	}
246
        this.readOnly = readonly;
247
        if (jlabel != null) {
248
            this.jlabel.setEnabled(!readonly);
249
        }
250
        if (this.contents != null) {
251
            if (this.contents instanceof JTextComponent) {
252
                x = (JTextComponent) this.contents;
253
                x.setEditable(!readonly);
254
            } else if (this.contents instanceof JScrollPane) {
255
                try {
256
                    JViewport port = ((JScrollPane) this.contents).getViewport();
257
                    x = (JTextComponent) port.getView();
258
                    x.setEditable(!readonly);
259
                } catch (Exception ex) {
260
                    this.contents.setEnabled(!readOnly);
261
                }
262
            } else {
263
                this.contents.setEnabled(!readOnly);
264
            }
265
        }
266
    }
257 267

  
258
	public class IllegalFieldValue extends RuntimeException {
259
		
260
		/**
261
		 * 
262
		 */
263
		private static final long serialVersionUID = -4409236610055983438L;
268
    public JProblemIndicator problemIndicator() {
269
        return this.problemIndicator;
270
    }
264 271

  
265
		public IllegalFieldValue(JDynFormField field, String message) {
266
			super("The value of field '"+field.getLabel()+"' is not valid. " + message);
267
		}
268
	}
269
	
270
	public String toString() {
271
		return super.toString() + "{" + this.getName() + "}";
272
	}
273
	
274
	public boolean isModified() {
275
		boolean modified = false;
276
		try {
277
			if( !this.isReadOnly() ) {
278
				Object value = this.getValue();
279
				if( value == null ) {
280
					if( value != this.getAssignedValue() ) {
281
						modified = true;
282
					}
283
				} else {
284
					if( ! value.equals(this.getAssignedValue()) ) {
285
						modified = true;
286
					}
287
				}
288
			}
289
		} catch(IllegalFieldValue ex) {
290
			// Si es incorrecto el valor del campo decimos a capom que esta modificado.
291
			modified = true;
292
		}
293
		return modified;
294
	}
295
	
296
	private void addPopupComponents(){
297
		Iterator it = this.customActions.iterator();
298
		while(it.hasNext()){
299
			Object obj = it.next();
300
			if(obj!=null){
301
				Action act = (Action) obj;
302
				if(contents instanceof SupportPopupMenu) {
303
					DynFormFieldAction sact = new DynFormFieldAction(this, act);
304
					((SupportPopupMenu) this.contents).addActionToPopupMenu(
305
						sact.getName(), 
306
						sact);
307
				}
308
			}else{
309
				if(contents instanceof SupportPopupMenu) {
310
					((SupportPopupMenu) this.contents).addSeparatorToPopupMenu();
311
				}	
312
			}
313
			
314
		}
315
	}
272
    public class IllegalFieldValue extends RuntimeException {
316 273

  
317
	public void addActionToPopupMenu(String name, Action action) {
318
		if(contents != null){
319
			if(contents instanceof SupportPopupMenu ) {
320
				DynFormFieldAction sact = new DynFormFieldAction(this,action);
321
				((SupportPopupMenu) this.contents).addActionToPopupMenu(
322
						sact.getName(), 
323
						sact);
324
			}
325
		}else{
326
			this.customActions.add(action);
327
		}
328
	}
274
        /**
275
         *
276
         */
277
        private static final long serialVersionUID = -4409236610055983438L;
329 278

  
330
	public void addSeparatorToPopupMenu() {
331
		if(contents != null){
332
			if( contents instanceof SupportPopupMenu ) {
333
				((SupportPopupMenu) this.contents).addSeparatorToPopupMenu();
334
			}
335
		}else{
336
			this.customActions.add(null);
337
		}
338
	}
339
	
340
	public void setTranslateEmptyToNull(boolean emptyToNull) {
341
	  this.emptyToNull = emptyToNull;
342
	}
343
	
344
	public boolean translateEmptyToNull() {
345
	  return this.emptyToNull;
346
	}
279
        public IllegalFieldValue(JDynFormField field, String message) {
280
            super("The value of field '" + field.getLabel() + "' is not valid. " + message);
281
        }
282
    }
347 283

  
284
    public String toString() {
285
        return super.toString() + "{" + this.getName() + "}";
286
    }
287

  
288
    public boolean isModified() {
289
        boolean modified = false;
290
        try {
291
            if (!this.isReadOnly()) {
292
                Object value = this.getValue();
293
                if (value == null) {
294
                    if (value != this.getAssignedValue()) {
295
                        modified = true;
296
                    }
297
                } else {
298
                    if (!value.equals(this.getAssignedValue())) {
299
                        modified = true;
300
                    }
301
                }
302
            }
303
        } catch (IllegalFieldValue ex) {
304
            // Si es incorrecto el valor del campo decimos a capom que esta modificado.
305
            modified = true;
306
        }
307
        return modified;
308
    }
309

  
310
    private void addPopupComponents() {
311
        Iterator it = this.customActions.iterator();
312
        while (it.hasNext()) {
313
            Object obj = it.next();
314
            if (obj != null) {
315
                Action act = (Action) obj;
316
                if (contents instanceof SupportPopupMenu) {
317
                    DynFormFieldAction sact = new DynFormFieldAction(this, act);
318
                    ((SupportPopupMenu) this.contents).addActionToPopupMenu(
319
                            sact.getName(),
320
                            sact);
321
                }
322
            } else {
323
                if (contents instanceof SupportPopupMenu) {
324
                    ((SupportPopupMenu) this.contents).addSeparatorToPopupMenu();
325
                }
326
            }
327

  
328
        }
329
    }
330

  
331
    public void addActionToPopupMenu(String name, Action action) {
332
        if (contents != null) {
333
            if (contents instanceof SupportPopupMenu) {
334
                DynFormFieldAction sact = new DynFormFieldAction(this, action);
335
                ((SupportPopupMenu) this.contents).addActionToPopupMenu(
336
                        sact.getName(),
337
                        sact);
338
            }
339
        } else {
340
            this.customActions.add(action);
341
        }
342
    }
343

  
344
    public void addSeparatorToPopupMenu() {
345
        if (contents != null) {
346
            if (contents instanceof SupportPopupMenu) {
347
                ((SupportPopupMenu) this.contents).addSeparatorToPopupMenu();
348
            }
349
        } else {
350
            this.customActions.add(null);
351
        }
352
    }
353

  
354
    public void setTranslateEmptyToNull(boolean emptyToNull) {
355
        this.emptyToNull = emptyToNull;
356
    }
357

  
358
    public boolean translateEmptyToNull() {
359
        return this.emptyToNull;
360
    }
361

  
362
    @SuppressWarnings("UnnecessaryReturnStatement")
348 363
    public void clear() {
349
        if( this.contents == null ) {
364
        if (this.contents == null) {
350 365
            return;
351 366
        }
352
        if( this.contents instanceof JTextField ) {
367
        if (this.contents instanceof JTextField) {
353 368
            Object value = this.getDefinition().getDefaultValue();
354
            if( value != null ) {
369
            if (value != null) {
355 370
                value = value.toString();
356 371
            } else {
357 372
                value = "";
358 373
            }
359
            ((JTextField)this.contents).setText((String)value);
374
            ((JTextField) this.contents).setText((String) value);
360 375
            return;
361 376
        }
362
        if( this.contents instanceof JSpinner ) {
377
        if (this.contents instanceof JSpinner) {
363 378
            Object value = this.getDefinition().getDefaultValue();
364
            if( value != null ) {
379
            if (value != null) {
365 380
                value = value.toString();
366 381
            }
367
            ((JSpinner)this.contents).setValue(value);
382
            ((JSpinner) this.contents).setValue(value);
368 383
            return;
369 384
        }
370
        if( this.contents instanceof JList ) {
371
            ((JList)this.contents).setSelectedIndex(-1);
385
        if (this.contents instanceof JList) {
386
            ((JList) this.contents).setSelectedIndex(-1);
372 387
            return;
373 388
        }
374
        if( this.contents instanceof JComboBox ) {
375
            ((JComboBox)this.contents).setSelectedIndex(-1);
389
        if (this.contents instanceof JComboBox) {
390
            ((JComboBox) this.contents).setSelectedIndex(-1);
376 391
            return;
377 392
        }
378 393
    }
......
380 395
    public void setForm(JDynForm form) {
381 396
        this.form = form;
382 397
    }
383
    
398

  
399
    @Override
384 400
    public JDynForm getForm() {
385 401
        return this.form;
386 402
    }
387 403

  
404
    @Override
405
    public void fetch(DynObject container) {
406
        Object value = this.getValue();
407
        container.setDynValue(this.getName(), value);
408
    }
409

  
388 410
    protected int getTagValueAsInt(String tagname, int defaultVaue) {
389 411
        return getTagValueAsInt(tagname, null, defaultVaue);
390 412
    }
391 413

  
392 414
    protected int getTagValueAsInt(String tagname1, String tagname2, int defaultVaue) {
393
        DynField_v2 fielddef = (DynField_v2)this.getDefinition();                
415
        DynField_v2 fielddef = (DynField_v2) this.getDefinition();
394 416
        String tagname = null;
395
        if( fielddef.getTags().has(tagname1) ) {
417
        if (fielddef.getTags().has(tagname1)) {
396 418
            tagname = tagname1;
397
        } else if( fielddef.getTags().has(tagname2) ) {
419
        } else if (fielddef.getTags().has(tagname2)) {
398 420
            tagname = tagname2;
399 421
        } else {
400 422
            return defaultVaue;
......
403 425
            int value = fielddef.getTags().getInt(tagname);
404 426
            return value;
405 427
        } catch (CoercionException ex) {
406
            logger.warn("Can't parse tag '"+tagname+"' as int for field '"+fielddef.getName()+"'.",ex);
428
            logger.warn("Can't parse tag '" + tagname + "' as int for field '" + fielddef.getName() + "'.", ex);
407 429
        }
408 430
        return defaultVaue;
409 431
    }
410
    
432

  
411 433
    protected boolean getTagValueAsBoolean(String tagname, boolean defaultVaue) {
412 434
        return getTagValueAsBoolean(tagname, null, defaultVaue);
413 435
    }
414
    
436

  
415 437
    protected boolean getTagValueAsBoolean(String tagname1, String tagname2, boolean defaultVaue) {
416
        DynField_v2 fielddef = (DynField_v2)this.getDefinition();                
438
        DynField_v2 fielddef = (DynField_v2) this.getDefinition();
417 439
        String tagname = null;
418
        if( fielddef.getTags().has(tagname1) ) {
440
        if (fielddef.getTags().has(tagname1)) {
419 441
            tagname = tagname1;
420
        } else if( fielddef.getTags().has(tagname2) ) {
442
        } else if (fielddef.getTags().has(tagname2)) {
421 443
            tagname = tagname2;
422 444
        } else {
423 445
            return defaultVaue;
......
426 448
            boolean value = fielddef.getTags().getBoolean(tagname);
427 449
            return value;
428 450
        } catch (CoercionException ex) {
429
            logger.warn("Can't parse tag '"+tagname+"' as boolean for field '"+fielddef.getName()+"'.",ex);
451
            logger.warn("Can't parse tag '" + tagname + "' as boolean for field '" + fielddef.getName() + "'.", ex);
430 452
        }
431 453
        return defaultVaue;
432 454
    }
433
    
455

  
434 456
    protected String getTagValueAsString(String tagname, String defaultVaue) {
435 457
        return getTagValueAsString(tagname, null, defaultVaue);
436 458
    }
437
    
459

  
438 460
    protected String getTagValueAsString(String tagname1, String tagname2, String defaultVaue) {
439
        DynField_v2 fielddef = (DynField_v2)this.getDefinition();                
461
        DynField_v2 fielddef = (DynField_v2) this.getDefinition();
440 462
        String tagname = null;
441
        if( fielddef.getTags().has(tagname1) ) {
463
        if (fielddef.getTags().has(tagname1)) {
442 464
            tagname = tagname1;
443
        } else if( fielddef.getTags().has(tagname2) ) {
465
        } else if (fielddef.getTags().has(tagname2)) {
444 466
            tagname = tagname2;
445 467
        } else {
446 468
            return defaultVaue;
447 469
        }
448 470
        try {
449
            String value = (String) fielddef.getTags().get(tagname,DataTypes.STRING);
471
            String value = (String) fielddef.getTags().get(tagname, DataTypes.STRING);
450 472
            return value;
451 473
        } catch (CoercionException ex) {
452
            logger.warn("Can't parse tag '"+tagname+"' as string for field '"+fielddef.getName()+"'.",ex);
474
            logger.warn("Can't parse tag '" + tagname + "' as string for field '" + fielddef.getName() + "'.", ex);
453 475
        }
454 476
        return defaultVaue;
455 477
    }
456
    
478

  
457 479
}

Also available in: Unified diff