001/** 002 * Copyright 2005-2015 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 */ 016package org.kuali.rice.krad.uif.lifecycle; 017 018import java.util.Set; 019 020import org.kuali.rice.krad.uif.UifConstants; 021import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle.LifecycleEvent; 022import org.kuali.rice.krad.uif.util.LifecycleElement; 023 024/** 025 * Lifecycle phase processing task for applying the model to a component. 026 * 027 * <p> 028 * During the apply model phase each component of the tree if invoked to setup any state based on 029 * the given model data 030 * </p> 031 * 032 * <p> 033 * Part of the view lifecycle that applies the model data to the view. Should be called after the 034 * model has been populated before the view is rendered. The main things that occur during this 035 * phase are: 036 * <ul> 037 * <li>Generation of dynamic fields (such as collection rows)</li> 038 * <li>Execution of conditional logic (hidden, read-only, required settings based on model values)</li> 039 * </ul> 040 * </p> 041 * 042 * <p> 043 * The update phase can be called multiple times for the view's lifecycle (typically only once per 044 * request) 045 * </p> 046 * 047 * @author Kuali Rice Team (rice.collab@kuali.org) 048 */ 049public class ApplyModelComponentPhase extends ViewLifecyclePhaseBase { 050 051 /** 052 * {@inheritDoc} 053 */ 054 @Override 055 public String getViewPhase() { 056 return UifConstants.ViewPhases.APPLY_MODEL; 057 } 058 059 /** 060 * {@inheritDoc} 061 */ 062 @Override 063 public String getStartViewStatus() { 064 return UifConstants.ViewStatus.INITIALIZED; 065 } 066 067 /** 068 * {@inheritDoc} 069 */ 070 @Override 071 public String getEndViewStatus() { 072 return UifConstants.ViewStatus.MODEL_APPLIED; 073 } 074 075 /** 076 * {@inheritDoc} 077 */ 078 @Override 079 public LifecycleEvent getEventToNotify() { 080 return null; 081 } 082 083 /** 084 * Visit a lifecycle element. 085 * 086 * @param element The lifecycle element (component or layout manager) to mark as visisted. 087 * @return True if the element has been visited before, false if this was the first visit. 088 */ 089 public boolean visit(LifecycleElement element) { 090 Set<String> visitedIds = ViewLifecycle.getVisitedIds(); 091 if (visitedIds.contains(element.getId())) { 092 return true; 093 } 094 095 synchronized (visitedIds) { 096 return !visitedIds.add(element.getId()); 097 } 098 } 099 100}