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 edu.sampleu.demo.kitchensink;
17  
18  import edu.sampleu.travel.bo.TravelAccount;
19  import org.kuali.rice.core.api.search.SearchOperator;
20  import org.kuali.rice.core.api.uif.RemotableAttributeField;
21  import org.kuali.rice.core.api.uif.RemotableSelect;
22  import org.kuali.rice.core.api.uif.RemotableTextInput;
23  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
24  import org.kuali.rice.krad.uif.container.Container;
25  import org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl;
26  import org.kuali.rice.krad.uif.view.View;
27  
28  import java.util.ArrayList;
29  import java.util.HashMap;
30  import java.util.List;
31  import java.util.Map;
32  
33  /**
34   * Custom view helper service for demonstration (supports the kitchen sink)
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class UIfComponentsViewHelperServiceImpl extends ViewHelperServiceImpl {
39  
40      public List<RemotableAttributeField> retrieveRemoteFields(View view, Object model, Container container) {
41          List<RemotableAttributeField> remoteFields = new ArrayList<RemotableAttributeField>();
42  
43          // note this would generally invoke a remote service to get the list of fields
44          RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create("remoteField1");
45          builder.setLongLabel("Remote Field 1");
46  
47          RemotableTextInput.Builder controlBuilder = RemotableTextInput.Builder.create();
48          controlBuilder.setSize(30);
49          builder.setControl(controlBuilder);
50          remoteFields.add(builder.build());
51  
52          builder.setName("remoteField2");
53          builder.setLongLabel("Remote Field 2");
54          remoteFields.add(builder.build());
55  
56          controlBuilder.setSize(5);
57          builder.setName("remoteField3");
58          builder.setLongLabel("Remote Field 3");
59          remoteFields.add(builder.build());
60  
61          Map<String, String> options = new HashMap<String, String>();
62          options.put("Fruit", "Fruit");
63          options.put("Vegetables", "Vegetables");
64  
65          RemotableSelect.Builder selectBuilder = RemotableSelect.Builder.create(options);
66          builder.setName("remoteField4");
67          builder.setLongLabel("Remote Field 4");
68          builder.setControl(selectBuilder);
69          remoteFields.add(builder.build());
70  
71          return remoteFields;
72      }
73  
74      public List<TravelAccount> retrieveTravelAccounts(String term) {
75          List<TravelAccount> matchingAccounts = new ArrayList<TravelAccount>();
76  
77          Map<String, String> lookupCriteria = new HashMap<String, String>();
78          lookupCriteria.put("number", term + SearchOperator.LIKE_MANY.op());
79  
80          matchingAccounts = (List<TravelAccount>) KRADServiceLocatorWeb.getLookupService().findCollectionBySearch(
81                  TravelAccount.class, lookupCriteria);
82  
83          return matchingAccounts;
84      }
85  
86      public List<TravelAccount> retrieveTravelAccountsBySubAcct(String subAccount, String term) {
87          List<TravelAccount> matchingAccounts = new ArrayList<TravelAccount>();
88  
89          Map<String, String> lookupCriteria = new HashMap<String, String>();
90          lookupCriteria.put("subAccount", subAccount);
91          lookupCriteria.put("number", term + SearchOperator.LIKE_MANY.op());
92  
93          matchingAccounts = (List<TravelAccount>) KRADServiceLocatorWeb.getLookupService().findCollectionBySearch(
94                  TravelAccount.class, lookupCriteria);
95  
96          return matchingAccounts;
97      }
98  
99  
100 
101 }