KickJava   Java API By Example, From Geeks To Geeks.

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


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.datatype.SelectionList;
19
20 /**
21  * The {@link WidgetDefinition} part of a Field widget, see {@link Field} for more information.
22  *
23  * @version $Id: FieldDefinition.java 292158 2005-09-28 10:24:51Z sylvain $
24  */

25 public class FieldDefinition extends AbstractDatatypeWidgetDefinition {
26     private boolean required;
27     private SelectionList suggestionList;
28
29     public Widget createInstance() {
30         Field field = new Field(this);
31         return field;
32     }
33     
34     /**
35      * initialize this definition with the other, sort of like a copy constructor
36      */

37     public void initializeFrom(WidgetDefinition definition) throws Exception JavaDoc {
38         if(!(definition instanceof FieldDefinition)) {
39             throw new Exception JavaDoc("Definition to inherit from is not of the right type! (at "+getLocation()+")");
40         }
41         super.initializeFrom(definition);
42         
43         FieldDefinition other = (FieldDefinition)definition;
44         
45         this.required = other.required;
46         
47         if (suggestionList == null) {
48             suggestionList = other.getSuggestionList();
49         }
50     }
51
52     public boolean isRequired() {
53         return required;
54     }
55
56     public void setRequired(boolean required) {
57         checkMutable();
58         this.required = required;
59     }
60
61     public SelectionList getSuggestionList() {
62         return this.suggestionList;
63     }
64
65     public void setSuggestionList(SelectionList list) {
66         this.suggestionList = list;
67     }
68 }
69
Popular Tags