View Javadoc

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.r1.common.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  @Deprecated
36  public class SwappablePanel extends Composite{
37  	private VerticalFlowPanel panel = new VerticalFlowPanel();
38  	private ListBox panelSelector = new ListBox();
39  	private LinkedHashMap<String, Widget> panelMap = new LinkedHashMap<String, Widget>();
40  	private SimplePanel content = new SimplePanel();
41  	//FIXME: eventually we will need 'Search For' label as well. can the use of 'Search By' or 'Search For' be automatically
42  	// implied or do we need another lookup configuration parameter?
43  	private KSLabel searchForLabel = new KSLabel(Application.getApplicationContext().getMessage("swappablePanelSearchBy"));
44      private List<Callback<LookupMetadata>> lookupChangedCallbacks = new ArrayList<Callback<LookupMetadata>>();
45      private LinkedHashMap<String, LookupMetadata> searchLookups = new LinkedHashMap<String, LookupMetadata>();
46  
47  	public SwappablePanel(LinkedHashMap<String, Widget> panelMap){
48  		this.panelMap = panelMap;
49  		drawPanel();
50  		panelSelector.addChangeHandler(new ChangeHandler(){
51  
52  			@Override
53  			public void onChange(ChangeEvent event) {
54  				int i = panelSelector.getSelectedIndex();
55  				Widget p = SwappablePanel.this.panelMap.get(panelSelector.getItemText(i));
56  				content.setWidget(p);
57                  if (lookupChangedCallbacks != null &&
58                          searchLookups != null) {
59                      LookupMetadata selectedLookup = SwappablePanel.this.searchLookups.get(
60                              panelSelector.getItemText(i));
61                      for (Callback<LookupMetadata> callback : lookupChangedCallbacks) {
62                          callback.exec(selectedLookup);
63                      }
64                  }
65  			}
66  		});
67  
68  		this.initWidget(panel);
69  	}
70  
71  	private void drawPanel(){
72  	    panel.add(searchForLabel);
73  		panel.add(panelSelector);
74  		panel.add(content);
75  
76          boolean contentSet = false;
77          for (String text : panelMap.keySet()) {
78              panelSelector.addItem(text);
79              if (!contentSet) {
80                  content.setWidget(panelMap.get(text));
81                  contentSet = true;
82              }
83          }
84  	}
85  	
86      public void addLookupChangedCallback(Callback<LookupMetadata> callback) {
87          lookupChangedCallbacks.add(callback);
88      }
89  
90      public LinkedHashMap<String, LookupMetadata> getSearchLookups() {
91          return searchLookups;
92      }
93  
94      public void setSearchLookups(LinkedHashMap<String, LookupMetadata> searchLookups) {
95          this.searchLookups = searchLookups;
96      }
97      
98  }