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 | |
|
24 | |
|
25 | |
|
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 | |
|
63 | |
|
64 | |
public ListType getListType() { |
65 | 0 | return listType; |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
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 | |
} |