001/** 002 * Copyright 2005-2015 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 org.kuali.rice.krad.labs.quickfinder; 017 018import org.kuali.rice.krad.lookup.LookupableImpl; 019import org.kuali.rice.krad.uif.UifConstants; 020import org.kuali.rice.krad.web.form.UifFormBase; 021 022import java.util.List; 023import java.util.Map; 024 025/** 026 * Quickfinder's view service implementation class that handles callbacks. 027 * 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 * 030 * Cheezy example of using callback methods. Each method is specified in 031 * LabsQuickFinderCallback.xml. 032 */ 033public class QuickfinderViewHelperServiceImpl extends LookupableImpl { 034 035 /** 036 * Retrieves the collection from the form, and depending on the context parameters given, it 037 * manipulates the object in the collection. 038 * 039 * @param form - the form that has the collection 040 * @param quickfinderId - the quickfinder id of the lookup component 041 * @param callbackContext - a map of parameters to manipulate the collection 042 */ 043 public void doCallbackTable1( UifFormBase form, String quickfinderId, Map<String, String> callbackContext ) { 044 QuickfinderForm qForm = (QuickfinderForm)form; 045 List<PersonAccount> collection = qForm.getPersonAccounts1(); 046 conditionallyModAccountName(callbackContext, collection, "Foo Bar"); 047 } 048 049 public void doCallbackTable2( UifFormBase form, String quickfinderId, Map<String, String> callbackContext ) { 050 QuickfinderForm qForm = (QuickfinderForm)form; 051 List<PersonAccount> collection = qForm.getPersonAccounts2(); 052 conditionallyModAccountName(callbackContext, collection, "Yo"); 053 } 054 055 public void doCallbackTable3( UifFormBase form, String quickfinderId, Map<String, String> callbackContext ) { 056 QuickfinderForm qForm = (QuickfinderForm)form; 057 List<PersonAccount> collection = qForm.getPersonAccounts3(); 058 conditionallyModAccountName(callbackContext, collection, "KaBoom"); 059 } 060 061 public void doCallbackTable4( UifFormBase form, String quickfinderId, Map<String, String> callbackContext ) { 062 QuickfinderForm qForm = (QuickfinderForm)form; 063 List<PersonAccount> collection = qForm.getPersonAccounts4(); 064 conditionallyModAccountName(callbackContext, collection, "Far Out"); 065 } 066 067 public void doCallbackTable5( UifFormBase form, String quickfinderId, Map<String, String> callbackContext ) { 068 QuickfinderForm qForm = (QuickfinderForm)form; 069 List<PersonAccount> collection = qForm.getPersonAccounts5(); 070 conditionallyModAccountName(callbackContext, collection, "Yee Haw"); 071 } 072 073 private void conditionallyModAccountName(Map<String, String> callbackContext, List<PersonAccount> collection, 074 String newAccountName) { 075 076 if (callbackContext != null) { 077 String lineIndexAsString = callbackContext 078 .get(UifConstants.PostMetadata.QUICKFINDER_CALLBACK_CONTEXT_PROPERTY_LINE_INDEX); 079 080 if (lineIndexAsString != null) { 081 int lineIndex = Integer.parseInt(lineIndexAsString); 082 if (lineIndex >= 0) { 083 PersonAccount personAccount = collection.get(lineIndex); 084 personAccount.setAccountName(newAccountName); 085 } 086 } 087 } 088 } 089}