Coverage Report - org.kuali.student.common.ui.client.widgets.menus.KSListPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
KSListPanel
0%
0/29
0%
0/4
1.222
KSListPanel$ListType
0%
0/2
N/A
1.222
 
 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.menus;
 17  
 
 18  
 import com.google.gwt.user.client.DOM;
 19  
 import com.google.gwt.user.client.Element;
 20  
 import com.google.gwt.user.client.ui.ComplexPanel;
 21  
 import com.google.gwt.user.client.ui.Label;
 22  
 import com.google.gwt.user.client.ui.Widget;
 23  
 import com.google.gwt.user.client.ui.WidgetCollection;
 24  
 
 25  
 /**
 26  
  * @author wilj
 27  
  */
 28  
 public class KSListPanel extends ComplexPanel {
 29  0
     public enum ListType {
 30  0
         ORDERED, UNORDERED
 31  
     }
 32  
 
 33  
     private final ListType listType;
 34  
     private final Element listElement;
 35  
 
 36  
     public KSListPanel() {
 37  0
         this(ListType.UNORDERED);
 38  0
     }
 39  
 
 40  0
     public KSListPanel(final ListType listType) {
 41  0
         this.listType = listType;
 42  0
         setElement(DOM.createDiv());
 43  0
         if (listType == ListType.ORDERED) {
 44  0
             this.listElement = DOM.createElement("ol");
 45  
         } else {
 46  0
             this.listElement = DOM.createElement("ul");
 47  
         }
 48  0
         getElement().appendChild(listElement);
 49  0
     }
 50  
 
 51  
     @Override
 52  
     public void add(final Widget widget) {
 53  0
         super.add(widget, listElement.appendChild(DOM.createElement("li")));
 54  0
     }
 55  
 
 56  
     public void add(final Widget widget, String text) {
 57  0
         Element element = DOM.createElement("li");
 58  0
         element.appendChild(new Label(text).getElement());
 59  0
         super.add(widget, listElement.appendChild(element));
 60  0
     }
 61  
 
 62  
     /**
 63  
      * @return the listType
 64  
      */
 65  
     public ListType getListType() {
 66  0
         return listType;
 67  
     }
 68  
 
 69  
     /* (non-Javadoc)
 70  
       * @see com.google.gwt.user.client.ui.ComplexPanel#remove(int)
 71  
       */
 72  
 
 73  
     @Override
 74  
     public boolean remove(final int index) {
 75  0
         final Widget w = super.getWidget(index);
 76  0
         final boolean result = super.remove(index);
 77  
 
 78  0
         return result;
 79  
     }
 80  
 
 81  
     @Override
 82  
     public boolean remove(Widget w) {
 83  0
         int widgetIndex = super.getWidgetIndex(w);
 84  0
         super.remove(w);
 85  0
         listElement.removeChild(listElement.getChildNodes().getItem(widgetIndex));
 86  0
         return true;
 87  
     }
 88  
 
 89  
     @Override
 90  
     public void clear() {
 91  0
         super.clear();
 92  0
         for (int i = 0; i < listElement.getChildNodes().getLength(); i++) {
 93  0
             listElement.removeChild(listElement.getChildNodes().getItem(i));
 94  
         }
 95  
 
 96  0
     }
 97  
 
 98  
     public WidgetCollection getChildren() {
 99  0
         return super.getChildren();    
 100  
     }
 101  
 
 102  
 }