KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > tabbedpane > HtmlPanelTabbedPane


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.custom.tabbedpane;
17
18 import org.apache.myfaces.renderkit.RendererUtils;
19
20 import javax.faces.component.html.HtmlPanelGroup;
21 import javax.faces.component.UIComponent;
22 import javax.faces.component.NamingContainer;
23 import javax.faces.component.UINamingContainer;
24 import javax.faces.component.UIForm;
25 import javax.faces.context.FacesContext;
26 import javax.faces.el.EvaluationException;
27 import javax.faces.el.MethodBinding;
28 import javax.faces.el.ValueBinding;
29 import javax.faces.event.AbortProcessingException;
30 import javax.faces.event.FacesEvent;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * @author Manfred Geiler (latest modification by $Author: mmarinschek $)
36  * @version $Revision: 1.10 $ $Date: 2005/02/11 16:03:00 $
37  * $Log: HtmlPanelTabbedPane.java,v $
38  * Revision 1.10 2005/02/11 16:03:00 mmarinschek
39  * solve bug in tabbed panel when datatable was displayed not on tab, but at the bottom of the datatable...
40  *
41  * Revision 1.9 2005/01/24 12:20:11 mmarinschek
42  * Changed the TabbedPane component to only decode components which are on the visible tags - other components are not processed in the decode phase. Changed the HtmlRendererUtils back to submit empty strings for components which should be posted back but have null values.
43  *
44  * Revision 1.8 2004/11/26 14:29:12 oros
45  * bug fix #1006636: VisibleOnUserRole attribute for x:panelTab tag
46  *
47  * Revision 1.7 2004/10/13 11:50:58 matze
48  * renamed packages to org.apache
49  *
50  * Revision 1.6 2004/08/09 07:28:20 manolito
51  * activeTabStyleClass, inactiveTabStyleClass, activeSubStyleClass, inactiveSubStyleClass, tagContentStyleClass via codegen
52  *
53  * Revision 1.5 2004/07/10 17:11:02 o_rossmueller
54  * added attributes activeTabStyleClass, inactiveTabStyleClass, activeSubStyleClass, inactiveSubStyleClass, tagContentStyleClass to overwrite style attributes using css
55  *
56  * Revision 1.4 2004/07/01 21:53:05 mwessendorf
57  * ASF switch
58  *
59  * Revision 1.3 2004/04/16 15:13:31 manolito
60  * validator attribute support and MethodBinding invoke exception handling fixed
61  *
62  * Revision 1.2 2004/04/06 15:36:31 manolito
63  * go to render phase after tab switching
64  *
65  */

66 public class HtmlPanelTabbedPane
67         extends HtmlPanelGroup
68 {
69     //private static final Log log = LogFactory.getLog(HtmlPanelTabbedPane.class);
70

71     private MethodBinding _tabChangeListener = null;
72
73     //TODO: additional HTML Table attributes (see HtmlPanelTabbedPaneTag)
74

75     public void decode(FacesContext context)
76     {
77         super.decode(context); //To change body of overridden methods use File | Settings | File Templates.
78
}
79
80     public void processDecodes(javax.faces.context.FacesContext context)
81     {
82         if (context == null) throw new NullPointerException JavaDoc("context");
83         decode(context);
84
85         int tabIdx = 0;
86         int selectedIndex = getSelectedIndex();
87
88         Iterator JavaDoc it = getFacetsAndChildren();
89
90         while (it.hasNext())
91         {
92             UIComponent childOrFacet = getUIComponent((UIComponent) it.next());
93             if (childOrFacet instanceof HtmlPanelTab)
94             {
95                 if (tabIdx == selectedIndex)
96                 {
97                     childOrFacet.processDecodes(context);
98                 }
99                 tabIdx++;
100             }
101             else
102             {
103                 childOrFacet.processDecodes(context);
104             }
105         }
106     }
107
108     private UIComponent getUIComponent(UIComponent uiComponent)
109     {
110         if (uiComponent instanceof UINamingContainer || uiComponent instanceof UIForm)
111         {
112             List JavaDoc children = uiComponent.getChildren();
113             for (int i = 0, len = children.size(); i < len; i++)
114             {
115                 uiComponent = getUIComponent((UIComponent)children.get(i));
116             }
117         }
118         return uiComponent;
119     }
120
121     public void addTabChangeListener(TabChangeListener listener)
122     {
123         addFacesListener(listener);
124     }
125
126     public void removeTabChangeListener(TabChangeListener listener)
127     {
128         removeFacesListener(listener);
129     }
130
131     public MethodBinding getTabChangeListener()
132     {
133         return _tabChangeListener;
134     }
135
136     public void setTabChangeListener(MethodBinding tabChangeListener)
137     {
138         _tabChangeListener = tabChangeListener;
139     }
140
141     public void broadcast(FacesEvent event) throws AbortProcessingException
142     {
143         if (event instanceof TabChangeEvent)
144         {
145             TabChangeEvent tabChangeEvent = (TabChangeEvent)event;
146             if (tabChangeEvent.getComponent() == this)
147             {
148                 setSelectedIndex(tabChangeEvent.getNewTabIndex());
149                 getFacesContext().renderResponse();
150             }
151         }
152         super.broadcast(event);
153
154         MethodBinding tabChangeListenerBinding = getTabChangeListener();
155         if (tabChangeListenerBinding != null)
156         {
157             try
158             {
159                 tabChangeListenerBinding.invoke(getFacesContext(), new Object JavaDoc[]{event});
160             }
161             catch (EvaluationException e)
162             {
163                 Throwable JavaDoc cause = e.getCause();
164                 if (cause != null && cause instanceof AbortProcessingException)
165                 {
166                     throw (AbortProcessingException)cause;
167                 }
168                 else
169                 {
170                     throw e;
171                 }
172             }
173         }
174     }
175
176     //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
177

178     public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.HtmlPanelTabbedPane";
179     public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Panel";
180     private static final String JavaDoc DEFAULT_RENDERER_TYPE = "org.apache.myfaces.TabbedPane";
181     private static final int DEFAULT_SELECTEDINDEX = 0;
182
183     private Integer JavaDoc _selectedIndex = null;
184     private String JavaDoc _bgcolor = null;
185     private String JavaDoc _activeTabStyleClass = null;
186     private String JavaDoc _inactiveTabStyleClass = null;
187     private String JavaDoc _disabledTabStyleClass = null;
188     private String JavaDoc _activeSubStyleClass = null;
189     private String JavaDoc _inactiveSubStyleClass = null;
190     private String JavaDoc _tabContentStyleClass = null;
191
192     public HtmlPanelTabbedPane()
193     {
194         setRendererType(DEFAULT_RENDERER_TYPE);
195     }
196
197     public String JavaDoc getFamily()
198     {
199         return COMPONENT_FAMILY;
200     }
201
202     public void setSelectedIndex(int selectedIndex)
203     {
204         _selectedIndex = new Integer JavaDoc(selectedIndex);
205     }
206
207     public int getSelectedIndex()
208     {
209         if (_selectedIndex != null) return _selectedIndex.intValue();
210         ValueBinding vb = getValueBinding("selectedIndex");
211         Integer JavaDoc v = vb != null ? (Integer JavaDoc)vb.getValue(getFacesContext()) : null;
212         return v != null ? v.intValue() : DEFAULT_SELECTEDINDEX;
213     }
214
215     public void setBgcolor(String JavaDoc bgcolor)
216     {
217         _bgcolor = bgcolor;
218     }
219
220     public String JavaDoc getBgcolor()
221     {
222         if (_bgcolor != null) return _bgcolor;
223         ValueBinding vb = getValueBinding("bgcolor");
224         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
225     }
226
227     public void setActiveTabStyleClass(String JavaDoc activeTabStyleClass)
228     {
229         _activeTabStyleClass = activeTabStyleClass;
230     }
231
232     public String JavaDoc getActiveTabStyleClass()
233     {
234         if (_activeTabStyleClass != null) return _activeTabStyleClass;
235         ValueBinding vb = getValueBinding("activeTabStyleClass");
236         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
237     }
238
239     public void setInactiveTabStyleClass(String JavaDoc inactiveTabStyleClass)
240     {
241         _inactiveTabStyleClass = inactiveTabStyleClass;
242     }
243
244     public String JavaDoc getInactiveTabStyleClass()
245     {
246         if (_inactiveTabStyleClass != null) return _inactiveTabStyleClass;
247         ValueBinding vb = getValueBinding("inactiveTabStyleClass");
248         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
249     }
250
251     public void setActiveSubStyleClass(String JavaDoc activeSubStyleClass)
252     {
253         _activeSubStyleClass = activeSubStyleClass;
254     }
255
256     public String JavaDoc getActiveSubStyleClass()
257     {
258         if (_activeSubStyleClass != null) return _activeSubStyleClass;
259         ValueBinding vb = getValueBinding("activeSubStyleClass");
260         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
261     }
262
263     public void setInactiveSubStyleClass(String JavaDoc inactiveSubStyleClass)
264     {
265         _inactiveSubStyleClass = inactiveSubStyleClass;
266     }
267
268     public String JavaDoc getInactiveSubStyleClass()
269     {
270         if (_inactiveSubStyleClass != null) return _inactiveSubStyleClass;
271         ValueBinding vb = getValueBinding("inactiveSubStyleClass");
272         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
273     }
274
275     public void setTabContentStyleClass(String JavaDoc tabContentStyleClass)
276     {
277         _tabContentStyleClass = tabContentStyleClass;
278     }
279
280     public String JavaDoc getTabContentStyleClass()
281     {
282         if (_tabContentStyleClass != null) return _tabContentStyleClass;
283         ValueBinding vb = getValueBinding("tabContentStyleClass");
284         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
285     }
286
287
288     public String JavaDoc getDisabledTabStyleClass()
289     {
290         return _disabledTabStyleClass;
291     }
292
293
294     public void setDisabledTabStyleClass(String JavaDoc disabledTabStyleClass)
295     {
296         this._disabledTabStyleClass = disabledTabStyleClass;
297     }
298
299
300     public Object JavaDoc saveState(FacesContext context)
301     {
302         Object JavaDoc values[] = new Object JavaDoc[10];
303         values[0] = super.saveState(context);
304         values[1] = _selectedIndex;
305         values[2] = _bgcolor;
306         values[3] = saveAttachedState(context, _tabChangeListener);
307         values[4] = _activeTabStyleClass;
308         values[5] = _inactiveTabStyleClass;
309         values[6] = _activeSubStyleClass;
310         values[7] = _inactiveSubStyleClass;
311         values[8] = _tabContentStyleClass;
312         values[9] = _disabledTabStyleClass;
313         return ((Object JavaDoc) (values));
314     }
315
316     public void restoreState(FacesContext context, Object JavaDoc state)
317     {
318         Object JavaDoc values[] = (Object JavaDoc[])state;
319         super.restoreState(context, values[0]);
320         _selectedIndex = (Integer JavaDoc)values[1];
321         _bgcolor = (String JavaDoc)values[2];
322         _tabChangeListener = (MethodBinding)restoreAttachedState(context, values[3]);
323         _activeTabStyleClass = (String JavaDoc)values[4];
324         _inactiveTabStyleClass = (String JavaDoc)values[5];
325         _activeSubStyleClass = (String JavaDoc)values[6];
326         _inactiveSubStyleClass = (String JavaDoc)values[7];
327         _tabContentStyleClass = (String JavaDoc)values[8];
328         _disabledTabStyleClass = (String JavaDoc)values[9];
329     }
330     //------------------ GENERATED CODE END ---------------------------------------
331
}
332
Popular Tags