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.finalize; 017 018 import org.kuali.rice.krad.uif.component.Component; 019 import org.kuali.rice.krad.uif.component.DataBinding; 020 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle; 021 import org.kuali.rice.krad.uif.lifecycle.ViewLifecyclePhase; 022 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase; 023 import org.kuali.rice.krad.uif.util.LifecycleElement; 024 import org.kuali.rice.krad.uif.view.ViewModel; 025 026 /** 027 * Sets data bindings to read-only at the end of the apply model phase. 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031 public class SetReadOnlyOnDataBindingTask extends ViewLifecycleTaskBase<DataBinding> { 032 033 /** 034 * Constructor. 035 * 036 * @param phase The finalize phase for the component. 037 */ 038 public SetReadOnlyOnDataBindingTask(ViewLifecyclePhase phase) { 039 super(phase, DataBinding.class); 040 } 041 042 /** 043 * {@inheritDoc} 044 */ 045 @Override 046 protected void performLifecycleTask() { 047 // implement readonly request overrides 048 LifecycleElement element = getElementState().getElement(); 049 ViewModel viewModel = (ViewModel) ViewLifecycle.getModel(); 050 if ((element instanceof DataBinding) 051 && ViewLifecycle.getView().isSupportsRequestOverrideOfReadOnlyFields() 052 && !viewModel.getReadOnlyFieldsList().isEmpty()) { 053 DataBinding dataBinding = (DataBinding) element; 054 String propertyName = dataBinding.getPropertyName(); 055 if (viewModel.getReadOnlyFieldsList().contains(propertyName)) { 056 ((Component) dataBinding).setReadOnly(true); 057 } 058 } 059 } 060 061 }