Home » tomahawk-1.1.6-src » org.apache.myfaces » custom » schedule » [javadoc | source]

    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.custom.schedule;
   21   
   22   import java.io.Serializable;
   23   import java.util.Date;
   24   
   25   import javax.faces.context.FacesContext;
   26   import javax.faces.el.MethodBinding;
   27   import javax.faces.el.ValueBinding;
   28   import javax.faces.event.AbortProcessingException;
   29   import javax.faces.event.FacesEvent;
   30   import javax.faces.event.PhaseId;
   31   
   32   import org.apache.myfaces.component.UserRoleAware;
   33   import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
   34   import org.apache.myfaces.shared_tomahawk.util._ComponentUtils;
   35   
   36   /**
   37    *
   38    * @author Bruno Aranda (latest modification by $Author: jlust $)
   39    * @author Jurgen Lust
   40    * @version $Revision: 392301 $
   41    */
   42   public class HtmlSchedule extends UISchedule implements UserRoleAware,
   43           Serializable
   44   {
   45   
   46       public static final String COMPONENT_FAMILY = "javax.faces.Panel";
   47   
   48       public static final String COMPONENT_TYPE = "org.apache.myfaces.Schedule";
   49       private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Schedule";
   50       private static final long serialVersionUID = 5859593107442371656L;
   51       //  ------------------ GENERATED CODE BEGIN (do not modify!) --------------------
   52   
   53       private String _enabledOnUserRole = null;
   54       private Date _lastClickedDateAndTime = null;
   55       private MethodBinding _mouseListener = null;
   56       private Boolean _submitOnClick = null;
   57       private String _visibleOnUserRole = null;
   58   
   59       public HtmlSchedule()
   60       {
   61           setRendererType(DEFAULT_RENDERER_TYPE);
   62       }
   63   
   64       /**
   65        * @see javax.faces.component.UIComponent#broadcast(javax.faces.event.FacesEvent)
   66        */
   67       public void broadcast(FacesEvent event) throws AbortProcessingException
   68       {
   69           // First invoke the mouse listener, before any other listener
   70           if (event instanceof ScheduleMouseEvent)
   71           {
   72               FacesContext context = getFacesContext();
   73               ScheduleMouseEvent mouseEvent = (ScheduleMouseEvent) event;
   74               MethodBinding mouseListenerBinding = getMouseListener();
   75   
   76               if (mouseListenerBinding != null)
   77               {
   78                   mouseListenerBinding.invoke(context,
   79                           new Object[] { mouseEvent });
   80               }
   81           }
   82           //now invoke the other listeners
   83           super.broadcast(event);
   84       }
   85   
   86       /**
   87        * @see org.apache.myfaces.component.UserRoleAware#getEnabledOnUserRole()
   88        */
   89       public String getEnabledOnUserRole()
   90       {
   91           if (_enabledOnUserRole != null)
   92               return _enabledOnUserRole;
   93           ValueBinding vb = getValueBinding("enabledOnUserRole");
   94           return vb != null ? _ComponentUtils.getStringValue(getFacesContext(),
   95                   vb) : null;
   96       }
   97   
   98       /**
   99        * @see javax.faces.component.UIComponent#getFamily()
  100        */
  101       public String getFamily()
  102       {
  103           return COMPONENT_FAMILY;
  104       }
  105   
  106       /**
  107        * <p>
  108        * The last date and time of day that was clicked. This is set when
  109        * submitOnClick is true, and the schedule is clicked by the user.
  110        * </p>
  111        * 
  112        * @return the last clicked date and time
  113        */
  114       public Date getLastClickedDateAndTime()
  115       {
  116           return _lastClickedDateAndTime;
  117       }
  118   
  119       /**
  120        * @return the method binding to the mouse listener method
  121        */
  122       public MethodBinding getMouseListener()
  123       {
  124           return _mouseListener;
  125       }
  126   
  127       /**
  128        * @see org.apache.myfaces.component.UserRoleAware#getVisibleOnUserRole()
  129        */
  130       public String getVisibleOnUserRole()
  131       {
  132           if (_visibleOnUserRole != null)
  133               return _visibleOnUserRole;
  134           ValueBinding vb = getValueBinding("visibleOnUserRole");
  135           return vb != null ? _ComponentUtils.getStringValue(getFacesContext(),
  136                   vb) : null;
  137       }
  138   
  139       /**
  140        * <p>
  141        * Should the parent form of this schedule be submitted when the user
  142        * clicks on a day? Note that this will only work when the readonly
  143        * property is set to false.
  144        * </p>
  145        *
  146        * @return submit the form on mouse click
  147        */
  148       public boolean isSubmitOnClick()
  149       {
  150           return ScheduleUtil.getBooleanProperty(this, _submitOnClick,
  151                   "submitOnClick", false);
  152       }
  153   
  154       /**
  155        * @see javax.faces.component.UIComponent#queueEvent(javax.faces.event.FacesEvent)
  156        */
  157       public void queueEvent(FacesEvent event)
  158       {
  159           if (event instanceof ScheduleMouseEvent)
  160           {
  161               if (isImmediate())
  162               {
  163                   event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
  164               }
  165               else
  166               {
  167                   event.setPhaseId(PhaseId.INVOKE_APPLICATION);
  168               }
  169           }
  170           super.queueEvent(event);
  171       }
  172   
  173       /**
  174        * This method is invoked at the beginning of the restore view phase,
  175        * resetting all mouse event variables that were left from the previous
  176        * request
  177        */
  178       public void resetMouseEvents()
  179       {
  180           this._lastClickedDateAndTime = null;
  181       }
  182   
  183       /**
  184        * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
  185        */
  186       public void restoreState(FacesContext context, Object state)
  187       {
  188           Object values[] = (Object[]) state;
  189           super.restoreState(context, values[0]);
  190           _enabledOnUserRole = (String) values[1];
  191           _visibleOnUserRole = (String) values[2];
  192           _submitOnClick = (Boolean) values[3];
  193           _lastClickedDateAndTime = (Date) values[4];
  194           _mouseListener = (MethodBinding) restoreAttachedState(context,
  195                   values[5]);
  196       }
  197   
  198       //  ------------------ GENERATED CODE END ---------------------------------------
  199   
  200       /**
  201        * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
  202        */
  203       public Object saveState(FacesContext context)
  204       {
  205           Object values[] = new Object[6];
  206           values[0] = super.saveState(context);
  207           values[1] = _enabledOnUserRole;
  208           values[2] = _visibleOnUserRole;
  209           values[3] = _submitOnClick;
  210           values[4] = _lastClickedDateAndTime;
  211           values[5] = saveAttachedState(context, _mouseListener);
  212           return ((Object) (values));
  213       }
  214   
  215       /**
  216        * @see org.apache.myfaces.component.UserRoleAware#setEnabledOnUserRole(java.lang.String)
  217        */
  218       public void setEnabledOnUserRole(String enabledOnUserRole)
  219       {
  220           _enabledOnUserRole = enabledOnUserRole;
  221       }
  222   
  223       /**
  224        * <p>
  225        * The last date and time of day that was clicked. This is set when
  226        * submitOnClick is true, and the schedule is clicked by the user.
  227        * </p>
  228        * 
  229        * @return the last clicked date and time
  230        */
  231       public void setLastClickedDateAndTime(Date lastClickedDateAndTime)
  232       {
  233           this._lastClickedDateAndTime = lastClickedDateAndTime;
  234       }
  235   
  236       /**
  237        * @param listener the method binding to the mouse listener method
  238        */
  239       public void setMouseListener(MethodBinding listener)
  240       {
  241           _mouseListener = listener;
  242       }
  243   
  244       /**
  245        * <p>
  246        * Should the parent form of this schedule be submitted when the user
  247        * clicks on a day? Note that this will only work when the readonly
  248        * property is set to false.
  249        * </p>
  250        * 
  251        *
  252        * @param submitOnClick submit the form on mouse click
  253        */
  254       public void setSubmitOnClick(boolean submitOnClick)
  255       {
  256           this._submitOnClick = Boolean.valueOf(submitOnClick);
  257       }
  258   
  259       public void setVisibleOnUserRole(String visibleOnUserRole)
  260       {
  261           _visibleOnUserRole = visibleOnUserRole;
  262       }
  263   
  264   }
  265   //The End

Home » tomahawk-1.1.6-src » org.apache.myfaces » custom » schedule » [javadoc | source]