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.field.DataField;
19  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
20  import org.kuali.rice.krad.uif.lifecycle.ViewLifecyclePhase;
21  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase;
22  import org.kuali.rice.krad.uif.lifecycle.ViewPostMetadata;
23  import org.kuali.rice.krad.uif.util.LifecycleElement;
24  
25  /**
26   * If the data field has a configured property editor registers the editor with the view
27   * post metadata.
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   * @see org.kuali.rice.krad.uif.field.DataField#getPropertyEditor()
31   */
32  public class RegisterPropertyEditorTask extends ViewLifecycleTaskBase<DataField> {
33  
34      /**
35       * Constructor.
36       *
37       * @param phase phase the task is running in
38       */
39      public RegisterPropertyEditorTask(ViewLifecyclePhase phase) {
40          super(phase, DataField.class);
41      }
42  
43      /**
44       * {@inheritDoc}
45       */
46      @Override
47      protected void performLifecycleTask() {
48          LifecycleElement element = getElementState().getElement();
49  
50          if (!(element instanceof DataField)) {
51              return;
52          }
53  
54          DataField dataField = (DataField) element;
55  
56          if ((dataField.getPropertyEditor() == null) || !dataField.isRender()) {
57              return;
58          }
59  
60          ViewPostMetadata viewPostMetadata = ViewLifecycle.getViewPostMetadata();
61          if (dataField.hasSecureValue()) {
62              viewPostMetadata.addSecureFieldPropertyEditor(dataField.getBindingInfo().getBindingPath(),
63                      dataField.getPropertyEditor());
64          } else {
65              viewPostMetadata.addFieldPropertyEditor(dataField.getBindingInfo().getBindingPath(),
66                      dataField.getPropertyEditor());
67          }
68      }
69  }