1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Defines a simple implementation of IComponent interface for creation
17 of new UI components by composition of existing components."""
18
19 from warnings import warn
20
21 from muntjac.util import fullname
22
23 from muntjac.ui.abstract_component_container import AbstractComponentContainer
24
25
27 """Custom component provides simple implementation of Component interface
28 for creation of new UI components by composition of existing components.
29
30 The component is used by inheriting the CustomComponent class and setting
31 composite root inside the Custom component. The composite root itself can
32 contain more components, but their interfaces are hidden from the users.
33
34 @author: Vaadin Ltd.
35 @author: Richard Lincoln
36 @version: 1.1.2
37 """
38
39 CLIENT_WIDGET = None
40
41 - def __init__(self, compositionRoot=None):
42 """Constructs a new custom component.
43
44 The component is implemented by wrapping the methods of the
45 composition root component given as parameter. The composition root
46 must not be null and can not be changed after the composition.
47
48 @param compositionRoot:
49 the root of the composition component tree.
50 """
51
52
53 self._root = None
54
55
56 self._componentType = None
57
58 super(CustomComponent, self).__init__()
59
60
61 self.setWidth(100, self.UNITS_PERCENTAGE)
62
63 if compositionRoot is not None:
64 self.setCompositionRoot(compositionRoot)
65
66
68 """Returns the composition root.
69
70 @return: the Component Composition root.
71 """
72 return self._root
73
74
76 """Sets the compositions root.
77
78 The composition root must be set to non-null value before the
79 component can be used. The composition root can only be set once.
80
81 @param compositionRoot:
82 the root of the composition component tree.
83 """
84 if compositionRoot != self._root:
85 if self._root is not None:
86
87 super(CustomComponent, self).removeComponent(self._root)
88
89 if compositionRoot is not None:
90
91 super(CustomComponent, self).addComponent(compositionRoot)
92
93 self._root = compositionRoot
94 self.requestRepaint()
95
96
97 - def paintContent(self, target):
98 if self._root is None:
99 raise ValueError, ('Composition root must be set to'
100 + ' non-null value before the ' + fullname(self)
101 + ' can be painted')
102
103 if self.getComponentType() is not None:
104 target.addAttribute('type', self.getComponentType())
105
106 self._root.paint(target)
107
108
110 """Gets the component type.
111
112 The component type is textual type of the component. This is included
113 in the UIDL as component tag attribute.
114
115 @deprecated: not more useful as the whole tag system has been removed
116
117 @return: the component type.
118 """
119 warn('tag system has been removed', DeprecationWarning)
120 return self._componentType
121
122
124 """Sets the component type.
125
126 The component type is textual type of the component. This is included
127 in the UIDL as component tag attribute.
128
129 @deprecated: not more useful as the whole tag system has been removed
130
131 @param componentType:
132 the componentType to set.
133 """
134 warn('tag system has been removed', DeprecationWarning)
135 self._componentType = componentType
136
137
140
141
143 """Gets the number of contained components. Consistent with the
144 iterator returned by L{getComponentIterator}.
145
146 @return: the number of contained components (zero or one)
147 """
148 return 1 if self._root is not None else 0
149
150
152 """This method is not supported by CustomComponent.
153
154 @see: L{ComponentContainer.replaceComponent()}
155 """
156 raise NotImplementedError
157
158
160 """This method is not supported by CustomComponent. Use
161 L{CustomComponent.setCompositionRoot} to set CustomComponents "child".
162
163 @see: L{AbstractComponentContainer.addComponent}
164 """
165 raise NotImplementedError
166
167
169 """This method is not supported by CustomComponent.
170
171 @see: L{AbstractComponentContainer.moveComponentsFrom}
172 """
173 raise NotImplementedError
174
175
177 """This method is not supported by CustomComponent.
178
179 @see: L{AbstractComponentContainer.removeAllComponents}
180 """
181 raise NotImplementedError
182
183
185 """This method is not supported by CustomComponent.
186
187 @see: L{AbstractComponentContainer.removeComponent}
188 """
189 raise NotImplementedError
190
191
193
197
198
201
202
205
206
208 if not self._first:
209 raise StopIteration
210 self._first = False
211 return self._component._root
212
213
215 raise NotImplementedError
216