Coverage Report - org.kuali.student.common.ui.client.widgets.search.SwappablePanel
 
Classes in this File Line Coverage Branch Coverage Complexity
SwappablePanel
0%
0/29
0%
0/4
1.833
SwappablePanel$1
0%
0/9
0%
0/6
1.833
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.common.ui.client.widgets.search;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.LinkedHashMap;
 20  
 import java.util.List;
 21  
 
 22  
 import org.kuali.student.common.ui.client.application.Application;
 23  
 import org.kuali.student.common.ui.client.mvc.Callback;
 24  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 25  
 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
 26  
 import org.kuali.student.core.assembly.data.LookupMetadata;
 27  
 
 28  
 import com.google.gwt.event.dom.client.ChangeEvent;
 29  
 import com.google.gwt.event.dom.client.ChangeHandler;
 30  
 import com.google.gwt.user.client.ui.Composite;
 31  
 import com.google.gwt.user.client.ui.ListBox;
 32  
 import com.google.gwt.user.client.ui.SimplePanel;
 33  
 import com.google.gwt.user.client.ui.Widget;
 34  
 
 35  0
 public class SwappablePanel extends Composite{
 36  0
         private VerticalFlowPanel panel = new VerticalFlowPanel();
 37  0
         private ListBox panelSelector = new ListBox();
 38  0
         private LinkedHashMap<String, Widget> panelMap = new LinkedHashMap<String, Widget>();
 39  0
         private SimplePanel content = new SimplePanel();
 40  
         //FIXME: eventually we will need 'Search For' label as well. can the use of 'Search By' or 'Search For' be automatically
 41  
         // implied or do we need another lookup configuration parameter?
 42  0
         private KSLabel searchForLabel = new KSLabel(Application.getApplicationContext().getMessage("swappablePanelSearchBy"));
 43  0
     private List<Callback<LookupMetadata>> lookupChangedCallbacks = new ArrayList<Callback<LookupMetadata>>();
 44  0
     private LinkedHashMap<String, LookupMetadata> searchLookups = new LinkedHashMap<String, LookupMetadata>();
 45  
 
 46  0
         public SwappablePanel(LinkedHashMap<String, Widget> panelMap){
 47  0
                 this.panelMap = panelMap;
 48  0
                 drawPanel();
 49  0
                 panelSelector.addChangeHandler(new ChangeHandler(){
 50  
 
 51  
                         @Override
 52  
                         public void onChange(ChangeEvent event) {
 53  0
                                 int i = panelSelector.getSelectedIndex();
 54  0
                                 Widget p = SwappablePanel.this.panelMap.get(panelSelector.getItemText(i));
 55  0
                                 content.setWidget(p);
 56  0
                 if (lookupChangedCallbacks != null &&
 57  
                         searchLookups != null) {
 58  0
                     LookupMetadata selectedLookup = SwappablePanel.this.searchLookups.get(
 59  
                             panelSelector.getItemText(i));
 60  0
                     for (Callback<LookupMetadata> callback : lookupChangedCallbacks) {
 61  0
                         callback.exec(selectedLookup);
 62  
                     }
 63  
                 }
 64  0
                         }
 65  
                 });
 66  
 
 67  0
                 this.initWidget(panel);
 68  0
         }
 69  
 
 70  
         private void drawPanel(){
 71  0
             panel.add(searchForLabel);
 72  0
                 panel.add(panelSelector);
 73  0
                 panel.add(content);
 74  
 
 75  0
         boolean contentSet = false;
 76  0
         for (String text : panelMap.keySet()) {
 77  0
             panelSelector.addItem(text);
 78  0
             if (!contentSet) {
 79  0
                 content.setWidget(panelMap.get(text));
 80  0
                 contentSet = true;
 81  
             }
 82  
         }
 83  0
         }
 84  
         
 85  
     public void addLookupChangedCallback(Callback<LookupMetadata> callback) {
 86  0
         lookupChangedCallbacks.add(callback);
 87  0
     }
 88  
 
 89  
     public LinkedHashMap<String, LookupMetadata> getSearchLookups() {
 90  0
         return searchLookups;
 91  
     }
 92  
 
 93  
     public void setSearchLookups(LinkedHashMap<String, LookupMetadata> searchLookups) {
 94  0
         this.searchLookups = searchLookups;
 95  0
     }
 96  
     
 97  
 }