| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.common.ui.client.configurable.mvc.sections; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.HashSet; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import org.kuali.student.common.assembly.data.Data; |
| 23 | |
import org.kuali.student.common.assembly.data.Data.Key; |
| 24 | |
import org.kuali.student.common.assembly.data.QueryPath; |
| 25 | |
import org.kuali.student.common.ui.client.application.Application; |
| 26 | |
import org.kuali.student.common.ui.client.configurable.mvc.CanProcessValidationResults; |
| 27 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
| 28 | |
import org.kuali.student.common.ui.client.configurable.mvc.LayoutController; |
| 29 | |
import org.kuali.student.common.ui.client.configurable.mvc.ValidationEventBinding; |
| 30 | |
import org.kuali.student.common.ui.client.configurable.mvc.ValidationEventBindingImpl; |
| 31 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding; |
| 32 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport; |
| 33 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite; |
| 34 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroup; |
| 35 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroupItem; |
| 36 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem; |
| 37 | |
import org.kuali.student.common.ui.client.event.ContentDirtyEvent; |
| 38 | |
import org.kuali.student.common.ui.client.event.ValidateRequestEvent; |
| 39 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
| 40 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
| 41 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 42 | |
import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; |
| 43 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
| 44 | |
import org.kuali.student.common.ui.client.mvc.View; |
| 45 | |
import org.kuali.student.common.ui.client.widgets.KSDropDown; |
| 46 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrPanel; |
| 47 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; |
| 48 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; |
| 49 | |
import org.kuali.student.common.ui.client.widgets.field.layout.layouts.FieldLayout; |
| 50 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
| 51 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
| 52 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel; |
| 53 | |
|
| 54 | |
import com.google.gwt.core.client.GWT; |
| 55 | |
import com.google.gwt.user.client.ui.TextBoxBase; |
| 56 | |
import com.google.gwt.user.client.ui.Widget; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | 0 | public abstract class BaseSection extends SpanPanel implements Section{ |
| 64 | |
|
| 65 | |
protected FieldLayout layout; |
| 66 | |
|
| 67 | 0 | protected ArrayList<Section> sections = new ArrayList<Section>(); |
| 68 | 0 | protected ArrayList<FieldDescriptor> fields = new ArrayList<FieldDescriptor>(); |
| 69 | 0 | protected LayoutController layoutController = null; |
| 70 | 0 | protected boolean isValidationEnabled = true; |
| 71 | 0 | protected boolean isDirty = false; |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
@Override |
| 86 | |
public String addField(final FieldDescriptor fieldDescriptor) { |
| 87 | 0 | String key = null; |
| 88 | |
|
| 89 | 0 | if (fieldDescriptor.isVisible()){ |
| 90 | 0 | fields.add(fieldDescriptor); |
| 91 | 0 | key = layout.addField(fieldDescriptor.getFieldElement()); |
| 92 | |
|
| 93 | 0 | ValidationEventBinding binding = new ValidationEventBindingImpl(); |
| 94 | 0 | if(fieldDescriptor.getValidationRequestCallback()== null){ |
| 95 | 0 | fieldDescriptor.setValidationCallBack(new Callback<Boolean>() { |
| 96 | |
@Override |
| 97 | |
public void exec(Boolean result) { |
| 98 | 0 | final ModelWidgetBinding mwb = fieldDescriptor.getModelWidgetBinding(); |
| 99 | 0 | if (mwb != null) { |
| 100 | 0 | final Widget w = fieldDescriptor.getFieldWidget(); |
| 101 | 0 | final String modelId = fieldDescriptor.getModelId(); |
| 102 | |
final Controller parent; |
| 103 | 0 | Controller findResult = LayoutController.findParentLayout(w); |
| 104 | 0 | if(BaseSection.this instanceof View){ |
| 105 | 0 | findResult = ((View)BaseSection.this).getController(); |
| 106 | |
} |
| 107 | 0 | parent = findResult; |
| 108 | 0 | if(parent != null){ |
| 109 | 0 | if (modelId == null) { |
| 110 | 0 | parent.requestModel(new ModelRequestCallback<DataModel>() { |
| 111 | |
|
| 112 | |
@Override |
| 113 | |
public void onModelReady(DataModel model) { |
| 114 | 0 | validateField(fieldDescriptor, model, parent); |
| 115 | |
|
| 116 | |
|
| 117 | 0 | HashSet<HasCrossConstraints> fds = Application.getApplicationContext().getCrossConstraint(null, Application.getApplicationContext().getParentPath()+fieldDescriptor.getFieldKey()); |
| 118 | 0 | if(fds!=null){ |
| 119 | 0 | for(HasCrossConstraints fd:fds){ |
| 120 | 0 | fd.reprocessWithUpdatedConstraints(); |
| 121 | |
} |
| 122 | |
} |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
@Override |
| 126 | |
public void onRequestFail(Throwable cause) { |
| 127 | 0 | GWT.log("Unable to retrieve model to validate " + fieldDescriptor.getFieldKey(), null); |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
}); |
| 131 | |
} else { |
| 132 | 0 | parent.requestModel(modelId, new ModelRequestCallback<DataModel>() { |
| 133 | |
|
| 134 | |
@Override |
| 135 | |
public void onModelReady(DataModel model) { |
| 136 | 0 | validateField(fieldDescriptor, model, parent); |
| 137 | 0 | } |
| 138 | |
|
| 139 | |
@Override |
| 140 | |
public void onRequestFail(Throwable cause) { |
| 141 | 0 | GWT.log("Unable to retrieve model to validate " + fieldDescriptor.getFieldKey(), null); |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
}); } |
| 145 | |
} |
| 146 | 0 | } else { |
| 147 | 0 | GWT.log(fieldDescriptor.getFieldKey() + " has no widget binding.", null); |
| 148 | |
} |
| 149 | 0 | } |
| 150 | |
}); |
| 151 | |
} |
| 152 | 0 | binding.bind(fieldDescriptor); |
| 153 | |
} |
| 154 | |
|
| 155 | 0 | return key; |
| 156 | |
} |
| 157 | |
|
| 158 | |
private void validateField( |
| 159 | |
final FieldDescriptor fieldDescriptor, final DataModel model, Controller controller) { |
| 160 | 0 | Widget w = fieldDescriptor.getFieldWidget(); |
| 161 | 0 | ModelWidgetBinding mwb = fieldDescriptor.getModelWidgetBinding(); |
| 162 | 0 | if(fieldDescriptor.getFieldKey() != null){ |
| 163 | 0 | mwb.setModelValue(w, model, fieldDescriptor.getFieldKey()); |
| 164 | 0 | dirtyCheckField(fieldDescriptor, model); |
| 165 | 0 | ValidateRequestEvent e = new ValidateRequestEvent(); |
| 166 | 0 | e.setFieldDescriptor(fieldDescriptor); |
| 167 | 0 | e.setValidateSingleField(true); |
| 168 | 0 | controller.fireApplicationEvent(e); |
| 169 | |
} |
| 170 | 0 | } |
| 171 | |
|
| 172 | |
private void dirtyCheckField(FieldDescriptor fieldDescriptor, DataModel model){ |
| 173 | 0 | QueryPath fieldPath = QueryPath.parse(fieldDescriptor.getFieldKey()); |
| 174 | 0 | QueryPath qPathDirty = fieldPath.subPath(0, fieldPath.size() - 1); |
| 175 | 0 | qPathDirty.add(ModelWidgetBindingSupport.RUNTIME_ROOT); |
| 176 | 0 | qPathDirty.add(ModelWidgetBindingSupport.DIRTY_PATH); |
| 177 | 0 | qPathDirty.add(fieldPath.get(fieldPath.size()-1)); |
| 178 | 0 | Boolean dirty = false; |
| 179 | |
|
| 180 | 0 | if(ensureDirtyFlagPath(model.getRoot(), qPathDirty)){ |
| 181 | 0 | dirty = model.get(qPathDirty); |
| 182 | |
} |
| 183 | 0 | if(dirty){ |
| 184 | 0 | setIsDirty(true); |
| 185 | 0 | fieldDescriptor.setDirty(true); |
| 186 | |
} |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
protected boolean ensureDirtyFlagPath(Data root, QueryPath path) { |
| 190 | 0 | Data current = root; |
| 191 | 0 | boolean containsFlag = false; |
| 192 | 0 | for (int i = 0; i < path.size(); i++) { |
| 193 | 0 | Key key = path.get(i); |
| 194 | 0 | if(i == path.size() - 1){ |
| 195 | 0 | containsFlag = current.containsKey(key); |
| 196 | 0 | break; |
| 197 | |
} |
| 198 | 0 | Data d = current.get(key); |
| 199 | 0 | if (d == null) { |
| 200 | 0 | containsFlag = false; |
| 201 | 0 | break; |
| 202 | |
} |
| 203 | 0 | current = d; |
| 204 | |
} |
| 205 | 0 | return containsFlag; |
| 206 | |
} |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
@Override |
| 214 | |
public String addSection(Section section) { |
| 215 | |
|
| 216 | 0 | section.setLayoutController(layoutController); |
| 217 | 0 | sections.add(section); |
| 218 | 0 | String key = layout.addLayout(section.getLayout()); |
| 219 | 0 | return key; |
| 220 | |
} |
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
@Override |
| 228 | |
public void removeSection(Section section){ |
| 229 | 0 | sections.remove(section); |
| 230 | 0 | layout.removeLayoutElement(section.getLayout()); |
| 231 | 0 | } |
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
protected void clearValidationErrors() { |
| 238 | 0 | layout.clearValidationErrors(); |
| 239 | 0 | } |
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
public void clearValidationWarnings() { |
| 246 | 0 | layout.clearValidationWarnings(); |
| 247 | 0 | } |
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
@Override |
| 255 | |
public List<FieldDescriptor> getFields() { |
| 256 | 0 | List<FieldDescriptor> allFields = new ArrayList<FieldDescriptor>(); |
| 257 | 0 | allFields.addAll(fields); |
| 258 | |
|
| 259 | 0 | for(Section ns: sections){ |
| 260 | 0 | allFields.addAll(ns.getFields()); |
| 261 | |
} |
| 262 | 0 | return allFields; |
| 263 | |
} |
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
@Override |
| 270 | |
public List<FieldDescriptor> getUnnestedFields() { |
| 271 | 0 | return fields; |
| 272 | |
} |
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
@Override |
| 279 | |
public List<Section> getSections() { |
| 280 | 0 | return sections; |
| 281 | |
} |
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
@Override |
| 290 | |
public ErrorLevel processValidationResults(List<ValidationResultInfo> results, boolean clearErrors){ |
| 291 | 0 | if(clearErrors){ |
| 292 | 0 | this.clearValidationErrors(); |
| 293 | |
} |
| 294 | 0 | ErrorLevel status = ErrorLevel.OK; |
| 295 | |
|
| 296 | 0 | if (isValidationEnabled){ |
| 297 | |
|
| 298 | 0 | for(FieldDescriptor f: this.fields){ |
| 299 | |
|
| 300 | 0 | if(f.hasHadFocus()){ |
| 301 | 0 | for(ValidationResultInfo vr: results){ |
| 302 | 0 | String vrElement = vr.getElement(); |
| 303 | 0 | if(vrElement.startsWith("/")){ |
| 304 | 0 | vrElement = vrElement.substring(1); |
| 305 | |
} |
| 306 | |
|
| 307 | 0 | vrElement = vrElement.replaceFirst("^(\\S+)/[0-9]+$", "$1"); |
| 308 | |
|
| 309 | |
|
| 310 | 0 | String parentPath = Application.getApplicationContext().getParentPath(); |
| 311 | 0 | parentPath = parentPath==null?"":parentPath; |
| 312 | |
|
| 313 | 0 | if((parentPath+vrElement).equals(parentPath+f.getFieldKey())){ |
| 314 | 0 | FieldElement element = f.getFieldElement(); |
| 315 | 0 | if (element != null){ |
| 316 | 0 | ErrorLevel fieldStatus = element.processValidationResult(vr); |
| 317 | 0 | if(fieldStatus.getLevel() > status.getLevel()){ |
| 318 | 0 | status = fieldStatus; |
| 319 | |
} |
| 320 | |
} |
| 321 | |
} |
| 322 | 0 | } |
| 323 | |
} |
| 324 | |
|
| 325 | 0 | if(f.getFieldWidget() instanceof MultiplicityComposite ){ |
| 326 | 0 | MultiplicityComposite mc = (MultiplicityComposite) f.getFieldWidget(); |
| 327 | |
|
| 328 | |
|
| 329 | 0 | for(MultiplicityItem item: mc.getItems()){ |
| 330 | 0 | if(item.getItemWidget() instanceof Section && !item.isDeleted()){ |
| 331 | 0 | ErrorLevel fieldStatus = ((Section)item.getItemWidget()).processValidationResults(results, clearErrors); |
| 332 | 0 | if(fieldStatus.getLevel() > status.getLevel()){ |
| 333 | 0 | status = fieldStatus; |
| 334 | |
} |
| 335 | 0 | } |
| 336 | |
} |
| 337 | |
} |
| 338 | |
|
| 339 | 0 | if(f.getFieldWidget() instanceof MultiplicityGroup ){ |
| 340 | 0 | MultiplicityGroup mg = (MultiplicityGroup) f.getFieldWidget(); |
| 341 | |
|
| 342 | |
|
| 343 | 0 | for(MultiplicityGroupItem item: mg.getItems()){ |
| 344 | 0 | if(item.getItemWidget() instanceof Section && !item.isDeleted()){ |
| 345 | 0 | ErrorLevel fieldStatus = ((Section)item.getItemWidget()).processValidationResults(results, clearErrors); |
| 346 | 0 | if(fieldStatus.getLevel() > status.getLevel()){ |
| 347 | 0 | status = fieldStatus; |
| 348 | |
} |
| 349 | 0 | } |
| 350 | |
} |
| 351 | |
} |
| 352 | 0 | if (f.getFieldWidget() instanceof CanProcessValidationResults) { |
| 353 | 0 | ErrorLevel fieldStatus = ((CanProcessValidationResults) f.getFieldWidget()).processValidationResults(f, results, clearErrors); |
| 354 | 0 | if (fieldStatus.getLevel() > status.getLevel()) { |
| 355 | 0 | status = fieldStatus; |
| 356 | |
} |
| 357 | 0 | } |
| 358 | |
} |
| 359 | |
|
| 360 | 0 | for(Section s: sections){ |
| 361 | 0 | ErrorLevel subsectionStatus = s.processValidationResults(results,clearErrors); |
| 362 | 0 | if(subsectionStatus.getLevel() > status.getLevel()){ |
| 363 | 0 | status = subsectionStatus; |
| 364 | |
} |
| 365 | 0 | } |
| 366 | |
} |
| 367 | |
|
| 368 | 0 | return status; |
| 369 | |
} |
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
@Override |
| 376 | |
public ErrorLevel processValidationResults(List<ValidationResultInfo> results) { |
| 377 | 0 | return processValidationResults(results, true); |
| 378 | |
} |
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
@Override |
| 386 | |
public LayoutController getLayoutController() { |
| 387 | 0 | return this.layoutController; |
| 388 | |
} |
| 389 | |
|
| 390 | |
@Override |
| 391 | |
public void setLayoutController(LayoutController controller) { |
| 392 | 0 | this.layoutController = controller; |
| 393 | 0 | } |
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
@Override |
| 401 | |
public String addWidget(Widget w) { |
| 402 | 0 | return layout.addWidget(w); |
| 403 | |
} |
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
public void setFieldHasHadFocusFlags(boolean hadFocus) { |
| 412 | 0 | for(FieldDescriptor f: fields){ |
| 413 | 0 | f.setHasHadFocus(hadFocus); |
| 414 | 0 | if(f.getFieldWidget() instanceof MultiplicityComposite){ |
| 415 | 0 | MultiplicityComposite mc = (MultiplicityComposite) f.getFieldWidget(); |
| 416 | |
|
| 417 | 0 | for(MultiplicityItem item: mc.getItems()){ |
| 418 | 0 | if(item.getItemWidget() instanceof Section && !item.isDeleted()){ |
| 419 | 0 | ((Section) item.getItemWidget()).setFieldHasHadFocusFlags(hadFocus); |
| 420 | |
} |
| 421 | |
} |
| 422 | 0 | }else if(f.getFieldWidget() instanceof MultiplicityGroup){ |
| 423 | 0 | MultiplicityGroup mg = (MultiplicityGroup) f.getFieldWidget(); |
| 424 | |
|
| 425 | 0 | for(MultiplicityGroupItem item: mg.getItems()){ |
| 426 | 0 | if(item.getItemWidget() instanceof Section && !item.isDeleted()){ |
| 427 | 0 | ((Section) item.getItemWidget()).setFieldHasHadFocusFlags(hadFocus); |
| 428 | |
} |
| 429 | |
} |
| 430 | 0 | } |
| 431 | |
} |
| 432 | |
|
| 433 | 0 | for(Section s: sections){ |
| 434 | 0 | s.setFieldHasHadFocusFlags(hadFocus); |
| 435 | |
} |
| 436 | |
|
| 437 | 0 | } |
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
@Override |
| 444 | |
public void enableValidation(boolean enableValidation) { |
| 445 | 0 | this.isValidationEnabled = enableValidation; |
| 446 | 0 | } |
| 447 | |
|
| 448 | |
@Override |
| 449 | |
public boolean isValidationEnabled() { |
| 450 | 0 | return isValidationEnabled; |
| 451 | |
} |
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
@Override |
| 460 | |
public void updateModel(DataModel model){ |
| 461 | 0 | SectionBinding.INSTANCE.setModelValue(this, model, ""); |
| 462 | 0 | } |
| 463 | |
|
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
|
| 472 | |
@Override |
| 473 | |
public void updateWidgetData(DataModel model) { |
| 474 | 0 | SectionBinding.INSTANCE.setWidgetValue(this, model, ""); |
| 475 | 0 | } |
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
@Override |
| 482 | |
public void resetFieldInteractionFlags() { |
| 483 | 0 | this.isDirty = false; |
| 484 | 0 | for(FieldDescriptor f: fields){ |
| 485 | 0 | f.setDirty(false); |
| 486 | 0 | f.setHasHadFocus(false); |
| 487 | |
} |
| 488 | |
|
| 489 | 0 | for(Section s: sections){ |
| 490 | 0 | s.resetFieldInteractionFlags(); |
| 491 | |
} |
| 492 | |
|
| 493 | 0 | } |
| 494 | |
|
| 495 | |
@Override |
| 496 | |
public void resetDirtyFlags() { |
| 497 | 0 | this.isDirty = false; |
| 498 | 0 | for(FieldDescriptor f: fields){ |
| 499 | 0 | f.setDirty(false); |
| 500 | |
} |
| 501 | |
|
| 502 | 0 | for(Section s: sections){ |
| 503 | 0 | s.resetDirtyFlags(); |
| 504 | |
} |
| 505 | 0 | } |
| 506 | |
|
| 507 | |
|
| 508 | |
|
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
@Override |
| 514 | |
public String addSection(String key, Section section) { |
| 515 | 0 | sections.add(section); |
| 516 | 0 | section.getLayout().setKey(key); |
| 517 | 0 | String rkey = layout.addLayout(section.getLayout()); |
| 518 | 0 | return rkey; |
| 519 | |
} |
| 520 | |
|
| 521 | |
@Override |
| 522 | |
public FieldDescriptor getField(String fieldKey) { |
| 523 | 0 | for(FieldDescriptor f: fields){ |
| 524 | 0 | if(f.getFieldKey().equals(fieldKey)){ |
| 525 | 0 | return f; |
| 526 | |
} |
| 527 | |
} |
| 528 | 0 | return null; |
| 529 | |
} |
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
@Override |
| 538 | |
public FieldLayout getLayout() { |
| 539 | 0 | return layout; |
| 540 | |
} |
| 541 | |
|
| 542 | |
@Override |
| 543 | |
public Section getSection(String sectionKey) { |
| 544 | 0 | for(Section s: sections){ |
| 545 | 0 | if(s.getLayout().getKey().equals(sectionKey)){ |
| 546 | 0 | return s; |
| 547 | |
} |
| 548 | |
} |
| 549 | 0 | return null; |
| 550 | |
} |
| 551 | |
|
| 552 | |
@Override |
| 553 | |
public void removeField(String fieldKey) { |
| 554 | 0 | int index = 0; |
| 555 | 0 | boolean found = false; |
| 556 | 0 | for(FieldDescriptor f: fields){ |
| 557 | 0 | if(f.getFieldKey().equals(fieldKey)){ |
| 558 | 0 | index = fields.indexOf(f); |
| 559 | 0 | found = true; |
| 560 | 0 | break; |
| 561 | |
} |
| 562 | |
} |
| 563 | 0 | if(found){ |
| 564 | 0 | fields.remove(index); |
| 565 | |
} |
| 566 | 0 | layout.removeLayoutElement(fieldKey); |
| 567 | |
|
| 568 | 0 | } |
| 569 | |
|
| 570 | |
@Override |
| 571 | |
public void removeField(FieldDescriptor field) { |
| 572 | |
|
| 573 | 0 | fields.remove(field); |
| 574 | 0 | layout.removeLayoutElement(field.getFieldKey()); |
| 575 | |
|
| 576 | 0 | } |
| 577 | |
|
| 578 | |
@Override |
| 579 | |
public void removeSection(String sectionKey) { |
| 580 | 0 | int index = 0; |
| 581 | 0 | boolean found = false; |
| 582 | 0 | for(Section s: sections){ |
| 583 | 0 | if(s.getLayout().getKey().equals(sectionKey)){ |
| 584 | 0 | index = sections.indexOf(s); |
| 585 | 0 | found = true; |
| 586 | 0 | break; |
| 587 | |
} |
| 588 | |
} |
| 589 | 0 | if(found){ |
| 590 | 0 | sections.remove(index); |
| 591 | |
} |
| 592 | 0 | layout.removeLayoutElement(sectionKey); |
| 593 | |
|
| 594 | 0 | } |
| 595 | |
|
| 596 | |
@Override |
| 597 | |
public void removeWidget(Widget widget) { |
| 598 | 0 | layout.removeLayoutElement(widget); |
| 599 | |
|
| 600 | 0 | } |
| 601 | |
|
| 602 | |
@Override |
| 603 | |
public void removeWidget(String key) { |
| 604 | 0 | layout.removeLayoutElement(key); |
| 605 | |
|
| 606 | 0 | } |
| 607 | |
|
| 608 | |
|
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
public boolean isDirty(){ |
| 615 | 0 | if(!this.isDirty){ |
| 616 | |
|
| 617 | 0 | for(Section s: sections){ |
| 618 | 0 | if(s.isDirty()){ |
| 619 | 0 | setIsDirty(true); |
| 620 | 0 | break; |
| 621 | |
} |
| 622 | |
} |
| 623 | |
} |
| 624 | 0 | return isDirty; |
| 625 | |
} |
| 626 | |
|
| 627 | |
public void setIsDirty(boolean state) { |
| 628 | |
|
| 629 | 0 | if (layoutController == null){ |
| 630 | 0 | layoutController = LayoutController.findParentLayout(layout); |
| 631 | |
} |
| 632 | 0 | if (isDirty != state){ |
| 633 | 0 | isDirty = state; |
| 634 | 0 | if (layoutController != null && isDirty){ |
| 635 | 0 | layoutController.fireApplicationEvent(new ContentDirtyEvent()); |
| 636 | |
} |
| 637 | |
} |
| 638 | 0 | } |
| 639 | |
|
| 640 | |
|
| 641 | |
|
| 642 | |
|
| 643 | |
@Override |
| 644 | |
public void add(Widget w) { |
| 645 | 0 | super.add(w); |
| 646 | 0 | } |
| 647 | |
|
| 648 | |
|
| 649 | |
|
| 650 | |
|
| 651 | |
|
| 652 | |
@Override |
| 653 | |
public void addStyleName(String style) { |
| 654 | 0 | layout.addStyleName(style); |
| 655 | 0 | } |
| 656 | |
|
| 657 | |
@Override |
| 658 | |
public void setStyleName(String style) { |
| 659 | 0 | layout.setStyleName(style); |
| 660 | 0 | } |
| 661 | |
|
| 662 | |
|
| 663 | |
|
| 664 | |
|
| 665 | |
|
| 666 | |
public void setInstructions(String html){ |
| 667 | 0 | layout.setInstructions(html); |
| 668 | 0 | } |
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | |
public void setHelp(String html){ |
| 675 | 0 | layout.setHelp(html); |
| 676 | 0 | } |
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | |
public void setRequired(AbbrPanel required){ |
| 683 | 0 | layout.setRequired(required); |
| 684 | 0 | } |
| 685 | |
|
| 686 | |
public void setSectionId(String id){ |
| 687 | 0 | ((Widget)layout).getElement().setId(id); |
| 688 | 0 | } |
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
|
| 694 | |
|
| 695 | |
|
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
public static void progressiveEnableFields(Boolean isEnabled, FieldDescriptor ... fieldDescriptors){ |
| 700 | |
|
| 701 | 0 | for (FieldDescriptor fd : fieldDescriptors){ |
| 702 | 0 | enableField(isEnabled, fd); |
| 703 | |
} |
| 704 | 0 | } |
| 705 | |
|
| 706 | |
|
| 707 | |
|
| 708 | |
|
| 709 | |
|
| 710 | |
|
| 711 | |
public static void progressiveEnableAndRequireFields(Boolean isRequiredAndEnabled, FieldDescriptor ... fieldDescriptors){ |
| 712 | |
|
| 713 | 0 | for (FieldDescriptor fd : fieldDescriptors){ |
| 714 | 0 | fd.setRequired(isRequiredAndEnabled); |
| 715 | 0 | enableField(isRequiredAndEnabled, fd); |
| 716 | |
} |
| 717 | 0 | } |
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
protected static void enableField(Boolean isEnabled, FieldDescriptor fd){ |
| 727 | |
|
| 728 | 0 | Widget widget = fd.getFieldWidget(); |
| 729 | |
|
| 730 | 0 | if (!isEnabled){ |
| 731 | 0 | fd.getFieldElement().clearValidationErrors(); |
| 732 | 0 | fd.getFieldElement().clearValidationWarnings(); |
| 733 | |
} |
| 734 | |
|
| 735 | |
|
| 736 | 0 | if (widget instanceof KSPicker && ((KSPicker)widget).getInputWidget() instanceof KSDropDown){ |
| 737 | 0 | ((KSDropDown)((KSPicker)widget).getInputWidget()).setEnabled(isEnabled); |
| 738 | 0 | } else if (widget instanceof TextBoxBase){ |
| 739 | 0 | ((TextBoxBase)widget).setReadOnly(!isEnabled); |
| 740 | |
} |
| 741 | 0 | } |
| 742 | |
} |