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