| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
package net.sf.beanform; |
| 16 |
|
|
| 17 |
|
import java.util.Iterator; |
| 18 |
|
import java.util.Map; |
| 19 |
|
|
| 20 |
|
import net.sf.beanform.prop.BeanProperty; |
| 21 |
|
|
| 22 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
| 23 |
|
import org.apache.tapestry.IComponent; |
| 24 |
|
import org.apache.tapestry.form.IFormComponent; |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
11 |
public abstract class BeanFormLabel extends BeanFormRowComponent { |
| 33 |
|
|
| 34 |
|
final static String PROPERTYSELECTION_BLOCK_ID = "propertySelectionBlock"; |
| 35 |
|
final static String CUSTOM_BLOCK_ID = "customBlock"; |
| 36 |
|
final static String TEXTFIELD_BLOCK_ID = "textFieldBlock"; |
| 37 |
|
final static String TEXTAREA_BLOCK_ID = "textAreaBlock"; |
| 38 |
|
final static String CHECKBOX_BLOCK_ID = "checkboxBlock"; |
| 39 |
|
final static String DATEPICKER_BLOCK_ID = "datePickerBlock"; |
| 40 |
|
final static String UPLOAD_BLOCK_ID = "uploadBlock"; |
| 41 |
|
final static String INSERT_BLOCK_ID = "insertBlock"; |
| 42 |
|
|
| 43 |
|
public IComponent getLabelBlock() { |
| 44 |
5 |
BeanProperty property = this.getProperty(); |
| 45 |
5 |
if( this.hasPropertySelectionModel( property, true ) ) return this.getComponent( PROPERTYSELECTION_BLOCK_ID ); |
| 46 |
5 |
else if( this.hasCustomField( property ) ) return this.getComponent( CUSTOM_BLOCK_ID ); |
| 47 |
5 |
else if( property.usesTextField() ) return this.getComponent( TEXTFIELD_BLOCK_ID ); |
| 48 |
4 |
else if( property.usesTextArea() ) return this.getComponent( TEXTAREA_BLOCK_ID ); |
| 49 |
3 |
else if( property.usesCheckbox() ) return this.getComponent( CHECKBOX_BLOCK_ID ); |
| 50 |
2 |
else if( property.usesDatePicker() ) return this.getComponent( DATEPICKER_BLOCK_ID ); |
| 51 |
1 |
else if( property.usesUpload() ) return this.getComponent( UPLOAD_BLOCK_ID ); |
| 52 |
1 |
else if( property.usesInsert() ) return this.getComponent( INSERT_BLOCK_ID ); |
| 53 |
|
else { |
| 54 |
0 |
String msg = BeanFormMessages.cantFindFieldForProperty( property ); |
| 55 |
0 |
throw new ApplicationRuntimeException( msg ); |
| 56 |
|
} |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
public IFormComponent getPropertySelection() { |
| 60 |
1 |
return this.getField( BeanFormField.PROPERTYSELECTION_FIELD_ID ); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
public IFormComponent getTextField() { |
| 64 |
1 |
return this.getField( BeanFormField.TEXTFIELD_FIELD_ID ); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
public IFormComponent getTextArea() { |
| 68 |
1 |
return this.getField( BeanFormField.TEXTAREA_FIELD_ID ); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
public IFormComponent getCheckbox() { |
| 72 |
1 |
return this.getField( BeanFormField.CHECKBOX_FIELD_ID ); |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
public IFormComponent getDatePicker() { |
| 76 |
1 |
return this.getField( BeanFormField.DATEPICKER_FIELD_ID ); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
public IFormComponent getUpload() { |
| 80 |
1 |
return this.getField( BeanFormField.UPLOAD_FIELD_ID ); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
private IFormComponent getField( String id ) { |
| 89 |
6 |
IFormComponent field = null; |
| 90 |
6 |
Map siblings = this.getContainer().getComponents(); |
| 91 |
6 |
for( Iterator i = siblings.values().iterator(); i.hasNext(); ) { |
| 92 |
12 |
IComponent sibling = (IComponent) i.next(); |
| 93 |
12 |
if( sibling instanceof BeanFormField ) { |
| 94 |
6 |
field = (IFormComponent) sibling.getComponent( id ); |
| 95 |
6 |
this.addExtraBindings( field ); |
| 96 |
6 |
break; |
| 97 |
|
} |
| 98 |
6 |
} |
| 99 |
6 |
return field; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
} |