Clover Coverage Report - Kuali Student 1.2-M4-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Jul 20 2011 11:14:35 EDT
../../../../../../../../img/srcFileCovDistChart0.png 41% of files have more coverage
23   97   9   3.83
4   67   0.39   6
6     1.5  
1    
 
  SwappablePanel       Line # 35 23 0% 9 33 0% 0.0
 
No Tests
 
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.assembly.data.LookupMetadata;
23    import org.kuali.student.common.ui.client.application.Application;
24    import org.kuali.student.common.ui.client.mvc.Callback;
25    import org.kuali.student.common.ui.client.widgets.KSLabel;
26    import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
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    public class SwappablePanel extends Composite{
36    private VerticalFlowPanel panel = new VerticalFlowPanel();
37    private ListBox panelSelector = new ListBox();
38    private LinkedHashMap<String, Widget> panelMap = new LinkedHashMap<String, Widget>();
39    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    private KSLabel searchForLabel = new KSLabel(Application.getApplicationContext().getMessage("swappablePanelSearchBy"));
43    private List<Callback<LookupMetadata>> lookupChangedCallbacks = new ArrayList<Callback<LookupMetadata>>();
44    private LinkedHashMap<String, LookupMetadata> searchLookups = new LinkedHashMap<String, LookupMetadata>();
45   
 
46  0 toggle public SwappablePanel(LinkedHashMap<String, Widget> panelMap){
47  0 this.panelMap = panelMap;
48  0 drawPanel();
49  0 panelSelector.addChangeHandler(new ChangeHandler(){
50   
 
51  0 toggle @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    }
65    });
66   
67  0 this.initWidget(panel);
68    }
69   
 
70  0 toggle 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    }
84   
 
85  0 toggle public void addLookupChangedCallback(Callback<LookupMetadata> callback) {
86  0 lookupChangedCallbacks.add(callback);
87    }
88   
 
89  0 toggle public LinkedHashMap<String, LookupMetadata> getSearchLookups() {
90  0 return searchLookups;
91    }
92   
 
93  0 toggle public void setSearchLookups(LinkedHashMap<String, LookupMetadata> searchLookups) {
94  0 this.searchLookups = searchLookups;
95    }
96   
97    }