1 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 ; 32 import java.util.List ; 33 34 66 public class HtmlPanelTabbedPane 67 extends HtmlPanelGroup 68 { 69 71 private MethodBinding _tabChangeListener = null; 72 73 75 public void decode(FacesContext context) 76 { 77 super.decode(context); } 79 80 public void processDecodes(javax.faces.context.FacesContext context) 81 { 82 if (context == null) throw new NullPointerException ("context"); 83 decode(context); 84 85 int tabIdx = 0; 86 int selectedIndex = getSelectedIndex(); 87 88 Iterator 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 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 []{event}); 160 } 161 catch (EvaluationException e) 162 { 163 Throwable 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 178 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlPanelTabbedPane"; 179 public static final String COMPONENT_FAMILY = "javax.faces.Panel"; 180 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.TabbedPane"; 181 private static final int DEFAULT_SELECTEDINDEX = 0; 182 183 private Integer _selectedIndex = null; 184 private String _bgcolor = null; 185 private String _activeTabStyleClass = null; 186 private String _inactiveTabStyleClass = null; 187 private String _disabledTabStyleClass = null; 188 private String _activeSubStyleClass = null; 189 private String _inactiveSubStyleClass = null; 190 private String _tabContentStyleClass = null; 191 192 public HtmlPanelTabbedPane() 193 { 194 setRendererType(DEFAULT_RENDERER_TYPE); 195 } 196 197 public String getFamily() 198 { 199 return COMPONENT_FAMILY; 200 } 201 202 public void setSelectedIndex(int selectedIndex) 203 { 204 _selectedIndex = new Integer (selectedIndex); 205 } 206 207 public int getSelectedIndex() 208 { 209 if (_selectedIndex != null) return _selectedIndex.intValue(); 210 ValueBinding vb = getValueBinding("selectedIndex"); 211 Integer v = vb != null ? (Integer )vb.getValue(getFacesContext()) : null; 212 return v != null ? v.intValue() : DEFAULT_SELECTEDINDEX; 213 } 214 215 public void setBgcolor(String bgcolor) 216 { 217 _bgcolor = bgcolor; 218 } 219 220 public String getBgcolor() 221 { 222 if (_bgcolor != null) return _bgcolor; 223 ValueBinding vb = getValueBinding("bgcolor"); 224 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 225 } 226 227 public void setActiveTabStyleClass(String activeTabStyleClass) 228 { 229 _activeTabStyleClass = activeTabStyleClass; 230 } 231 232 public String getActiveTabStyleClass() 233 { 234 if (_activeTabStyleClass != null) return _activeTabStyleClass; 235 ValueBinding vb = getValueBinding("activeTabStyleClass"); 236 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 237 } 238 239 public void setInactiveTabStyleClass(String inactiveTabStyleClass) 240 { 241 _inactiveTabStyleClass = inactiveTabStyleClass; 242 } 243 244 public String getInactiveTabStyleClass() 245 { 246 if (_inactiveTabStyleClass != null) return _inactiveTabStyleClass; 247 ValueBinding vb = getValueBinding("inactiveTabStyleClass"); 248 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 249 } 250 251 public void setActiveSubStyleClass(String activeSubStyleClass) 252 { 253 _activeSubStyleClass = activeSubStyleClass; 254 } 255 256 public String getActiveSubStyleClass() 257 { 258 if (_activeSubStyleClass != null) return _activeSubStyleClass; 259 ValueBinding vb = getValueBinding("activeSubStyleClass"); 260 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 261 } 262 263 public void setInactiveSubStyleClass(String inactiveSubStyleClass) 264 { 265 _inactiveSubStyleClass = inactiveSubStyleClass; 266 } 267 268 public String getInactiveSubStyleClass() 269 { 270 if (_inactiveSubStyleClass != null) return _inactiveSubStyleClass; 271 ValueBinding vb = getValueBinding("inactiveSubStyleClass"); 272 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 273 } 274 275 public void setTabContentStyleClass(String tabContentStyleClass) 276 { 277 _tabContentStyleClass = tabContentStyleClass; 278 } 279 280 public String getTabContentStyleClass() 281 { 282 if (_tabContentStyleClass != null) return _tabContentStyleClass; 283 ValueBinding vb = getValueBinding("tabContentStyleClass"); 284 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 285 } 286 287 288 public String getDisabledTabStyleClass() 289 { 290 return _disabledTabStyleClass; 291 } 292 293 294 public void setDisabledTabStyleClass(String disabledTabStyleClass) 295 { 296 this._disabledTabStyleClass = disabledTabStyleClass; 297 } 298 299 300 public Object saveState(FacesContext context) 301 { 302 Object values[] = new Object [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 ) (values)); 314 } 315 316 public void restoreState(FacesContext context, Object state) 317 { 318 Object values[] = (Object [])state; 319 super.restoreState(context, values[0]); 320 _selectedIndex = (Integer )values[1]; 321 _bgcolor = (String )values[2]; 322 _tabChangeListener = (MethodBinding)restoreAttachedState(context, values[3]); 323 _activeTabStyleClass = (String )values[4]; 324 _inactiveTabStyleClass = (String )values[5]; 325 _activeSubStyleClass = (String )values[6]; 326 _inactiveSubStyleClass = (String )values[7]; 327 _tabContentStyleClass = (String )values[8]; 328 _disabledTabStyleClass = (String )values[9]; 329 } 330 } 332 | Popular Tags |