1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.component;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.myfaces.tobago.component.Attributes;
25 import org.apache.myfaces.tobago.internal.util.Deprecation;
26 import org.apache.myfaces.tobago.layout.LayoutComponent;
27 import org.apache.myfaces.tobago.model.ExpandedState;
28 import org.apache.myfaces.tobago.model.MarkedState;
29 import org.apache.myfaces.tobago.model.MixedTreeModel;
30 import org.apache.myfaces.tobago.model.TreeState;
31
32 import javax.el.ELContext;
33 import javax.el.ValueExpression;
34 import javax.faces.component.NamingContainer;
35 import javax.faces.component.UIComponent;
36 import javax.faces.context.FacesContext;
37
38 public abstract class AbstractUITree extends AbstractUIData
39
40 implements NamingContainer, LayoutComponent {
41
42 private static final Log LOG = LogFactory.getLog(AbstractUITree.class);
43
44 public static final String MESSAGE_NOT_LEAF = "tobago.tree.MESSAGE_NOT_LEAF";
45
46
47
48
49 @Deprecated
50 public static final String SEP = "-";
51
52
53
54
55 @Deprecated
56 public static final String SELECT_STATE = SEP + "selectState";
57
58
59
60
61 @Deprecated
62 public static final String MARKED = "marked";
63
64 private TreeState state;
65
66 @Override
67 public void processValidators(FacesContext facesContext) {
68 final int last = hasRows() ? getFirst() + getRows() : Integer.MAX_VALUE;
69 for (int rowIndex = getFirst(); rowIndex < last; rowIndex++) {
70 setRowIndex(rowIndex);
71 if (!isRowAvailable()) {
72 break;
73 }
74 for (UIComponent child : getChildren()) {
75 child.processValidators(facesContext);
76 }
77 }
78 setRowIndex(-1);
79 }
80
81 @Override
82 public void processUpdates(FacesContext facesContext) {
83 final int last = hasRows() ? getFirst() + getRows() : Integer.MAX_VALUE;
84 for (int rowIndex = getFirst(); rowIndex < last; rowIndex++) {
85 setRowIndex(rowIndex);
86 if (!isRowAvailable()) {
87 break;
88 }
89 for (UIComponent child : getChildren()) {
90 child.processUpdates(facesContext);
91 }
92 }
93 setRowIndex(-1);
94 }
95
96
97
98
99 @Deprecated
100 public UIComponent getRoot() {
101
102 for (UIComponent child : getChildren()) {
103 if (child instanceof AbstractUITreeNode) {
104 return child;
105 }
106 if (child instanceof AbstractUITreeData) {
107 return child;
108 }
109 }
110 return null;
111 }
112
113
114
115
116 @Deprecated
117 public MixedTreeModel getModel() {
118 Deprecation.LOG.error("Doesn't work anymore.");
119 return null;
120 }
121
122 @Override
123 public boolean getRendersChildren() {
124 return true;
125 }
126
127 @Override
128 public void processDecodes(FacesContext facesContext) {
129
130 if (!isRendered()) {
131 return;
132 }
133
134 final int last = hasRows() ? getFirst() + getRows() : Integer.MAX_VALUE;
135 for (int rowIndex = getFirst(); rowIndex < last; rowIndex++) {
136 setRowIndex(rowIndex);
137 if (!isRowAvailable()) {
138 break;
139 }
140 for (UIComponent child : getChildren()) {
141 child.processDecodes(facesContext);
142 }
143 }
144 setRowIndex(-1);
145
146 decode(facesContext);
147 }
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 public void setState(TreeState state) {
205 this.state = state;
206 }
207
208 public TreeState getState() {
209 if (state != null) {
210 return state;
211 }
212
213 final ELContext elContext = FacesContext.getCurrentInstance().getELContext();
214 final ValueExpression expression = getValueExpression(Attributes.STATE);
215
216 if (expression != null) {
217 TreeState state = (TreeState) expression.getValue(elContext);
218 if (state == null) {
219 state = new TreeState(new ExpandedState(2), new MarkedState());
220 expression.setValue(elContext, state);
221 }
222 return state;
223 }
224
225 state = new TreeState(new ExpandedState(2), new MarkedState());
226 return state;
227 }
228
229 public MarkedState getMarkedState() {
230 return getState().getMarkedState();
231 }
232
233 @Override
234 public ExpandedState getExpandedState() {
235 return getState().getExpandedState();
236 }
237
238 public void restoreState(FacesContext context, Object componentState) {
239 Object[] values = (Object[]) componentState;
240 super.restoreState(context, values[0]);
241 state = (TreeState) values[1];
242 }
243
244 public Object saveState(FacesContext context) {
245 Object[] values = new Object[2];
246 values[0] = super.saveState(context);
247 values[1] = state;
248 return values;
249 }
250 }