| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.common.ui.client.widgets.field.layout.layouts; |
| 17 | |
|
| 18 | |
import java.util.HashMap; |
| 19 | |
import java.util.Iterator; |
| 20 | |
import java.util.LinkedHashMap; |
| 21 | |
import java.util.Map; |
| 22 | |
|
| 23 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
| 24 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.WarnContainer; |
| 25 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout; |
| 26 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrButton; |
| 27 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; |
| 28 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; |
| 29 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrButton.AbbrButtonType; |
| 30 | |
import org.kuali.student.core.validation.dto.ValidationResultInfo; |
| 31 | |
|
| 32 | |
import com.google.gwt.user.client.ui.FlowPanel; |
| 33 | |
import com.google.gwt.user.client.ui.HTML; |
| 34 | |
import com.google.gwt.user.client.ui.Widget; |
| 35 | |
|
| 36 | 0 | public abstract class FieldLayout extends FlowPanel implements FieldLayoutComponent{ |
| 37 | 0 | protected Map<String, FieldElement> fieldMap = new HashMap<String, FieldElement>(); |
| 38 | 0 | protected Map<String, FieldLayout> layoutMap = new HashMap<String, FieldLayout>(); |
| 39 | 0 | protected LinkedHashMap<String, Widget> drawOrder = new LinkedHashMap<String, Widget>(); |
| 40 | 0 | protected SpanPanel instructions = new SpanPanel(); |
| 41 | 0 | protected WarnContainer message = new WarnContainer(false); |
| 42 | |
protected FieldLayout parentLayout; |
| 43 | 0 | protected boolean hasValidation = false; |
| 44 | |
private HTML messagePanel; |
| 45 | 0 | private static int generatedKeyNum = 0; |
| 46 | |
private String key; |
| 47 | |
private ButtonLayout buttonLayout; |
| 48 | 0 | protected SectionTitle layoutTitle = null; |
| 49 | 0 | private AbbrButton help = null; |
| 50 | |
|
| 51 | |
|
| 52 | |
private static String getNextId() { |
| 53 | 0 | return "fieldComponent" + (generatedKeyNum++); |
| 54 | |
} |
| 55 | |
|
| 56 | |
public void underlineTitle(boolean underline){ |
| 57 | 0 | if(layoutTitle != null){ |
| 58 | 0 | if(underline){ |
| 59 | 0 | layoutTitle.addStyleName("header-underline"); |
| 60 | |
} |
| 61 | |
else{ |
| 62 | 0 | layoutTitle.removeStyleName("header-underline"); |
| 63 | |
} |
| 64 | |
} |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
public FieldLayout getParentLayout() { |
| 68 | 0 | return parentLayout; |
| 69 | |
} |
| 70 | |
|
| 71 | |
protected void setParentLayout(FieldLayout parentLayout) { |
| 72 | 0 | this.parentLayout = parentLayout; |
| 73 | 0 | } |
| 74 | |
|
| 75 | |
public String addField(FieldElement field){ |
| 76 | 0 | String key = null; |
| 77 | 0 | if(field != null){ |
| 78 | 0 | if(field.getKey() == null){ |
| 79 | 0 | key = getNextId(); |
| 80 | 0 | field.setKey(key); |
| 81 | |
} |
| 82 | |
else{ |
| 83 | 0 | key = field.getKey(); |
| 84 | |
} |
| 85 | 0 | fieldMap.put(key, field); |
| 86 | 0 | drawOrder.put(key, field); |
| 87 | 0 | addFieldToLayout(field); |
| 88 | |
} |
| 89 | 0 | return key; |
| 90 | |
} |
| 91 | |
|
| 92 | |
public String addLayout(FieldLayout layout){ |
| 93 | 0 | String key = null; |
| 94 | 0 | if(layout != null){ |
| 95 | 0 | if(layout.getKey() == null){ |
| 96 | 0 | key = getNextId(); |
| 97 | 0 | layout.setKey(key); |
| 98 | |
} |
| 99 | |
else{ |
| 100 | 0 | key = layout.getKey(); |
| 101 | |
} |
| 102 | 0 | layoutMap.put(key, layout); |
| 103 | 0 | drawOrder.put(key, layout); |
| 104 | 0 | addLayoutToLayout(layout); |
| 105 | |
} |
| 106 | 0 | return key; |
| 107 | |
} |
| 108 | |
|
| 109 | |
public String addWidget(Widget widget){ |
| 110 | 0 | return this.addWidget(null, widget); |
| 111 | |
} |
| 112 | |
|
| 113 | |
public String addWidget(String key, Widget widget){ |
| 114 | 0 | if(widget != null){ |
| 115 | 0 | if(key == null){ |
| 116 | 0 | key = getNextId(); |
| 117 | |
} |
| 118 | 0 | drawOrder.put(key, widget); |
| 119 | 0 | addWidgetToLayout(widget); |
| 120 | |
} |
| 121 | |
else{ |
| 122 | 0 | key = null; |
| 123 | |
} |
| 124 | 0 | return key; |
| 125 | |
} |
| 126 | |
|
| 127 | |
public boolean removeLayoutElement(String key){ |
| 128 | 0 | Widget w = drawOrder.get(key); |
| 129 | 0 | if(w != null){ |
| 130 | |
|
| 131 | 0 | fieldMap.remove(key); |
| 132 | 0 | layoutMap.remove(key); |
| 133 | 0 | drawOrder.remove(key); |
| 134 | 0 | if(w instanceof FieldLayoutComponent){ |
| 135 | 0 | removeFieldLayoutComponentFromLayout((FieldLayoutComponent)w); |
| 136 | |
} |
| 137 | |
else{ |
| 138 | 0 | removeWidgetFromLayout(w); |
| 139 | |
} |
| 140 | 0 | return true; |
| 141 | |
} |
| 142 | |
else{ |
| 143 | 0 | return false; |
| 144 | |
} |
| 145 | |
} |
| 146 | |
|
| 147 | |
public boolean removeLayoutElement(Widget widget){ |
| 148 | 0 | if(drawOrder.containsValue(widget)){ |
| 149 | 0 | Iterator<String> it = drawOrder.keySet().iterator(); |
| 150 | 0 | String matchedKey = null; |
| 151 | 0 | while(it.hasNext()){ |
| 152 | 0 | String key = it.next(); |
| 153 | 0 | Widget w = drawOrder.get(key); |
| 154 | 0 | if(w.equals(widget)){ |
| 155 | 0 | matchedKey = key; |
| 156 | 0 | break; |
| 157 | |
} |
| 158 | 0 | } |
| 159 | 0 | fieldMap.remove(matchedKey); |
| 160 | 0 | layoutMap.remove(matchedKey); |
| 161 | 0 | drawOrder.remove(matchedKey); |
| 162 | 0 | if(widget instanceof FieldLayoutComponent){ |
| 163 | 0 | removeFieldLayoutComponentFromLayout((FieldLayoutComponent)widget); |
| 164 | |
} |
| 165 | |
else{ |
| 166 | 0 | removeWidgetFromLayout(widget); |
| 167 | |
} |
| 168 | 0 | return true; |
| 169 | |
} |
| 170 | |
else{ |
| 171 | 0 | return false; |
| 172 | |
} |
| 173 | |
} |
| 174 | |
|
| 175 | |
public void setInstructions(String instructions) { |
| 176 | 0 | if(instructions != null && !instructions.equals("")){ |
| 177 | 0 | this.instructions.addStyleName("ks-section-instuctions"); |
| 178 | 0 | this.instructions.setHTML(instructions); |
| 179 | 0 | this.instructions.setVisible(true); |
| 180 | |
} |
| 181 | |
else{ |
| 182 | 0 | this.instructions.setVisible(false); |
| 183 | |
} |
| 184 | 0 | } |
| 185 | |
|
| 186 | |
public void setMessage(String html, boolean show) { |
| 187 | 0 | if(messagePanel == null){ |
| 188 | 0 | messagePanel = new HTML(html); |
| 189 | 0 | message.addWarnWidget(messagePanel); |
| 190 | |
} |
| 191 | |
else{ |
| 192 | 0 | messagePanel.setHTML(html); |
| 193 | |
} |
| 194 | 0 | message.setVisible(show); |
| 195 | 0 | message.showWarningLayout(show); |
| 196 | 0 | } |
| 197 | |
|
| 198 | |
public void showMessage(boolean show) { |
| 199 | 0 | message.setVisible(show); |
| 200 | 0 | message.showWarningLayout(show); |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
public WarnContainer getMessageWarnContainer(){ |
| 204 | 0 | return message; |
| 205 | |
} |
| 206 | |
|
| 207 | |
@Override |
| 208 | |
public String getKey() { |
| 209 | 0 | return key; |
| 210 | |
} |
| 211 | |
|
| 212 | |
@Override |
| 213 | |
public void setKey(String layoutKey) { |
| 214 | 0 | key = layoutKey; |
| 215 | 0 | } |
| 216 | |
|
| 217 | |
public FieldElement getFieldElement(String key){ |
| 218 | 0 | return fieldMap.get(key); |
| 219 | |
} |
| 220 | |
|
| 221 | |
public FieldLayout getFieldLayout(String key){ |
| 222 | 0 | return layoutMap.get(key); |
| 223 | |
} |
| 224 | |
|
| 225 | |
public Widget getWidget(String key){ |
| 226 | 0 | return drawOrder.get(key); |
| 227 | |
} |
| 228 | |
|
| 229 | |
public abstract void addFieldToLayout(FieldElement field); |
| 230 | |
public abstract void addLayoutToLayout(FieldLayout layout); |
| 231 | |
public abstract void addWidgetToLayout(Widget widget); |
| 232 | |
public abstract void removeWidgetFromLayout(Widget widget); |
| 233 | |
public abstract void removeFieldLayoutComponentFromLayout(FieldLayoutComponent component); |
| 234 | |
|
| 235 | |
public void processValidationResults(String fieldElementKey, ValidationResultInfo validationResult){ |
| 236 | 0 | FieldElement field = fieldMap.get(fieldElementKey); |
| 237 | 0 | if(field != null && hasValidation){ |
| 238 | 0 | field.processValidationResult(validationResult); |
| 239 | |
} |
| 240 | 0 | } |
| 241 | |
|
| 242 | |
public void addValidationErrorMessage(String fieldElementKey, String message){ |
| 243 | 0 | FieldElement field = fieldMap.get(fieldElementKey); |
| 244 | 0 | if(field != null && hasValidation){ |
| 245 | 0 | field.addValidationErrorMessage(message); |
| 246 | |
} |
| 247 | 0 | } |
| 248 | |
|
| 249 | |
public void clearValidation(){ |
| 250 | |
|
| 251 | 0 | for(FieldElement e: fieldMap.values()){ |
| 252 | 0 | e.clearValidationPanel(); |
| 253 | |
} |
| 254 | 0 | for(FieldLayout layout: layoutMap.values()){ |
| 255 | 0 | layout.clearValidation(); |
| 256 | |
} |
| 257 | 0 | } |
| 258 | |
|
| 259 | |
|
| 260 | |
public abstract void setLayoutTitle(SectionTitle layoutTitle); |
| 261 | |
|
| 262 | |
public SectionTitle getLayoutTitle() { |
| 263 | 0 | return layoutTitle; |
| 264 | |
} |
| 265 | |
|
| 266 | |
public void addButtonLayout(ButtonLayout buttonLayout){ |
| 267 | 0 | this.buttonLayout = buttonLayout; |
| 268 | 0 | addButtonLayoutToLayout(buttonLayout); |
| 269 | 0 | } |
| 270 | |
|
| 271 | |
public ButtonLayout getButtonLayout(){ |
| 272 | 0 | return buttonLayout; |
| 273 | |
} |
| 274 | |
|
| 275 | |
public abstract void addButtonLayoutToLayout(ButtonLayout buttonLayout); |
| 276 | |
|
| 277 | |
public void setHelp(String html){ |
| 278 | 0 | if(layoutTitle != null){ |
| 279 | 0 | if(help == null){ |
| 280 | 0 | help = new AbbrButton(AbbrButtonType.HELP); |
| 281 | 0 | layoutTitle.add(help); |
| 282 | |
} |
| 283 | |
|
| 284 | 0 | if(html != null && !html.trim().equals("")){ |
| 285 | 0 | help.setVisible(true); |
| 286 | 0 | help.setHoverHTML(html); |
| 287 | |
} |
| 288 | |
else{ |
| 289 | 0 | help.setVisible(false); |
| 290 | |
} |
| 291 | |
|
| 292 | |
|
| 293 | |
} |
| 294 | 0 | } |
| 295 | |
|
| 296 | |
} |