KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > BooleanFieldDefinition


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
23  * The {@link WidgetDefinition} part of a BooleanField widget, see {@link BooleanField} for more information.
24  *
25  * @version $Id: BooleanFieldDefinition.java 326930 2005-10-20 16:03:19Z sylvain $
26  */

27 public class BooleanFieldDefinition extends AbstractWidgetDefinition {
28     private ValueChangedListener listener;
29     
30     private Boolean JavaDoc initialValue;
31     
32     private String JavaDoc trueParamValue = "true";
33
34     public Widget createInstance() {
35         return new BooleanField(this);
36     }
37     
38     /**
39      * initialize this definition with the other, sort of like a copy constructor
40      */

41     public void initializeFrom(WidgetDefinition definition) throws Exception JavaDoc {
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 JavaDoc("Definition to inherit from is not of the right type! (at "+getLocation()+")");
53         }
54     }
55     
56     public void setInitialValue(Boolean JavaDoc value) {
57         checkMutable();
58         this.initialValue = value;
59     }
60     
61     public Boolean JavaDoc getInitialValue() {
62         return this.initialValue;
63     }
64     
65     public void setTrueParamValue(String JavaDoc value) {
66         checkMutable();
67         this.trueParamValue = value;
68     }
69     
70     /**
71      * Get the parameter value that indicates a true value. Default
72      * is "<code>true</code>".
73      */

74     public String JavaDoc 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 JavaDoc("The property 'required' is not available on widgets of type booleanfield.");
100     }
101 }
102
Popular Tags