001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.formmodel;
018:
019: import org.apache.cocoon.forms.FormsException;
020: import org.apache.cocoon.forms.event.ValueChangedEvent;
021: import org.apache.cocoon.forms.event.ValueChangedListener;
022: import org.apache.cocoon.forms.event.WidgetEventMulticaster;
023:
024: /**
025: * The {@link WidgetDefinition} part of a BooleanField widget, see {@link BooleanField} for more information.
026: *
027: * @version $Id: BooleanFieldDefinition.java 449149 2006-09-23 03:58:05Z crossley $
028: */
029: public class BooleanFieldDefinition extends AbstractWidgetDefinition {
030:
031: private ValueChangedListener listener;
032: private Boolean initialValue;
033: private String trueParamValue = "true";
034:
035: public Widget createInstance() {
036: return new BooleanField(this );
037: }
038:
039: /**
040: * initialize this definition with the other, sort of like a copy constructor
041: */
042: public void initializeFrom(WidgetDefinition definition)
043: throws Exception {
044: super .initializeFrom(definition);
045:
046: if (!(definition instanceof BooleanFieldDefinition)) {
047: throw new FormsException("Ancestor definition "
048: + definition.getClass().getName()
049: + " is not a BooleanFieldDefinition.",
050: getLocation());
051: }
052:
053: BooleanFieldDefinition other = (BooleanFieldDefinition) definition;
054:
055: this .listener = other.listener;
056: this .initialValue = other.initialValue;
057: this .trueParamValue = other.trueParamValue;
058: }
059:
060: public void setInitialValue(Boolean value) {
061: checkMutable();
062: this .initialValue = value;
063: }
064:
065: public Boolean getInitialValue() {
066: return this .initialValue;
067: }
068:
069: public void setTrueParamValue(String value) {
070: checkMutable();
071: this .trueParamValue = value;
072: }
073:
074: /**
075: * Get the parameter value that indicates a true value. Default
076: * is "<code>true</code>".
077: */
078: public String getTrueParamValue() {
079: return this .trueParamValue;
080: }
081:
082: public void addValueChangedListener(ValueChangedListener listener) {
083: checkMutable();
084: this .listener = WidgetEventMulticaster.add(this .listener,
085: listener);
086: }
087:
088: public ValueChangedListener getValueChangedListener() {
089: return this .listener;
090: }
091:
092: public void fireValueChangedEvent(ValueChangedEvent event) {
093: if (this .listener != null) {
094: this .listener.valueChanged(event);
095: }
096: }
097:
098: public boolean hasValueChangedListeners() {
099: return listener != null;
100: }
101:
102: public void setRequired(boolean required) {
103: checkMutable();
104: throw new UnsupportedOperationException(
105: "The property 'required' is not available on widgets of type booleanfield.");
106: }
107: }
|