| 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 | 0 | private boolean updateable=false; |
| 35 | |
private Integer itemKey; |
| 36 | |
private Widget itemWidget; |
| 37 | |
private Callback<MultiplicityGroupItem> removeCallback; |
| 38 | 0 | private boolean created = true; |
| 39 | 0 | private boolean deleted = false; |
| 40 | 0 | 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 | 0 | public MultiplicityGroupItem(String itemLabel, StyleType style, boolean updateable){ |
| 56 | |
|
| 57 | 0 | this.itemLabel = itemLabel; |
| 58 | 0 | this.style = style; |
| 59 | 0 | this.updateable = updateable; |
| 60 | 0 | } |
| 61 | |
|
| 62 | |
private void buildLayout() { |
| 63 | |
|
| 64 | 0 | switch (style) { |
| 65 | |
case TOP_LEVEL_GROUP: |
| 66 | |
case BORDERED_TABLE: |
| 67 | 0 | layout = new BorderedHeadedLayout(itemLabel, updateable); |
| 68 | 0 | break; |
| 69 | |
case SUB_LEVEL_GROUP: |
| 70 | |
case BORDERLESS_TABLE: |
| 71 | 0 | layout = new UnborderedHeadedLayout(itemLabel, updateable); |
| 72 | |
break; |
| 73 | |
} |
| 74 | 0 | ((HeadedLayout)layout).setUpdateable(updateable); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
public void redraw() { |
| 78 | 0 | if (!loaded){ |
| 79 | 0 | buildLayout(); |
| 80 | |
|
| 81 | 0 | if(updateable){ |
| 82 | 0 | ((HeadedLayout)layout).addDeleteHandler(new ClickHandler() { |
| 83 | |
public void onClick(ClickEvent event) { |
| 84 | 0 | getRemoveCallback().exec(MultiplicityGroupItem.this); |
| 85 | 0 | } |
| 86 | |
}); |
| 87 | |
} |
| 88 | |
|
| 89 | 0 | layout.addWidget(this.getItemWidget()); |
| 90 | 0 | this.add(layout); |
| 91 | |
} |
| 92 | 0 | } |
| 93 | |
public Integer getItemKey() { |
| 94 | 0 | return itemKey; |
| 95 | |
} |
| 96 | |
|
| 97 | |
public void setItemKey(Integer itemKey) { |
| 98 | 0 | this.itemKey = itemKey; |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
public Widget getItemWidget() { |
| 102 | 0 | return itemWidget; |
| 103 | |
} |
| 104 | |
|
| 105 | |
public void setItemWidget(Widget itemWidget) { |
| 106 | 0 | this.itemWidget = itemWidget; |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
public void setRemoveCallback(Callback<MultiplicityGroupItem> callback){ |
| 110 | 0 | removeCallback = callback; |
| 111 | 0 | } |
| 112 | |
|
| 113 | |
public Callback<MultiplicityGroupItem> getRemoveCallback(){ |
| 114 | 0 | return removeCallback; |
| 115 | |
} |
| 116 | |
|
| 117 | |
public boolean isCreated() { |
| 118 | 0 | return created; |
| 119 | |
} |
| 120 | |
|
| 121 | |
public void setCreated(boolean created) { |
| 122 | 0 | this.created = created; |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
public boolean isDeleted() { |
| 126 | 0 | return deleted; |
| 127 | |
} |
| 128 | |
|
| 129 | |
public void setDeleted(boolean isDeleted) { |
| 130 | 0 | this.deleted = isDeleted; |
| 131 | 0 | if(isDeleted) |
| 132 | 0 | this.created = false; |
| 133 | 0 | } |
| 134 | |
} |