1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
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 | |
|
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 | |
|
64 | |
|
65 | |
public ListType getListType() { |
66 | 0 | return listType; |
67 | |
} |
68 | |
|
69 | |
|
70 | |
|
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 | |
} |