View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.lifecycle.finalize;
17  
18  import org.kuali.rice.krad.uif.component.Component;
19  import org.kuali.rice.krad.uif.component.DataBinding;
20  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
21  import org.kuali.rice.krad.uif.lifecycle.ViewLifecyclePhase;
22  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase;
23  import org.kuali.rice.krad.uif.util.LifecycleElement;
24  import org.kuali.rice.krad.uif.view.ViewModel;
25  
26  /**
27   * Sets data bindings to read-only at the end of the apply model phase.
28   * 
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class SetReadOnlyOnDataBindingTask extends ViewLifecycleTaskBase<DataBinding> {
32  
33      /**
34       * Constructor.
35       * 
36       * @param phase The finalize phase for the component.
37       */
38      public SetReadOnlyOnDataBindingTask(ViewLifecyclePhase phase) {
39          super(phase, DataBinding.class);
40      }
41  
42      /**
43       * {@inheritDoc}
44       */
45      @Override
46      protected void performLifecycleTask() {
47          // implement readonly request overrides
48          LifecycleElement element = getElementState().getElement();
49          ViewModel viewModel = (ViewModel) ViewLifecycle.getModel();
50          if ((element instanceof DataBinding)
51                  && ViewLifecycle.getView().isSupportsRequestOverrideOfReadOnlyFields()
52                  && !viewModel.getReadOnlyFieldsList().isEmpty()) {
53              DataBinding dataBinding = (DataBinding) element;
54              String propertyName = dataBinding.getPropertyName();
55              if (viewModel.getReadOnlyFieldsList().contains(propertyName)) {
56                  ((Component) dataBinding).setReadOnly(true);
57              }
58          }
59      }
60  
61  }