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     * Created by IntelliJ IDEA.
029     * User: bommel
030     * Date: 28.05.2006
031     * Time: 21:57:46
032     */
033    public class UIReload extends UIComponentBase {
034      public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Reload";
035      public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.Reload";
036    
037      private Integer frequency;
038    
039      private Boolean update;
040    
041      public Object saveState(FacesContext context) {
042        Object[] values = new Object[3];
043        values[0] = super.saveState(context);
044        values[1] = frequency;
045        values[2] = update;
046        return values;
047      }
048    
049      public void restoreState(FacesContext context, Object savedState) {
050        Object[] values = (Object[]) savedState;
051        super.restoreState(context, values[0]);
052        frequency = (Integer) values[1];
053        update = (Boolean) values[2];
054      }
055    
056      public int getFrequency() {
057        if (frequency != null) {
058          return frequency;
059        }
060        ValueBinding vb = getValueBinding(ATTR_FREQUENCY);
061        Integer value = null;
062        if (vb != null) {
063          value = (Integer) vb.getValue(getFacesContext());
064        }
065        if (value != null) {
066          return value;
067        } else {
068          return 5000;
069        }
070      }
071    
072      public void setFrequency(int frequency) {
073        this.frequency = frequency;
074      }
075    
076      public void setUpdate(boolean update) {
077        this.update = update;
078      }
079    
080      public boolean getUpdate() {
081        if (update != null) {
082          return update;
083        }
084        ValueBinding vb = getValueBinding(ATTR_UPDATE);
085        Boolean value = null;
086        if (vb != null) {
087          value = (Boolean) vb.getValue(getFacesContext());
088        }
089        if (value != null) {
090          return value;
091        } else {
092          return true;
093        }
094      }
095    
096      public String getFamily() {
097        return COMPONENT_FAMILY;
098      }
099    }