1 | |
package org.kuali.student.lum.lu.ui.tools.client.widgets.itemlist; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
7 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
8 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
9 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
10 | |
|
11 | |
import com.google.gwt.event.dom.client.ClickEvent; |
12 | |
import com.google.gwt.event.dom.client.ClickHandler; |
13 | |
import com.google.gwt.user.client.ui.Widget; |
14 | |
|
15 | 0 | public class CluRangeItemValue implements ItemValue<CluRangeItemValue> { |
16 | |
|
17 | |
private String id; |
18 | |
private String name; |
19 | |
private Callback<CluRangeItemValue> deleteCallback; |
20 | |
private boolean editable; |
21 | |
|
22 | |
@Override |
23 | |
public List<Widget> generateDisplayWidgets() { |
24 | 0 | List<Widget> displayWidgets = new ArrayList<Widget>(); |
25 | 0 | KSButton deleteButton = new KSButton("X", ButtonStyle.DELETE); |
26 | 0 | KSLabel itemLabel = new KSLabel(getName()); |
27 | |
|
28 | 0 | displayWidgets.add(itemLabel); |
29 | 0 | if (isEditable()) { |
30 | 0 | displayWidgets.add(deleteButton); |
31 | |
|
32 | 0 | if (deleteCallback != null) { |
33 | 0 | deleteButton.addClickHandler(new ClickHandler() { |
34 | |
@Override |
35 | |
public void onClick(ClickEvent event) { |
36 | 0 | deleteCallback.exec(CluRangeItemValue.this); |
37 | 0 | } |
38 | |
}); |
39 | |
} |
40 | |
} |
41 | 0 | return displayWidgets; |
42 | |
} |
43 | |
|
44 | |
public String getName() { |
45 | 0 | return name; |
46 | |
} |
47 | |
|
48 | |
public void setName(String name) { |
49 | 0 | this.name = name; |
50 | 0 | } |
51 | |
|
52 | |
@Override |
53 | |
public Callback<CluRangeItemValue> getDeleteCallback() { |
54 | 0 | return deleteCallback; |
55 | |
} |
56 | |
|
57 | |
@Override |
58 | |
public void setDeleteCallback(Callback<CluRangeItemValue> deleteCallback) { |
59 | 0 | this.deleteCallback = deleteCallback; |
60 | 0 | } |
61 | |
|
62 | |
@Override |
63 | |
public String getId() { |
64 | 0 | return id; |
65 | |
} |
66 | |
|
67 | |
@Override |
68 | |
public void setId(String id) { |
69 | 0 | this.id = id; |
70 | 0 | } |
71 | |
|
72 | |
@Override |
73 | |
public boolean isEditable() { |
74 | 0 | return editable; |
75 | |
} |
76 | |
|
77 | |
@Override |
78 | |
public void setEditable(boolean editable) { |
79 | 0 | this.editable = editable; |
80 | 0 | } |
81 | |
|
82 | |
@Override |
83 | |
public boolean equals(Object obj) { |
84 | 0 | if (this == obj) |
85 | 0 | return true; |
86 | 0 | if (obj == null) |
87 | 0 | return false; |
88 | 0 | if (getClass() != obj.getClass()) |
89 | 0 | return false; |
90 | 0 | CluRangeItemValue other = (CluRangeItemValue) obj; |
91 | 0 | if (id == null) { |
92 | 0 | if (other.id != null) |
93 | 0 | return false; |
94 | 0 | } else if (!id.equals(other.id)) |
95 | 0 | return false; |
96 | 0 | if (name == null) { |
97 | 0 | if (other.name != null) |
98 | 0 | return false; |
99 | 0 | } else if (!name.equals(other.name)) |
100 | 0 | return false; |
101 | 0 | return true; |
102 | |
} |
103 | |
|
104 | |
@Override |
105 | |
public int hashCode() { |
106 | 0 | final int prime = 31; |
107 | 0 | int result = 1; |
108 | 0 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
109 | 0 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
110 | 0 | return result; |
111 | |
} |
112 | |
|
113 | |
} |