1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.custom.accordion;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import javax.faces.context.FacesContext;
25
26 import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
27
28
29 /**
30 * A group of panels, which can be opened and closed. See attribute layout for
31 * further description on how opening and closing works.
32 *
33 * Extends standard panelGroup by user role support.
34 *
35 * @JSFComponent
36 * name = "s:accordionPanel"
37 * class = "org.apache.myfaces.custom.accordion.HtmlAccordionPanel"
38 * tagClass = "org.apache.myfaces.custom.accordion.HtmlAccordionPanelTag"
39 *
40 * @author Martin Marinschek
41 * @version $Revision: 663481 $ $Date: 2008-06-05 02:00:34 -0500 (Thu, 05 Jun 2008) $
42 * <p/>
43 */
44 public abstract class AbstractHtmlAccordionPanel extends HtmlPanelGroup
45 {
46 public static String ACCORDION_LAYOUT = "accordion";
47 public static String TOGGLING_LAYOUT = "toggling";
48
49 public static String EXPANDED_BACK_COLOR = "expandedBg";
50 public static String EXPANDED_TEXT_COLOR = "expandedTextColor";
51 public static String EXPANDED_FONT_WEIGHT = "expandedFontWeight";
52 public static String COLLAPSED_BACK_COLOR = "collapsedBg";
53 public static String COLLAPSED_TEXT_COLOR = "collapsedTextColor";
54 public static String COLLAPSED_FONT_WEIGHT = "collapsedFontWeight";
55 public static String HOVER_BACK_COLOR = "hoverBg";
56 public static String HOVER_TEXT_COLOR = "hoverTextColor";
57 public static String BORDER_COLOR = "borderColor";
58
59 public static String EXPAND_STATEHOLDER_ID = "_STATEHOLDER";
60
61 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlAccordionPanel";
62 public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.AccordionPanel";
63
64 //expansionstate of children
65 private List _childExpanded;
66
67 public Object saveState(FacesContext context)
68 {
69 Object[] values = new Object[2];
70 values[0] = super.saveState(context);
71 values[1] = _childExpanded;
72
73 return values;
74 }
75
76 public void restoreState(FacesContext context, Object state)
77 {
78 Object values[] = (Object[])state;
79 super.restoreState(context, values[0]);
80 _childExpanded = (List) values[1];
81 }
82
83 /**
84 * Defines the layout of this accordionPanel. If you set this to
85 * 'accordion', opening a panel will close all other panels.
86 * If you set this to 'toggling', opening a panel doesn't
87 * affect the state of the other panels. You can close
88 * a panel by clicking on the header of this panel a second time.
89 *
90 * @JSFProperty
91 * defaultValue="accordion"
92 */
93 public abstract String getLayout();
94
95 /**
96 * Defines the background color for expanded state.
97 *
98 * @JSFProperty
99 */
100 public abstract String getExpandedBackColor();
101
102 /**
103 * Defines the text color for expanded state.
104 *
105 * @JSFProperty
106 */
107 public abstract String getExpandedTextColor();
108
109 /**
110 * Defines the font weight for expanded state.
111 *
112 * @JSFProperty
113 */
114 public abstract String getExpandedFontWeight();
115
116 /**
117 * Defines the background color for collapsed state.
118 *
119 * @JSFProperty
120 */
121 public abstract String getCollapsedBackColor();
122
123 /**
124 * Defines the text color for collapsed state.
125 *
126 * @JSFProperty
127 */
128 public abstract String getCollapsedTextColor();
129
130 /**
131 * Defines the font weight for collapsed state.
132 *
133 * @JSFProperty
134 */
135 public abstract String getCollapsedFontWeight();
136
137 /**
138 * Defines the background color on hover.
139 *
140 * @JSFProperty
141 */
142 public abstract String getHoverBackColor();
143
144 /**
145 * Defines the text color on hover.
146 *
147 * @JSFProperty
148 */
149 public abstract String getHoverTextColor();
150
151 /**
152 * Defines the color of the border.
153 *
154 * @JSFProperty
155 */
156 public abstract String getBorderColor();
157
158 //TODO
159 public List getChildExpanded()
160 {
161 if(_childExpanded == null)
162 {
163 _childExpanded = new ArrayList(getChildCount());
164 for(int i = 0; i < getChildCount(); i++)
165 {
166 Integer curState = new Integer(i == 0 ? 1 : 0);
167 _childExpanded.add(curState);
168 }
169 }
170 return _childExpanded;
171 }
172
173
174 public void setChildExpanded(List childExpanded)
175 {
176 _childExpanded = childExpanded;
177 }
178 }