01: /* ***** BEGIN LICENSE BLOCK *****
02: * Version: MPL 1.1
03: * The contents of this file are subject to the Mozilla Public License Version
04: * 1.1 (the "License"); you may not use this file except in compliance with
05: * the License. You may obtain a copy of the License at
06: * http://www.mozilla.org/MPL/
07: *
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * 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;
27: import java.util.List;
28:
29: import org.riotfamily.common.markup.Html;
30: import org.riotfamily.common.markup.TagWriter;
31:
32: /**
33: * Composite element that notifys the form whenever an element is added or
34: * removed. This way elements can benefit from the framework's AJAX support
35: * without needing to know anything about.
36: * Refer to the {@link org.riotfamily.forms.element.collection.ListEditor} implementation
37: * for an example.
38: */
39: public class Container extends CompositeElement implements
40: ContainerElement {
41:
42: /**
43: * Creates an empty container.
44: */
45: public Container() {
46: }
47:
48: public List 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 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: }
|