View Javadoc
1   /**
2    * Copyright 2005-2016 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.initialize;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.rice.krad.uif.component.Component;
22  import org.kuali.rice.krad.uif.container.Container;
23  import org.kuali.rice.krad.uif.field.InputField;
24  import org.kuali.rice.krad.uif.field.RemoteFieldsHolder;
25  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
26  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase;
27  import org.kuali.rice.krad.uif.view.ViewModel;
28  
29  /**
30   * Process any remote fields holder that might be in the containers items.
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class ProcessRemoteFieldsHolderTask extends ViewLifecycleTaskBase<Container> {
35  
36      /**
37       * Default constructor.
38       */
39      public ProcessRemoteFieldsHolderTask() {
40          super(Container.class);
41      }
42  
43      /**
44       * Invoke custom initialization based on the view helper.
45       * 
46       * {@inheritDoc}
47       */
48      @Override
49      protected void performLifecycleTask() {
50          Container container = (Container) getElementState().getElement();
51          
52          if (!container.isProcessRemoteFieldHolders()) {
53              return;
54          }
55          
56          List<Component> processedItems = new ArrayList<Component>();
57  
58          // check for holders and invoke to retrieve the remotable fields and translate
59          // translated fields are placed into the container item list at the position of the holder
60          for (Component item : container.getItems()) {
61              if (item instanceof RemoteFieldsHolder) {
62                  List<InputField> translatedFields = ((RemoteFieldsHolder) item)
63                          .fetchAndTranslateRemoteFields(container);
64                  processedItems.addAll(translatedFields);
65              } else {
66                  processedItems.add(item);
67              }
68          }
69  
70          // updated container items
71          container.setItems(processedItems);
72  
73          
74          // invoke hook point for adding components through code
75          ViewLifecycle.getHelper().addCustomContainerComponents((ViewModel)ViewLifecycle.getModel(),
76                  (Container) getElementState().getElement());
77      }
78  
79  }