1 16 package org.apache.cocoon.forms.formmodel; 17 18 import org.apache.cocoon.forms.event.ValueChangedEvent; 19 import org.apache.cocoon.forms.event.ValueChangedListener; 20 import org.apache.cocoon.forms.event.WidgetEventMulticaster; 21 22 27 public class BooleanFieldDefinition extends AbstractWidgetDefinition { 28 private ValueChangedListener listener; 29 30 private Boolean initialValue; 31 32 private String trueParamValue = "true"; 33 34 public Widget createInstance() { 35 return new BooleanField(this); 36 } 37 38 41 public void initializeFrom(WidgetDefinition definition) throws Exception { 42 super.initializeFrom(definition); 43 44 if(definition instanceof BooleanFieldDefinition) { 45 BooleanFieldDefinition other = (BooleanFieldDefinition)definition; 46 47 this.listener = other.listener; 48 this.initialValue = other.initialValue; 49 this.trueParamValue = other.trueParamValue; 50 51 } else { 52 throw new Exception ("Definition to inherit from is not of the right type! (at "+getLocation()+")"); 53 } 54 } 55 56 public void setInitialValue(Boolean value) { 57 checkMutable(); 58 this.initialValue = value; 59 } 60 61 public Boolean getInitialValue() { 62 return this.initialValue; 63 } 64 65 public void setTrueParamValue(String value) { 66 checkMutable(); 67 this.trueParamValue = value; 68 } 69 70 74 public String getTrueParamValue() { 75 return this.trueParamValue; 76 } 77 78 public void addValueChangedListener(ValueChangedListener listener) { 79 checkMutable(); 80 this.listener = WidgetEventMulticaster.add(this.listener, listener); 81 } 82 83 public ValueChangedListener getValueChangedListener() { 84 return this.listener; 85 } 86 87 public void fireValueChangedEvent(ValueChangedEvent event) { 88 if (this.listener != null) { 89 this.listener.valueChanged(event); 90 } 91 } 92 93 public boolean hasValueChangedListeners() { 94 return listener != null; 95 } 96 97 public void setRequired(boolean required) { 98 checkMutable(); 99 throw new UnsupportedOperationException ("The property 'required' is not available on widgets of type booleanfield."); 100 } 101 } 102 | Popular Tags |