| 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.AbbrButton.AbbrButtonType; | 
  | 28 |  |  import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrPanel; | 
  | 29 |  |  import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; | 
  | 30 |  |  import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; | 
  | 31 |  |  import org.kuali.student.core.validation.dto.ValidationResultInfo; | 
  | 32 |  |   | 
  | 33 |  |  import com.google.gwt.user.client.ui.FlowPanel; | 
  | 34 |  |  import com.google.gwt.user.client.ui.HTML; | 
  | 35 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 36 |  |   | 
  | 37 |  |   | 
  | 38 |  |   | 
  | 39 |  |   | 
  | 40 |  |   | 
  | 41 |  |   | 
  | 42 |  |   | 
  | 43 |  |   | 
  | 44 | 0 |  public abstract class FieldLayout extends FlowPanel implements FieldLayoutComponent{ | 
  | 45 | 0 |          protected Map<String, FieldElement> fieldMap = new HashMap<String, FieldElement>(); | 
  | 46 | 0 |          protected Map<String, FieldLayout> layoutMap = new HashMap<String, FieldLayout>(); | 
  | 47 | 0 |          protected LinkedHashMap<String, Widget> drawOrder = new LinkedHashMap<String, Widget>(); | 
  | 48 | 0 |          protected SpanPanel instructions = new SpanPanel(); | 
  | 49 | 0 |          protected WarnContainer message = new WarnContainer(false); | 
  | 50 |  |          protected FieldLayout parentLayout; | 
  | 51 | 0 |          protected boolean hasValidation = false; | 
  | 52 |  |          private HTML messagePanel; | 
  | 53 | 0 |          private static int generatedKeyNum = 0; | 
  | 54 |  |          private String key; | 
  | 55 |  |          private ButtonLayout buttonLayout; | 
  | 56 | 0 |          protected SectionTitle layoutTitle = null; | 
  | 57 | 0 |          private AbbrButton help = null; | 
  | 58 |  |   | 
  | 59 |  |   | 
  | 60 |  |          private static String getNextId() { | 
  | 61 | 0 |                  return "fieldComponent" + (generatedKeyNum++); | 
  | 62 |  |          } | 
  | 63 |  |   | 
  | 64 |  |           | 
  | 65 |  |   | 
  | 66 |  |   | 
  | 67 |  |   | 
  | 68 |  |          public void underlineTitle(boolean underline){ | 
  | 69 | 0 |                  if(layoutTitle != null){ | 
  | 70 | 0 |                          if(underline){ | 
  | 71 | 0 |                                  layoutTitle.addStyleName("header-underline"); | 
  | 72 |  |                          } | 
  | 73 |  |                          else{ | 
  | 74 | 0 |                                  layoutTitle.removeStyleName("header-underline"); | 
  | 75 |  |                          } | 
  | 76 |  |                  } | 
  | 77 | 0 |          } | 
  | 78 |  |   | 
  | 79 |  |          public FieldLayout getParentLayout() { | 
  | 80 | 0 |                  return parentLayout; | 
  | 81 |  |          } | 
  | 82 |  |   | 
  | 83 |  |          protected void setParentLayout(FieldLayout parentLayout) { | 
  | 84 | 0 |                  this.parentLayout = parentLayout; | 
  | 85 | 0 |          } | 
  | 86 |  |   | 
  | 87 |  |           | 
  | 88 |  |   | 
  | 89 |  |   | 
  | 90 |  |   | 
  | 91 |  |   | 
  | 92 |  |   | 
  | 93 |  |          public String addField(FieldElement field){ | 
  | 94 | 0 |                  String key = null; | 
  | 95 | 0 |                  if(field != null){ | 
  | 96 | 0 |                          if(field.getKey() == null){ | 
  | 97 | 0 |                                  key = getNextId(); | 
  | 98 | 0 |                                  field.setKey(key); | 
  | 99 |  |                          } | 
  | 100 |  |                          else{ | 
  | 101 | 0 |                                  key = field.getKey(); | 
  | 102 |  |                          } | 
  | 103 | 0 |                          fieldMap.put(key, field); | 
  | 104 | 0 |                          drawOrder.put(key, field); | 
  | 105 | 0 |                          addFieldToLayout(field); | 
  | 106 |  |                  } | 
  | 107 | 0 |                  return key; | 
  | 108 |  |          } | 
  | 109 |  |   | 
  | 110 |  |           | 
  | 111 |  |   | 
  | 112 |  |   | 
  | 113 |  |   | 
  | 114 |  |   | 
  | 115 |  |   | 
  | 116 |  |          public String addLayout(FieldLayout layout){ | 
  | 117 | 0 |                  String key = null; | 
  | 118 | 0 |                  if(layout != null){ | 
  | 119 | 0 |                          if(layout.getKey() == null){ | 
  | 120 | 0 |                                  key = getNextId(); | 
  | 121 | 0 |                                  layout.setKey(key); | 
  | 122 |  |                          } | 
  | 123 |  |                          else{ | 
  | 124 | 0 |                                  key = layout.getKey(); | 
  | 125 |  |                          } | 
  | 126 | 0 |                          layoutMap.put(key, layout); | 
  | 127 | 0 |                          drawOrder.put(key, layout); | 
  | 128 | 0 |                          addLayoutToLayout(layout); | 
  | 129 |  |                  } | 
  | 130 | 0 |                  return key; | 
  | 131 |  |          } | 
  | 132 |  |   | 
  | 133 |  |           | 
  | 134 |  |   | 
  | 135 |  |   | 
  | 136 |  |   | 
  | 137 |  |   | 
  | 138 |  |          public String addWidget(Widget widget){ | 
  | 139 | 0 |                  return this.addWidget(null, widget); | 
  | 140 |  |          } | 
  | 141 |  |   | 
  | 142 |  |           | 
  | 143 |  |   | 
  | 144 |  |   | 
  | 145 |  |   | 
  | 146 |  |   | 
  | 147 |  |   | 
  | 148 |  |          public String addWidget(String key, Widget widget){ | 
  | 149 | 0 |                  if(widget != null){ | 
  | 150 | 0 |                          if(key == null){ | 
  | 151 | 0 |                                  key = getNextId(); | 
  | 152 |  |                          } | 
  | 153 | 0 |                          drawOrder.put(key, widget); | 
  | 154 | 0 |                          addWidgetToLayout(widget); | 
  | 155 |  |                  } | 
  | 156 |  |                  else{ | 
  | 157 | 0 |                          key = null; | 
  | 158 |  |                  } | 
  | 159 | 0 |                  return key; | 
  | 160 |  |          } | 
  | 161 |  |   | 
  | 162 |  |           | 
  | 163 |  |   | 
  | 164 |  |   | 
  | 165 |  |   | 
  | 166 |  |   | 
  | 167 |  |          public boolean removeLayoutElement(String key){ | 
  | 168 | 0 |                  Widget w = drawOrder.get(key); | 
  | 169 | 0 |                  if(w != null){ | 
  | 170 |  |                           | 
  | 171 | 0 |                          fieldMap.remove(key); | 
  | 172 | 0 |                          layoutMap.remove(key); | 
  | 173 | 0 |                          drawOrder.remove(key); | 
  | 174 | 0 |                          if(w instanceof FieldLayoutComponent){ | 
  | 175 | 0 |                                  removeFieldLayoutComponentFromLayout((FieldLayoutComponent)w); | 
  | 176 |  |                          } | 
  | 177 |  |                          else{ | 
  | 178 | 0 |                                  removeWidgetFromLayout(w); | 
  | 179 |  |                          } | 
  | 180 | 0 |                          return true; | 
  | 181 |  |                  } | 
  | 182 |  |                  else{ | 
  | 183 | 0 |                          return false; | 
  | 184 |  |                  } | 
  | 185 |  |          } | 
  | 186 |  |   | 
  | 187 |  |           | 
  | 188 |  |   | 
  | 189 |  |   | 
  | 190 |  |   | 
  | 191 |  |   | 
  | 192 |  |          public boolean removeLayoutElement(Widget widget){ | 
  | 193 | 0 |                  if(drawOrder.containsValue(widget)){ | 
  | 194 | 0 |                          Iterator<String> it = drawOrder.keySet().iterator(); | 
  | 195 | 0 |                          String matchedKey = null; | 
  | 196 | 0 |                          while(it.hasNext()){ | 
  | 197 | 0 |                                  String key = it.next(); | 
  | 198 | 0 |                                  Widget w = drawOrder.get(key); | 
  | 199 | 0 |                                  if(w.equals(widget)){ | 
  | 200 | 0 |                                          matchedKey = key; | 
  | 201 | 0 |                                          break; | 
  | 202 |  |                                  } | 
  | 203 | 0 |                          } | 
  | 204 | 0 |                          fieldMap.remove(matchedKey); | 
  | 205 | 0 |                          layoutMap.remove(matchedKey); | 
  | 206 | 0 |                          drawOrder.remove(matchedKey); | 
  | 207 | 0 |                          if(widget instanceof FieldLayoutComponent){ | 
  | 208 | 0 |                                  removeFieldLayoutComponentFromLayout((FieldLayoutComponent)widget); | 
  | 209 |  |                          } | 
  | 210 |  |                          else{ | 
  | 211 | 0 |                                  removeWidgetFromLayout(widget); | 
  | 212 |  |                          } | 
  | 213 | 0 |                          return true; | 
  | 214 |  |                  } | 
  | 215 |  |                  else{ | 
  | 216 | 0 |                          return false; | 
  | 217 |  |                  } | 
  | 218 |  |          } | 
  | 219 |  |   | 
  | 220 |  |           | 
  | 221 |  |   | 
  | 222 |  |   | 
  | 223 |  |   | 
  | 224 |  |   | 
  | 225 |  |          public void setInstructions(String instructions) { | 
  | 226 | 0 |                  if(instructions != null && !instructions.equals("")){ | 
  | 227 | 0 |                          this.instructions.addStyleName("ks-section-instuctions"); | 
  | 228 | 0 |                          this.instructions.setHTML(instructions); | 
  | 229 | 0 |                          this.instructions.setVisible(true); | 
  | 230 |  |                  } | 
  | 231 |  |                  else{ | 
  | 232 | 0 |                          this.instructions.setVisible(false); | 
  | 233 |  |                  } | 
  | 234 | 0 |          } | 
  | 235 |  |   | 
  | 236 |  |           | 
  | 237 |  |   | 
  | 238 |  |   | 
  | 239 |  |   | 
  | 240 |  |   | 
  | 241 |  |   | 
  | 242 |  |          public void setMessage(String html, boolean show) { | 
  | 243 | 0 |                  if(messagePanel == null){ | 
  | 244 | 0 |                          messagePanel = new HTML(html); | 
  | 245 | 0 |                          message.addWarnWidget(messagePanel); | 
  | 246 |  |                  } | 
  | 247 |  |                  else{ | 
  | 248 | 0 |                          messagePanel.setHTML(html); | 
  | 249 |  |                  } | 
  | 250 | 0 |                  message.setVisible(show); | 
  | 251 | 0 |                  message.showWarningLayout(show); | 
  | 252 | 0 |          } | 
  | 253 |  |   | 
  | 254 |  |          public void showMessage(boolean show) { | 
  | 255 | 0 |                  message.setVisible(show); | 
  | 256 | 0 |                  message.showWarningLayout(show); | 
  | 257 | 0 |          } | 
  | 258 |  |           | 
  | 259 |  |          public WarnContainer getMessageWarnContainer(){ | 
  | 260 | 0 |                  return message; | 
  | 261 |  |          } | 
  | 262 |  |   | 
  | 263 |  |          @Override | 
  | 264 |  |          public String getKey() { | 
  | 265 | 0 |                  return key; | 
  | 266 |  |          } | 
  | 267 |  |   | 
  | 268 |  |          @Override | 
  | 269 |  |          public void setKey(String layoutKey) { | 
  | 270 | 0 |                  key = layoutKey; | 
  | 271 | 0 |          } | 
  | 272 |  |   | 
  | 273 |  |          public FieldElement getFieldElement(String key){ | 
  | 274 | 0 |                  return fieldMap.get(key); | 
  | 275 |  |          } | 
  | 276 |  |   | 
  | 277 |  |          public FieldLayout getFieldLayout(String key){ | 
  | 278 | 0 |                  return layoutMap.get(key); | 
  | 279 |  |          } | 
  | 280 |  |   | 
  | 281 |  |          public Widget getWidget(String key){ | 
  | 282 | 0 |                  return drawOrder.get(key); | 
  | 283 |  |          } | 
  | 284 |  |   | 
  | 285 |  |          public abstract void addFieldToLayout(FieldElement field); | 
  | 286 |  |          public abstract void addLayoutToLayout(FieldLayout layout); | 
  | 287 |  |          public abstract void addWidgetToLayout(Widget widget); | 
  | 288 |  |          public abstract void removeWidgetFromLayout(Widget widget); | 
  | 289 |  |          public abstract void removeFieldLayoutComponentFromLayout(FieldLayoutComponent component); | 
  | 290 |  |   | 
  | 291 |  |           | 
  | 292 |  |   | 
  | 293 |  |   | 
  | 294 |  |   | 
  | 295 |  |   | 
  | 296 |  |   | 
  | 297 |  |          public void processValidationResults(String fieldElementKey, ValidationResultInfo validationResult){ | 
  | 298 | 0 |                  FieldElement field = fieldMap.get(fieldElementKey); | 
  | 299 | 0 |                  if(field != null && hasValidation){ | 
  | 300 | 0 |                          field.processValidationResult(validationResult); | 
  | 301 |  |                  } | 
  | 302 | 0 |          } | 
  | 303 |  |   | 
  | 304 |  |          public void addValidationErrorMessage(String fieldElementKey, String message){ | 
  | 305 | 0 |                  FieldElement field = fieldMap.get(fieldElementKey); | 
  | 306 | 0 |                  if(field != null && hasValidation){ | 
  | 307 | 0 |                          field.addValidationErrorMessage(message); | 
  | 308 |  |                  } | 
  | 309 | 0 |          } | 
  | 310 |  |   | 
  | 311 |  |           | 
  | 312 |  |   | 
  | 313 |  |   | 
  | 314 |  |          public void clearValidation(){ | 
  | 315 |  |                   | 
  | 316 | 0 |                  for(FieldElement e: fieldMap.values()){ | 
  | 317 | 0 |                          e.clearValidationPanel(); | 
  | 318 |  |                  } | 
  | 319 | 0 |                  for(FieldLayout layout: layoutMap.values()){ | 
  | 320 | 0 |                          layout.clearValidation(); | 
  | 321 |  |                  } | 
  | 322 | 0 |          } | 
  | 323 |  |           | 
  | 324 |  |   | 
  | 325 |  |          public abstract void setLayoutTitle(SectionTitle layoutTitle); | 
  | 326 |  |   | 
  | 327 |  |          public SectionTitle getLayoutTitle() { | 
  | 328 | 0 |                  return layoutTitle; | 
  | 329 |  |          } | 
  | 330 |  |   | 
  | 331 |  |           | 
  | 332 |  |   | 
  | 333 |  |   | 
  | 334 |  |   | 
  | 335 |  |          public void addButtonLayout(ButtonLayout buttonLayout){ | 
  | 336 | 0 |                  this.buttonLayout = buttonLayout; | 
  | 337 | 0 |                  addButtonLayoutToLayout(buttonLayout); | 
  | 338 | 0 |          } | 
  | 339 |  |   | 
  | 340 |  |          public ButtonLayout getButtonLayout(){ | 
  | 341 | 0 |                  return buttonLayout; | 
  | 342 |  |          } | 
  | 343 |  |   | 
  | 344 |  |          public abstract void addButtonLayoutToLayout(ButtonLayout buttonLayout); | 
  | 345 |  |           | 
  | 346 |  |           | 
  | 347 |  |   | 
  | 348 |  |   | 
  | 349 |  |   | 
  | 350 |  |   | 
  | 351 |  |          public void setHelp(String html){ | 
  | 352 | 0 |                  if(layoutTitle != null){ | 
  | 353 | 0 |                          if(help == null){ | 
  | 354 | 0 |                                  help = new AbbrButton(AbbrButtonType.HELP); | 
  | 355 | 0 |                                  layoutTitle.add(help); | 
  | 356 |  |                          } | 
  | 357 |  |                           | 
  | 358 | 0 |                      if(html != null && !html.trim().equals("")){ | 
  | 359 | 0 |                              help.setVisible(true); | 
  | 360 | 0 |                              help.setHoverHTML(html); | 
  | 361 |  |                      } | 
  | 362 |  |                      else{ | 
  | 363 | 0 |                              help.setVisible(false); | 
  | 364 |  |                      } | 
  | 365 |  |                       | 
  | 366 |  |                       | 
  | 367 |  |                  } | 
  | 368 | 0 |          } | 
  | 369 |  |           | 
  | 370 |  |          public void setRequired(AbbrPanel required){ | 
  | 371 | 0 |                  if(layoutTitle != null && required != null){ | 
  | 372 | 0 |                          layoutTitle.add(required); | 
  | 373 |  |                  } | 
  | 374 | 0 |          } | 
  | 375 |  |   | 
  | 376 |  |  } |