KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > controlx > impl > AbstractControl


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.controlx.impl;
14
15 import info.magnolia.cms.gui.controlx.Control;
16 import info.magnolia.cms.gui.controlx.RenderKit;
17 import info.magnolia.cms.gui.controlx.Renderer;
18
19 import java.util.Collection JavaDoc;
20
21 import org.apache.commons.collections.OrderedMap;
22 import org.apache.commons.collections.map.ListOrderedMap;
23 import org.apache.commons.lang.StringUtils;
24
25
26 /**
27  * Default Implementation. Gets the nearest RenderKit in the controls tree.
28  * @author Philipp Bracher
29  * @version $Revision: 6341 $ ($Author: philipp $)
30  */

31 public class AbstractControl implements Control {
32
33     /**
34      * Name of the control
35      */

36     private String JavaDoc name;
37
38     /**
39      * The renderer kit used. layzy bound.
40      */

41     private RenderKit renderKit;
42
43     /**
44      * The name of the renderer to use.
45      */

46     private String JavaDoc renderType;
47
48     /**
49      * The renderer used. If not set the renderType is used to get the renderer from the RenderKit
50      */

51     private Renderer renderer;
52
53     /**
54      * Parent control
55      */

56     private Control parent;
57
58     /**
59      * The ordered children
60      */

61     private OrderedMap children = new ListOrderedMap();
62
63     /**
64      * @return Returns the parent.
65      */

66     public Control getParent() {
67         return parent;
68     }
69
70     /**
71      * @param parent The parent to set.
72      */

73     public void setParent(Control parent) {
74         this.parent = parent;
75     }
76
77     /**
78      * If no name set yet just set one.
79      */

80     public void addChild(Control control) {
81         control.setParent(this);
82         if (StringUtils.isEmpty(control.getName())) {
83             control.setName(this.getName() + "_" + this.children.size());
84         }
85         this.children.put(control.getName(), control);
86     }
87
88     public Control getChild(String JavaDoc name) {
89         return (Control) this.children.get(name);
90     }
91
92     public Collection JavaDoc getChildren() {
93         return this.children.values();
94     }
95
96     /**
97      * @return Returns the name.
98      */

99     public String JavaDoc getName() {
100         return name;
101     }
102
103     /**
104      * @param name The name to set.
105      */

106     public void setName(String JavaDoc name) {
107         this.name = name;
108     }
109
110     /**
111      * @return Returns the renderKit.
112      */

113     public RenderKit getRenderKit() {
114         if (this.renderKit == null) {
115             if (this.getParent() != null) {
116                 this.renderKit = this.getParent().getRenderKit();
117             }
118         }
119         return renderKit;
120     }
121
122     /**
123      * @param renderKit The renderKit to set.
124      */

125     public void setRenderKit(RenderKit renderKit) {
126         this.renderKit = renderKit;
127     }
128
129     /**
130      * Get the Renderer assigned to this renderer type and call its renderer() method.
131      */

132     public String JavaDoc render() {
133         return this.getRenderer().render(this);
134     }
135
136     /**
137      * @return Returns the renderType.
138      */

139     public String JavaDoc getRenderType() {
140         return renderType;
141     }
142
143     /**
144      * @param renderType The renderType to set.
145      */

146     public void setRenderType(String JavaDoc renderType) {
147         this.renderType = renderType;
148     }
149
150     /**
151      * @return Returns the renderer.
152      */

153     public Renderer getRenderer() {
154         if (this.renderer == null) {
155             this.renderer = this.getRenderKit().getRenderer(this.getRenderType());
156         }
157
158         return this.renderer;
159     }
160
161     /**
162      * @param renderer The renderer to set.
163      */

164     public void setRenderer(Renderer renderer) {
165         this.renderer = renderer;
166     }
167
168 }
169
Popular Tags