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;
17  
18  
19  import java.util.List;
20  
21  import org.kuali.student.common.ui.client.mvc.Callback;
22  import org.kuali.student.common.ui.client.widgets.impl.KSDropDownImpl;
23  import org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract;
24  import org.kuali.student.common.ui.client.widgets.list.ListItems;
25  import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
26  
27  import com.google.gwt.core.client.GWT;
28  import com.google.gwt.event.dom.client.BlurHandler;
29  import com.google.gwt.event.dom.client.FocusHandler;
30  import com.google.gwt.event.shared.HandlerRegistration;
31  import com.google.gwt.user.client.ui.Widget;
32  
33  /**
34   * KSDropDown wraps gwt Listbox in a KSSelectItemWidgetAbstract. This provides  
35   * the same basic functionality as a listbox, but allows it to be interchangable
36   * with other select item widget implementations.
37   * 
38   * @author Kuali Student Team
39   *
40   */
41  public class KSDropDown extends KSSelectItemWidgetAbstract{ 
42      
43      KSSelectItemWidgetAbstract dropDown = GWT.create(KSDropDownImpl.class);
44      /**
45       * This constructs a KSDropDown that wraps an impl
46       * 
47       */    
48  	public KSDropDown(){
49  	    this.initWidget(dropDown);
50  	}
51  
52      /**
53       * Select an item whose text equals the name passed in.
54       * 
55       * @param id of the item to be selected.
56       */
57      @Override
58      public void selectItem(String id) {
59          dropDown.selectItem(id);       
60      }
61  
62      /**
63       * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#deSelectItem(java.lang.String)
64       */
65      @Override
66      public void deSelectItem(String id) {       
67          dropDown.deSelectItem(id);
68      }
69  
70      /**
71       * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#getSelectedItems()
72       */
73      @Override
74      public List<String> getSelectedItems() {
75          return dropDown.getSelectedItems();
76      }
77  
78      /**
79       * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#getSelectedItem()
80       */
81      @Override
82      public String getSelectedItem() {
83          return dropDown.getSelectedItem();
84      }
85  
86      /**
87       * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#onLoad()
88       */
89      @Override
90      public void onLoad() {
91          dropDown.onLoad();
92      }
93  
94      /**
95       * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#setListItems(org.kuali.student.common.ui.client.widgets.list.ListItems)
96       */
97      @Override
98      public void setListItems(ListItems listItems) {
99          dropDown.setListItems(listItems);
100     }
101 
102     /**
103      * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#addSelectionChangeHandler(org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler)
104      */
105     public HandlerRegistration addSelectionChangeHandler(SelectionChangeHandler selectionHandler) {
106         return dropDown.addSelectionChangeHandler(selectionHandler);
107     }
108 
109     /**
110      * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#getListItems()
111      */
112     public ListItems getListItems() {
113         return dropDown.getListItems();
114     }
115 
116     /**
117      * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#getName()
118      */
119     public String getName() {
120         return dropDown.getName();
121     }
122 
123     /**
124      * @see org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract#setName(java.lang.String)
125      */
126     @Override
127     public void setName(String name) {
128         dropDown.setName(name);
129     }
130 
131     public void setEnabled(boolean b) {
132         dropDown.setEnabled(b);
133     }
134 
135     @Override
136     public boolean isEnabled() {
137         return dropDown.isEnabled();
138     }
139 
140     public boolean isBlankFirstItem() {
141     	if (dropDown instanceof KSDropDownImpl){
142     		return ((KSDropDownImpl)dropDown).isBlankFirstItem();
143     	} else {
144     		return false;
145     	}
146     }
147 
148     /** 
149      * Use when the first item in list should be blank. If set, it must be called before call to setListItems()
150      * 
151      * @param blankFirstItem
152      */
153     public void setBlankFirstItem(boolean blankFirstItem) {
154     	if (dropDown instanceof KSDropDownImpl){
155     		((KSDropDownImpl)dropDown).setBlankFirstItem(blankFirstItem);
156     	}
157     }
158 
159     @Override
160     public void redraw() {
161         dropDown.redraw();        
162     }
163 
164 	@Override
165 	public HandlerRegistration addFocusHandler(FocusHandler handler) {
166 		return dropDown.addFocusHandler(handler);
167 	}
168 
169 	@Override
170 	public HandlerRegistration addBlurHandler(BlurHandler handler) {
171 		return dropDown.addBlurHandler(handler);
172 	}
173 
174     @Override
175     public void addWidgetReadyCallback(Callback<Widget> callback) {
176         dropDown.addWidgetReadyCallback(callback);
177     }
178 
179     @Override
180     public boolean isInitialized() {
181         return dropDown.isInitialized();
182     }
183 
184     @Override
185     public void setInitialized(boolean initialized) {
186         dropDown.setInitialized(initialized);
187     }
188 
189     @Override
190     public void clear() {
191         dropDown.clear();        
192     }
193 }