001/**
002 * Copyright 2005-2016 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 */
016package edu.sampleu.demo.kitchensink;
017
018import edu.sampleu.travel.bo.TravelAccount;
019import org.kuali.rice.core.api.search.SearchOperator;
020import org.kuali.rice.core.api.uif.RemotableAttributeField;
021import org.kuali.rice.core.api.uif.RemotableSelect;
022import org.kuali.rice.core.api.uif.RemotableTextInput;
023import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
024import org.kuali.rice.krad.uif.container.Container;
025import org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl;
026import org.kuali.rice.krad.uif.view.View;
027
028import java.util.ArrayList;
029import java.util.HashMap;
030import java.util.List;
031import java.util.Map;
032
033/**
034 * Custom view helper service for demonstration (supports the kitchen sink)
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038public class UIfComponentsViewHelperServiceImpl extends ViewHelperServiceImpl {
039
040    public List<RemotableAttributeField> retrieveRemoteFields(View view, Object model, Container container) {
041        List<RemotableAttributeField> remoteFields = new ArrayList<RemotableAttributeField>();
042
043        // note this would generally invoke a remote service to get the list of fields
044        RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create("remoteField1");
045        builder.setLongLabel("Remote Field 1");
046
047        RemotableTextInput.Builder controlBuilder = RemotableTextInput.Builder.create();
048        controlBuilder.setSize(30);
049        builder.setControl(controlBuilder);
050        remoteFields.add(builder.build());
051
052        builder.setName("remoteField2");
053        builder.setLongLabel("Remote Field 2");
054        remoteFields.add(builder.build());
055
056        controlBuilder.setSize(5);
057        builder.setName("remoteField3");
058        builder.setLongLabel("Remote Field 3");
059        remoteFields.add(builder.build());
060
061        Map<String, String> options = new HashMap<String, String>();
062        options.put("Fruit", "Fruit");
063        options.put("Vegetables", "Vegetables");
064
065        RemotableSelect.Builder selectBuilder = RemotableSelect.Builder.create(options);
066        builder.setName("remoteField4");
067        builder.setLongLabel("Remote Field 4");
068        builder.setControl(selectBuilder);
069        remoteFields.add(builder.build());
070
071        return remoteFields;
072    }
073
074    public List<TravelAccount> retrieveTravelAccounts(String term) {
075        List<TravelAccount> matchingAccounts = new ArrayList<TravelAccount>();
076
077        Map<String, String> lookupCriteria = new HashMap<String, String>();
078        lookupCriteria.put("number", term + SearchOperator.LIKE_MANY.op());
079
080        matchingAccounts = (List<TravelAccount>) KRADServiceLocatorWeb.getLookupService().findCollectionBySearch(
081                TravelAccount.class, lookupCriteria);
082
083        return matchingAccounts;
084    }
085
086    public List<TravelAccount> retrieveTravelAccountsBySubAcctAndTerm(String subAccount, String term) {
087        List<TravelAccount> matchingAccounts = new ArrayList<TravelAccount>();
088
089        Map<String, String> lookupCriteria = new HashMap<String, String>();
090        lookupCriteria.put("subAccount", subAccount);
091        lookupCriteria.put("number", term + SearchOperator.LIKE_MANY.op());
092
093        matchingAccounts = (List<TravelAccount>) KRADServiceLocatorWeb.getLookupService().findCollectionBySearch(
094                TravelAccount.class, lookupCriteria);
095
096        return matchingAccounts;
097    }
098
099
100
101}