Coverage Report - org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract
 
Classes in this File Line Coverage Branch Coverage Complexity
KSSelectItemWidgetAbstract
0%
0/32
0%
0/12
1.381
 
 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.list;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.student.common.ui.client.mvc.Callback;
 22  
 import org.kuali.student.common.ui.client.mvc.HasWidgetReadyCallback;
 23  
 import org.kuali.student.core.dto.Idable;
 24  
 
 25  
 import com.google.gwt.event.dom.client.HasBlurHandlers;
 26  
 import com.google.gwt.event.dom.client.HasFocusHandlers;
 27  
 import com.google.gwt.event.shared.HandlerRegistration;
 28  
 import com.google.gwt.user.client.ui.Composite;
 29  
 import com.google.gwt.user.client.ui.HasName;
 30  
 import com.google.gwt.user.client.ui.Widget;
 31  
 
 32  
 /**
 33  
  * This SelectItemWidget abstracts out the use of selecting an item from a list.
 34  
  * Use of this interface will easily allow the underlying widget to be 
 35  
  * interchangeable.
 36  
  * 
 37  
  * @author Kuali Student Team
 38  
  *
 39  
  */
 40  0
 public abstract class KSSelectItemWidgetAbstract extends Composite implements HasName, HasFocusHandlers, HasBlurHandlers, HasSelectionChangeHandlers, HasWidgetReadyCallback{
 41  0
         private ListItems listItems = null;
 42  
         private String name;
 43  
         private List<Callback<Widget>> widgetReadyCallbacks;
 44  0
         private boolean initialized = false;
 45  
                 
 46  
         public ListItems getListItems() {
 47  0
                 return listItems;
 48  
         }
 49  
 
 50  
         public <T extends Idable> void setListItems(ListItems listItems) {
 51  0
                 this.listItems = listItems;
 52  0
         }        
 53  
         
 54  
         public abstract void redraw();
 55  
 
 56  
         /**
 57  
          * Used to had a selection change handler.
 58  
          * 
 59  
          * @param selectionHandler
 60  
          * @return
 61  
          */
 62  
     public HandlerRegistration addSelectionChangeHandler(SelectionChangeHandler selectionHandler){
 63  0
         return addHandler(selectionHandler,SelectionChangeEvent.getType());
 64  
     }           
 65  
         
 66  
         protected void fireChangeEvent(boolean userInitiated){
 67  0
             SelectionChangeEvent.fire(this, userInitiated);
 68  0
         }
 69  
         
 70  
         /**
 71  
          * Select the item in list represented by the id. For multi-select list
 72  
          * any existing selection should remain selected.
 73  
          * 
 74  
          * @param id
 75  
          */        
 76  
         public abstract void selectItem(String id);
 77  
         
 78  
         /**
 79  
          * Remove selection for item represented by id.
 80  
          * 
 81  
          * @param id
 82  
          */
 83  
         public abstract void deSelectItem(String id);
 84  
         
 85  
         
 86  
         /**
 87  
          * List of items that have been selected.
 88  
          * 
 89  
          * @return
 90  
          */
 91  
         public abstract List<String> getSelectedItems();
 92  
         
 93  
         /**
 94  
          * Id of selected item.  If multiple items are selected, this will return the
 95  
          * first selected item.
 96  
          * 
 97  
          * @see com.google.gwt.user.client.ui.HasName#getName()
 98  
          */
 99  
         public String getSelectedItem(){
 100  0
             String selectedItem = null;
 101  0
             List<String> selectedItems = getSelectedItems();
 102  0
             if (selectedItems != null && selectedItems.size() > 0){
 103  0
                 selectedItem = selectedItems.get(0);
 104  
             }
 105  0
             return selectedItem;
 106  
         }        
 107  
         
 108  
     public String getName() {
 109  0
         return this.name;
 110  
     }
 111  
 
 112  
     public void setName(String name) {
 113  0
         this.name = name;         
 114  0
     }
 115  
     
 116  
     /** 
 117  
      * This method should be implemented if list supports setting of multiple select. 
 118  
      * 
 119  
      */
 120  
     public void setMultipleSelect(boolean isMultipleSelect){
 121  0
         throw new UnsupportedOperationException();
 122  
     }
 123  
     
 124  
     /**
 125  
      *  
 126  
      * This method should if implemented if list supports multiple select
 127  
      *
 128  
      */
 129  
     public boolean isMultipleSelect(){
 130  0
         return false;
 131  
     }
 132  
         
 133  
     /** 
 134  
      * This method should be implemented if list supports column sizing. 
 135  
      * 
 136  
      */
 137  
     public void setColumnSize(int col){
 138  0
         throw new UnsupportedOperationException();
 139  
     }
 140  
     
 141  
     public abstract void onLoad();
 142  
 
 143  
     public abstract void setEnabled(boolean b);
 144  
     
 145  
     public abstract boolean isEnabled();
 146  
     
 147  
     /**
 148  
      * 
 149  
      * This method clears the current selection
 150  
      *
 151  
      */
 152  
     public abstract void clear();
 153  
 
 154  
     @Override
 155  
     public void addWidgetReadyCallback(Callback<Widget> callback) {
 156  0
         if (widgetReadyCallbacks == null){
 157  0
             widgetReadyCallbacks = new ArrayList<Callback<Widget>>();
 158  
         }
 159  0
         widgetReadyCallbacks.add(callback);    
 160  0
    }
 161  
 
 162  
     @Override
 163  
     public void setInitialized(boolean initialized) {
 164  0
         this.initialized = initialized;
 165  0
         if (initialized){
 166  
             //Callbacks might need to be moved after a redraw happens
 167  0
             while (widgetReadyCallbacks != null && widgetReadyCallbacks.size() > 0){
 168  0
                 Callback<Widget> callback = widgetReadyCallbacks.remove(0);
 169  0
                 callback.exec(this);
 170  0
             }            
 171  
         }
 172  0
     }
 173  
 
 174  
     @Override
 175  
     public boolean isInitialized() {
 176  0
         return initialized;
 177  
     }
 178  
 }