001    package org.apache.myfaces.tobago.component;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FREQUENCY;
021    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_UPDATE;
022    
023    import javax.faces.component.UIComponentBase;
024    import javax.faces.context.FacesContext;
025    import javax.faces.el.ValueBinding;
026    
027    /*
028     * Date: 28.05.2006
029     * Time: 21:57:46
030     */
031    public class UIReload extends UIComponentBase {
032      public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Reload";
033      public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.Reload";
034    
035      private Integer frequency;
036    
037      private Boolean update;
038    
039      private Boolean immediate;
040    
041      public Object saveState(FacesContext context) {
042        Object[] values = new Object[4];
043        values[0] = super.saveState(context);
044        values[1] = frequency;
045        values[2] = update;
046        values[3] = immediate;
047        return values;
048      }
049    
050      public void restoreState(FacesContext context, Object savedState) {
051        Object[] values = (Object[]) savedState;
052        super.restoreState(context, values[0]);
053        frequency = (Integer) values[1];
054        update = (Boolean) values[2];
055        immediate = (Boolean) values[3];
056      }
057    
058      public int getFrequency() {
059        if (frequency != null) {
060          return frequency;
061        }
062        ValueBinding vb = getValueBinding(ATTR_FREQUENCY);
063        Integer value = null;
064        if (vb != null) {
065          value = (Integer) vb.getValue(getFacesContext());
066        }
067        if (value != null) {
068          return value;
069        } else {
070          return 5000;
071        }
072      }
073    
074      public void setFrequency(int frequency) {
075        this.frequency = frequency;
076      }
077    
078      public void setUpdate(boolean update) {
079        this.update = update;
080      }
081    
082      public boolean getUpdate() {
083        if (update != null) {
084          return update;
085        }
086        ValueBinding vb = getValueBinding(ATTR_UPDATE);
087        Boolean value = null;
088        if (vb != null) {
089          value = (Boolean) vb.getValue(getFacesContext());
090        }
091        if (value != null) {
092          return value;
093        } else {
094          return true;
095        }
096      }
097    
098      public void setImmediate(boolean immediate) {
099        this.immediate = immediate;
100      }
101    
102      public boolean isImmediate() {
103        if (immediate != null) {
104          return immediate;
105        }
106        ValueBinding vb = getValueBinding("immediate");
107        Boolean value = null;
108        if (vb != null) {
109          value = (Boolean) vb.getValue(getFacesContext());
110        }
111        if (value != null) {
112          return value;
113        } else {
114          return false;
115        }
116      }
117    
118      public String getFamily() {
119        return COMPONENT_FAMILY;
120      }
121    }