1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.student.common.ui.client.configurable.mvc.multiplicity;
20
21 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityConfiguration.StyleType;
22 import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection;
23 import org.kuali.student.common.ui.client.mvc.Callback;
24 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.BorderedHeadedLayout;
25 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.HeadedLayout;
26 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.UnborderedHeadedLayout;
27
28 import com.google.gwt.event.dom.client.ClickEvent;
29 import com.google.gwt.event.dom.client.ClickHandler;
30 import com.google.gwt.user.client.ui.Widget;
31
32 public class MultiplicityGroupItem extends BaseSection {
33
34 private boolean updateable=false;
35 private Integer itemKey;
36 private Widget itemWidget;
37 private Callback<MultiplicityGroupItem> removeCallback;
38 private boolean created = true;
39 private boolean deleted = false;
40 private boolean loaded = false;
41
42 private MultiplicityConfiguration.StyleType style;
43
44 String itemLabel;
45
46
47
48
49
50
51
52
53
54
55 public MultiplicityGroupItem(String itemLabel, StyleType style, boolean updateable){
56
57 this.itemLabel = itemLabel;
58 this.style = style;
59 this.updateable = updateable;
60 }
61
62 private void buildLayout() {
63
64 switch (style) {
65 case TOP_LEVEL_GROUP:
66 case BORDERED_TABLE:
67 layout = new BorderedHeadedLayout(itemLabel, updateable);
68 break;
69 case SUB_LEVEL_GROUP:
70 case BORDERLESS_TABLE:
71 layout = new UnborderedHeadedLayout(itemLabel, updateable);
72 break;
73 }
74 ((HeadedLayout)layout).setUpdateable(updateable);
75 }
76
77 public void redraw() {
78 if (!loaded){
79 buildLayout();
80
81 if(updateable){
82 ((HeadedLayout)layout).addDeleteHandler(new ClickHandler() {
83 public void onClick(ClickEvent event) {
84 getRemoveCallback().exec(MultiplicityGroupItem.this);
85 }
86 });
87 }
88
89 layout.addWidget(this.getItemWidget());
90 this.add(layout);
91 }
92 }
93 public Integer getItemKey() {
94 return itemKey;
95 }
96
97 public void setItemKey(Integer itemKey) {
98 this.itemKey = itemKey;
99 }
100
101 public Widget getItemWidget() {
102 return itemWidget;
103 }
104
105 public void setItemWidget(Widget itemWidget) {
106 this.itemWidget = itemWidget;
107 }
108
109 public void setRemoveCallback(Callback<MultiplicityGroupItem> callback){
110 removeCallback = callback;
111 }
112
113 public Callback<MultiplicityGroupItem> getRemoveCallback(){
114 return removeCallback;
115 }
116
117 public boolean isCreated() {
118 return created;
119 }
120
121 public void setCreated(boolean created) {
122 this.created = created;
123 }
124
125 public boolean isDeleted() {
126 return deleted;
127 }
128
129 public void setDeleted(boolean isDeleted) {
130 this.deleted = isDeleted;
131 if(isDeleted)
132 this.created = false;
133 }
134 }