package com.appspot.bootstrap4gwt.client.ui;

import com.google.gwt.dom.client.Document;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

public class Breadcrumbs extends ComplexPanel {

    public Breadcrumbs() {
        setElement(Document.get().createULElement());
        setStyleName("breadcrumb");
    }
    
    public void add(Anchor child) {
        Li li = new Li();
        if (child.getStyleName().indexOf("active") > -1) {
            li.setStyleName("active");
        }
        if (getWidgetCount() > 0) {
            InlineHTML divider = new InlineHTML("/");
            divider.setStyleName("divider");
            li.add(divider);
        }
        li.add(child);
        add(li, getElement());
    }
    
    public void add(Li child) {
        Li li = new Li();
        li.setStyleName("active");
        if (getWidgetCount() > 0) {
            InlineHTML divider = new InlineHTML("/");
            divider.setStyleName("divider");
            li.add(divider);
        }
        li.add(child);
        add(li, getElement());
    }
    
    @Override
    @Deprecated
    public void add(IsWidget child) {
        super.add(child);
    }
    
    @Override
    @Deprecated
    public void add(Widget child) {
        super.add(child);
    }
    
    public Anchor getAnchor(int index) {
        return (Anchor) super.getWidget(index);
    }
    
    @Override
    @Deprecated
    public Widget getWidget(int index) {
        return super.getWidget(index);
    }
}

@@ -499,36 +499,32 @@
 rumb%22);%0D%0A    %7D%0D%0A
-    
 %0D%0A    public voi
@@ -696,231 +696,33 @@
     
-if (getWidgetCount() %3E 0) %7B%0D%0A            InlineHTML divider = new InlineHTML(%22/%22);%0D%0A            divider.setStyleName(%22divider%22);%0D%0A            li.add(divider);%0D%0A        %7D%0D%0A        li.add(child);%0D%0A        add(li, getElement()
+%0D%0A        addLi(li, child
 );%0D%0A
@@ -720,36 +720,32 @@
 child);%0D%0A    %7D%0D%0A
-    
 %0D%0A    public voi
@@ -838,136 +838,128 @@
     
-if (getWidgetCount() %3E 0) %7B
+%0D%0A        addLi(li, child);
 %0D%0A    
+%7D%0D%0A
     
+%0D%0A
     
-InlineHTML divider = new InlineHTML(%22/%22);%0D%0A            divider.setStyleName(%22divider%22);
+private void addLi(Li li, Widget w) %7B%0D%0A        if (getWidgetCount() %3E 0) %7B
 %0D%0A  
@@ -979,15 +979,21 @@
 add(
-d
+new D
 ivider
+()
 );%0D%0A
@@ -1014,29 +1014,25 @@
      li.add(
-child
+w
 );%0D%0A        
@@ -1054,36 +1054,32 @@
 ent());%0D%0A    %7D%0D%0A
-    
 %0D%0A    @Override%0D
@@ -1161,36 +1161,32 @@
 child);%0D%0A    %7D%0D%0A
-    
 %0D%0A    @Override%0D
@@ -1270,28 +1270,24 @@
 d);%0D%0A    %7D%0D%0A
-    
 %0D%0A    public
@@ -1370,28 +1370,24 @@
 x);%0D%0A    %7D%0D%0A
-    
 %0D%0A    @Overr
@@ -1496,12 +1496,181 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    private static class Divider extends InlineHTML %7B%0D%0A        protected Divider() %7B%0D%0A            super(%22/%22);%0D%0A            setStyleName(%22divider%22);%0D%0A        %7D%0D%0A    %7D%0D
 %0A%7D%0D%0A

remove duplicate code