KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > forms > Container


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.forms;
25
26 import java.io.PrintWriter JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.riotfamily.common.markup.Html;
30 import org.riotfamily.common.markup.TagWriter;
31
32
33 /**
34  * Composite element that notifys the form whenever an element is added or
35  * removed. This way elements can benefit from the framework's AJAX support
36  * without needing to know anything about.
37  * Refer to the {@link org.riotfamily.forms.element.collection.ListEditor} implementation
38  * for an example.
39  */

40 public class Container extends CompositeElement implements ContainerElement {
41
42     /**
43      * Creates an empty container.
44      */

45     public Container() {
46     }
47
48     public List JavaDoc getElements() {
49         return getComponents();
50     }
51
52     public void addElement(Element element) {
53         addComponent(element);
54         if (getFormListener() != null) {
55             getFormListener().elementAdded(element);
56         }
57     }
58
59     /**
60      * Removes the given element from the container.
61      */

62     public void removeElement(Element element) {
63         removeComponent(element);
64         getForm().unregisterElement(element);
65         if (getFormListener() != null) {
66             getFormListener().elementRemoved(element);
67         }
68     }
69
70     /**
71      * Renders the container's components surrounded by a <tt>span</tt> tag
72      * with the id of the container.
73      */

74     public void renderInternal(PrintWriter JavaDoc writer) {
75         TagWriter div = new TagWriter(writer);
76         div.start(Html.DIV).attribute(Html.COMMON_ID, getId()).body();
77         renderComponents(writer);
78         div.end();
79     }
80     
81 }
Popular Tags