001    /**
002     * Copyright 2005-2014 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.uif.lifecycle;
017    
018    import java.util.Queue;
019    
020    import org.kuali.rice.krad.uif.UifConstants;
021    import org.kuali.rice.krad.uif.component.Component;
022    import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle.LifecycleEvent;
023    import org.kuali.rice.krad.uif.lifecycle.initialize.AssignIdsTask;
024    import org.kuali.rice.krad.uif.lifecycle.initialize.PopulatePathTask;
025    import org.kuali.rice.krad.uif.lifecycle.initialize.PrepareForCacheTask;
026    import org.kuali.rice.krad.uif.lifecycle.initialize.SortContainerTask;
027    import org.kuali.rice.krad.uif.util.LifecycleElement;
028    
029    /**
030     * Lifecycle phase implementation representing the pre-process phase.
031     *
032     * @author Kuali Rice Team (rice.collab@kuali.org)
033     */
034    public class PreProcessElementPhase extends ViewLifecyclePhaseBase {
035    
036        /**
037         * {@inheritDoc}
038         */
039        @Override
040        public LifecycleEvent getEventToNotify() {
041            return null;
042        }
043    
044        /**
045         * {@inheritDoc}
046         */
047        @Override
048        public String getStartViewStatus() {
049            return UifConstants.ViewStatus.CREATED;
050        }
051    
052        /**
053         * {@inheritDoc}
054         */
055        @Override
056        public String getEndViewStatus() {
057            return UifConstants.ViewStatus.CACHED;
058        }
059    
060        /**
061         * {@inheritDoc}
062         */
063        @Override
064        public String getViewPhase() {
065            return UifConstants.ViewPhases.PRE_PROCESS;
066        }
067    
068        /**
069         * {@inheritDoc}
070         */
071        @Override
072        protected void initializePendingTasks(Queue<ViewLifecycleTask<?>> tasks) {
073            tasks.offer(LifecycleTaskFactory.getTask(AssignIdsTask.class, this));
074            tasks.offer(LifecycleTaskFactory.getTask(PopulatePathTask.class, this));
075            tasks.offer(LifecycleTaskFactory.getTask(SortContainerTask.class, this));
076            tasks.offer(LifecycleTaskFactory.getTask(PrepareForCacheTask.class, this));
077        }
078    
079        /**
080         * {@inheritDoc}
081         */
082        @Override
083        protected ViewLifecyclePhase initializeSuccessor(LifecycleElement nestedElement, String nestedPath,
084                Component nestedParent) {
085            if (nestedElement != null && !UifConstants.ViewStatus.CACHED.equals(nestedElement.getViewStatus())) {
086                return LifecyclePhaseFactory.preProcess(nestedElement, nestedPath, nestedParent);
087            }
088    
089            return null;
090        }
091    
092    }