View Javadoc
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  
20  package org.apache.myfaces.tobago.internal.component;
21  
22  import org.apache.myfaces.tobago.component.Attributes;
23  import org.apache.myfaces.tobago.component.Facets;
24  import org.apache.myfaces.tobago.model.CollapseMode;
25  
26  import javax.el.ValueExpression;
27  import javax.faces.component.UIComponent;
28  import javax.faces.context.FacesContext;
29  
30  /**
31   * Base class for collapsible panels.
32   */
33  public abstract class AbstractUICollapsiblePanel extends AbstractUIPanelBase {
34  
35    private transient Boolean submittedCollapsed;
36  
37    @Override
38    public void processDecodes(final FacesContext facesContext) {
39      if (isNormalLifecycle()) {
40        super.processDecodes(facesContext);
41      } else {
42        decode(facesContext);
43        final UIComponent bar = getFacet(Facets.BAR); // XXX is from Box or Section
44        if (bar != null) {
45          bar.processDecodes(facesContext);
46        }
47      }
48    }
49  
50    @Override
51    public void processValidators(final FacesContext facesContext) {
52      if (isNormalLifecycle()) {
53        super.processValidators(facesContext);
54      } else {
55        final UIComponent bar = getFacet(Facets.BAR); // XXX is from Box or Section
56        if (bar != null) {
57          bar.processValidators(facesContext);
58        }
59      }
60    }
61  
62    @Override
63    public void processUpdates(final FacesContext facesContext) {
64      if (isNormalLifecycle()) {
65        super.processUpdates(facesContext);
66      } else {
67        final UIComponent bar = getFacet(Facets.BAR); // XXX is from Box or Section
68        if (bar != null) {
69          bar.processUpdates(facesContext);
70        }
71      }
72    }
73  
74    public boolean isNormalLifecycle() {
75      return getCollapsedMode() == CollapseMode.hidden || !isCollapsed();
76    }
77  
78    public abstract boolean isCollapsed();
79  
80    public abstract void setCollapsed(final boolean collapsed);
81  
82    public abstract CollapseMode getCollapsedMode();
83  
84    public void setSubmittedCollapsed(final Boolean submittedCollapsed) {
85      this.submittedCollapsed = submittedCollapsed;
86    }
87  
88    public void processState() {
89      if (submittedCollapsed != null) {
90        final ValueExpression valueExpression = getValueExpression(Attributes.collapsed.name());
91        if (valueExpression != null) {
92          valueExpression.setValue(FacesContext.getCurrentInstance().getELContext(), submittedCollapsed);
93        } else {
94          setCollapsed(submittedCollapsed);
95        }
96        submittedCollapsed = null;
97      }
98    }
99  }