| 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.element; |
| 17 | |
|
| 18 | |
import org.kuali.student.common.assembly.data.Metadata; |
| 19 | |
import org.kuali.student.common.ui.client.application.Application; |
| 20 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
| 21 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.ValidationMessagePanel; |
| 22 | |
import org.kuali.student.common.ui.client.util.DebugIdUtils; |
| 23 | |
import org.kuali.student.common.ui.client.widgets.HasInputWidget; |
| 24 | |
import org.kuali.student.common.ui.client.widgets.HasWatermark; |
| 25 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
| 26 | |
import org.kuali.student.common.ui.client.widgets.KSTitleDescPanel; |
| 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.layouts.FieldLayout; |
| 29 | |
import org.kuali.student.common.ui.client.widgets.field.layout.layouts.FieldLayoutComponent; |
| 30 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
| 31 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel; |
| 32 | |
|
| 33 | |
import com.google.gwt.user.client.Element; |
| 34 | |
import com.google.gwt.user.client.ui.Composite; |
| 35 | |
import com.google.gwt.user.client.ui.FlowPanel; |
| 36 | |
import com.google.gwt.user.client.ui.HTMLPanel; |
| 37 | |
import com.google.gwt.user.client.ui.Panel; |
| 38 | |
import com.google.gwt.user.client.ui.UIObject; |
| 39 | |
import com.google.gwt.user.client.ui.Widget; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
public class FieldElement extends Composite implements FieldLayoutComponent{ |
| 75 | |
|
| 76 | |
|
| 77 | 0 | private KSTitleDescPanel titlePanel = new KSTitleDescPanel(); |
| 78 | 0 | private FlowPanel layout = new FlowPanel(); |
| 79 | |
private FieldTitle fieldTitle; |
| 80 | 0 | private SpanPanel instructions = new SpanPanel(); |
| 81 | 0 | private AbbrButton examplesButton = new AbbrButton(AbbrButtonType.EXAMPLES); |
| 82 | 0 | private SpanPanel constraints = new SpanPanel(); |
| 83 | 0 | private AbbrPanel required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
| 84 | 0 | private AbbrButton help = new AbbrButton(AbbrButtonType.HELP); |
| 85 | |
private Widget fieldWidget; |
| 86 | 0 | private SpanPanel widgetSpan = new SpanPanel(); |
| 87 | |
private String fieldHTMLId; |
| 88 | 0 | private String watermarkText = null; |
| 89 | 0 | public static enum LineNum{SINGLE, DOUBLE, TRIPLE} |
| 90 | |
|
| 91 | |
private ValidationMessagePanel validationPanel; |
| 92 | |
private String fieldKey; |
| 93 | 0 | private boolean labelShown = true; |
| 94 | |
|
| 95 | |
private Panel parentPanel; |
| 96 | |
private Element parentElement; |
| 97 | |
|
| 98 | 0 | private ErrorLevel status = ErrorLevel.OK; |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
public void setValidationPanel(ValidationMessagePanel validationPanel) { |
| 107 | 0 | this.validationPanel = validationPanel; |
| 108 | 0 | } |
| 109 | |
|
| 110 | |
|
| 111 | |
public Panel getParentPanel() { |
| 112 | 0 | return parentPanel; |
| 113 | |
} |
| 114 | |
|
| 115 | |
public void setParentPanel(Panel parentPanel) { |
| 116 | 0 | this.parentPanel = parentPanel; |
| 117 | 0 | this.parentElement = parentPanel.getElement(); |
| 118 | 0 | } |
| 119 | |
|
| 120 | |
public void setParentElement(Element element){ |
| 121 | 0 | parentElement = element; |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
private String fieldName; |
| 125 | |
private String instructionText; |
| 126 | |
|
| 127 | |
public String getInstructionText() { |
| 128 | 0 | return instructionText; |
| 129 | |
} |
| 130 | |
|
| 131 | 0 | public FieldElement(String title, Widget widget) { |
| 132 | 0 | generateLayout(title, title, null, null, null, null, widget); |
| 133 | |
|
| 134 | 0 | } |
| 135 | |
|
| 136 | 0 | public FieldElement(String key, String title, Widget widget){ |
| 137 | 0 | generateLayout(key, title, null, null, null, null, widget); |
| 138 | 0 | } |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | 0 | public FieldElement(String key, MessageKeyInfo info){ |
| 146 | 0 | init(key, info, null, null); |
| 147 | 0 | } |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | 0 | public FieldElement(String key, MessageKeyInfo info, Widget widget, Metadata metadata){ |
| 156 | 0 | init(key, info, widget, metadata); |
| 157 | |
|
| 158 | 0 | } |
| 159 | |
|
| 160 | |
private void init(String key, MessageKeyInfo info, Widget widget, Metadata metadata ){ |
| 161 | 0 | String title = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(), info.getId()); |
| 162 | |
|
| 163 | 0 | String help = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(), |
| 164 | |
info.getId() + HELP_MESSAGE_KEY, metadata); |
| 165 | 0 | if(help.equals(info.getId() + HELP_MESSAGE_KEY)){ |
| 166 | 0 | help = null; |
| 167 | |
} |
| 168 | |
|
| 169 | 0 | String instructions = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(), |
| 170 | |
info.getId() + INSTRUCT_MESSAGE_KEY, metadata); |
| 171 | 0 | if(instructions.equals(info.getId() + INSTRUCT_MESSAGE_KEY)){ |
| 172 | 0 | instructions = null; |
| 173 | |
} |
| 174 | |
|
| 175 | 0 | String examplesText = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(), |
| 176 | |
info.getId() + EXAMPLES_MESSAGE_KEY, metadata); |
| 177 | 0 | if (examplesText.equals(info.getId() + EXAMPLES_MESSAGE_KEY)) { |
| 178 | 0 | examplesText = null; |
| 179 | |
} |
| 180 | |
|
| 181 | 0 | String constraints = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(), |
| 182 | |
info.getId() + CONSTRAINT_MESSAGE_KEY, metadata); |
| 183 | 0 | if(constraints.equals(info.getId() + CONSTRAINT_MESSAGE_KEY)){ |
| 184 | 0 | constraints = null; |
| 185 | |
} |
| 186 | |
|
| 187 | 0 | watermarkText = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(), |
| 188 | |
info.getId() + WATERMARK_MESSAGE_KEY, metadata); |
| 189 | 0 | if(watermarkText.equals(info.getId() + WATERMARK_MESSAGE_KEY)){ |
| 190 | 0 | watermarkText = null; |
| 191 | |
} |
| 192 | |
|
| 193 | 0 | generateLayout(key, title, help, instructions, examplesText, constraints, widget); |
| 194 | 0 | } |
| 195 | |
|
| 196 | |
private void generateLayout(String key, String title, String helpText, String instructText, String examplesText, String constraintText, Widget widget){ |
| 197 | 0 | this.setKey(key); |
| 198 | 0 | fieldName = title; |
| 199 | 0 | fieldHTMLId = HTMLPanel.createUniqueId(); |
| 200 | 0 | fieldTitle = new LabelPanel(title, fieldHTMLId); |
| 201 | 0 | required.setVisible(false); |
| 202 | 0 | fieldTitle.add(required); |
| 203 | 0 | if(helpText != null){ |
| 204 | 0 | this.setHelp(helpText); |
| 205 | |
} |
| 206 | |
else{ |
| 207 | 0 | help.setVisible(false); |
| 208 | |
} |
| 209 | 0 | fieldTitle.add(help); |
| 210 | 0 | layout.add(fieldTitle); |
| 211 | 0 | if(instructText != null){ |
| 212 | 0 | this.setInstructions(instructText); |
| 213 | |
} |
| 214 | |
else{ |
| 215 | 0 | instructions.setVisible(false); |
| 216 | |
} |
| 217 | 0 | if (examplesText != null) { |
| 218 | 0 | this.setExamples(examplesText); |
| 219 | |
} |
| 220 | |
else { |
| 221 | 0 | examplesButton.setVisible(false); |
| 222 | |
} |
| 223 | 0 | if(constraintText != null){ |
| 224 | 0 | this.setConstraintText(constraintText); |
| 225 | |
} |
| 226 | |
else{ |
| 227 | 0 | constraints.setVisible(false); |
| 228 | |
} |
| 229 | 0 | instructions.setStyleName("ks-form-module-elements-instruction"); |
| 230 | 0 | layout.add(instructions); |
| 231 | 0 | instructions.add(examplesButton); |
| 232 | 0 | layout.add(widgetSpan); |
| 233 | 0 | constraints.setStyleName("ks-form-module-elements-help-text"); |
| 234 | 0 | layout.add(constraints); |
| 235 | 0 | initWidget(layout); |
| 236 | 0 | layout.addStyleName("ks-form-module-elements"); |
| 237 | 0 | layout.addStyleName("ks-form-module-single-line-margin"); |
| 238 | 0 | layout.ensureDebugId(DebugIdUtils.createWebDriverSafeDebugId(key != null ? key : title)); |
| 239 | |
|
| 240 | 0 | if(widget != null){ |
| 241 | 0 | this.setWidget(widget); |
| 242 | |
} |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
public void setWidget(Widget w){ |
| 251 | 0 | if(fieldWidget != null){ |
| 252 | 0 | widgetSpan.remove(fieldWidget); |
| 253 | |
} |
| 254 | 0 | fieldWidget = w; |
| 255 | |
|
| 256 | 0 | if(fieldWidget != null){ |
| 257 | |
|
| 258 | |
|
| 259 | 0 | if(fieldWidget instanceof HasInputWidget){ |
| 260 | 0 | Widget input = ((HasInputWidget)fieldWidget).getInputWidget(); |
| 261 | 0 | if(input != null){ |
| 262 | 0 | if(input instanceof HasWatermark && watermarkText != null){ |
| 263 | 0 | ((HasWatermark)input).setWatermarkText(watermarkText); |
| 264 | |
} |
| 265 | 0 | input.getElement().setAttribute("id", fieldHTMLId); |
| 266 | 0 | setDebugId(fieldWidget); |
| 267 | |
|
| 268 | |
|
| 269 | 0 | setDebugId(input); |
| 270 | |
} |
| 271 | |
else{ |
| 272 | 0 | fieldWidget.getElement().setAttribute("id", fieldHTMLId); |
| 273 | 0 | setDebugId(fieldWidget); |
| 274 | |
} |
| 275 | 0 | } |
| 276 | |
else{ |
| 277 | 0 | if(fieldWidget instanceof HasWatermark && watermarkText != null){ |
| 278 | 0 | ((HasWatermark)fieldWidget).setWatermarkText(watermarkText); |
| 279 | |
} |
| 280 | 0 | fieldWidget.getElement().setAttribute("id", fieldHTMLId); |
| 281 | 0 | setDebugId(fieldWidget); |
| 282 | |
|
| 283 | |
} |
| 284 | |
|
| 285 | 0 | widgetSpan.add(fieldWidget); |
| 286 | |
} |
| 287 | 0 | } |
| 288 | |
|
| 289 | |
|
| 290 | |
private void setDebugId(final Widget widget) { |
| 291 | 0 | widget.ensureDebugId(DebugIdUtils.createWebDriverSafeDebugId(layout.getElement().getId())); |
| 292 | 0 | } |
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
public void setRequiredString(String requiredKey){ |
| 301 | 0 | String requiredText = Application.getApplicationContext().getMessage(requiredKey); |
| 302 | 0 | required.setText(requiredText); |
| 303 | 0 | required.setVisible(true); |
| 304 | 0 | } |
| 305 | |
|
| 306 | |
public void setRequiredString(String requiredKey, String style){ |
| 307 | 0 | String requiredText = Application.getApplicationContext().getMessage(requiredKey); |
| 308 | 0 | required.setText(requiredText); |
| 309 | 0 | required.setStyleName(style); |
| 310 | 0 | required.setVisible(true); |
| 311 | 0 | } |
| 312 | |
|
| 313 | |
public AbbrPanel getRequiredPanel(){ |
| 314 | 0 | return required; |
| 315 | |
} |
| 316 | |
|
| 317 | |
public void clearRequiredText(){ |
| 318 | 0 | required.setText(""); |
| 319 | 0 | } |
| 320 | |
|
| 321 | |
public Widget getFieldWidget(){ |
| 322 | 0 | return fieldWidget; |
| 323 | |
} |
| 324 | |
|
| 325 | |
public FlowPanel getFieldDetailsLayout(){ |
| 326 | 0 | FlowPanel div = new FlowPanel(); |
| 327 | 0 | div.add(fieldTitle); |
| 328 | 0 | div.add(instructions); |
| 329 | 0 | div.addStyleName("ks-form-module-elements"); |
| 330 | 0 | return div; |
| 331 | |
} |
| 332 | |
|
| 333 | |
public FlowPanel getFieldWidgetAreaLayout(){ |
| 334 | 0 | FlowPanel div = new FlowPanel(); |
| 335 | 0 | div.add(fieldWidget); |
| 336 | 0 | div.add(constraints); |
| 337 | 0 | div.addStyleName("ks-form-module-elements"); |
| 338 | 0 | return div; |
| 339 | |
} |
| 340 | |
|
| 341 | |
public boolean isRequired() { |
| 342 | 0 | return required.isVisible(); |
| 343 | |
} |
| 344 | |
|
| 345 | |
public void setRequired(boolean isRequired){ |
| 346 | 0 | required.setVisible(isRequired); |
| 347 | 0 | } |
| 348 | |
|
| 349 | |
public void setInstructions(String text){ |
| 350 | 0 | instructionText = text; |
| 351 | 0 | if(instructionText != null && !instructionText.trim().equals("")){ |
| 352 | 0 | instructions.setHTML(text); |
| 353 | 0 | instructions.setVisible(true); |
| 354 | |
} |
| 355 | 0 | } |
| 356 | |
|
| 357 | |
public void setExamples(String examplesText) { |
| 358 | 0 | if (examplesText != null && !"".equals(examplesText.trim())) { |
| 359 | 0 | examplesButton.setVisible(true); |
| 360 | |
|
| 361 | 0 | instructions.setVisible(true); |
| 362 | 0 | examplesButton.setHoverHTML(examplesText); |
| 363 | 0 | examplesButton.getHoverPopup().addStyleName("ks-example-popup"); |
| 364 | |
} |
| 365 | |
else { |
| 366 | 0 | examplesButton.setVisible(false); |
| 367 | |
} |
| 368 | 0 | } |
| 369 | |
|
| 370 | |
public void setConstraintText(String text){ |
| 371 | 0 | if(text != null && !text.trim().equals("")){ |
| 372 | 0 | constraints.setHTML(text); |
| 373 | 0 | constraints.setVisible(true); |
| 374 | |
} |
| 375 | 0 | } |
| 376 | |
|
| 377 | |
public void setHelp(final String html){ |
| 378 | 0 | if(html != null && !html.trim().equals("")){ |
| 379 | 0 | help.setVisible(true); |
| 380 | 0 | help.setHoverHTML(html); |
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
} |
| 391 | |
else{ |
| 392 | 0 | help.setVisible(false); |
| 393 | |
} |
| 394 | 0 | } |
| 395 | |
|
| 396 | |
public Widget getTitleWidget() { |
| 397 | 0 | return titlePanel.getTitleWidget(); |
| 398 | |
} |
| 399 | |
|
| 400 | |
public ValidationMessagePanel getValidationPanel() { |
| 401 | 0 | return validationPanel; |
| 402 | |
} |
| 403 | |
|
| 404 | |
public Panel getEncapsulatingPanel() { |
| 405 | 0 | return parentPanel; |
| 406 | |
} |
| 407 | |
|
| 408 | |
public String getFieldName() { |
| 409 | 0 | return fieldName; |
| 410 | |
} |
| 411 | |
|
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
public void setErrorState(boolean error){ |
| 418 | 0 | if(error){ |
| 419 | 0 | fieldTitle.addStyleName("invalid"); |
| 420 | 0 | if(parentPanel != null){ |
| 421 | 0 | parentPanel.addStyleName("error"); |
| 422 | |
} |
| 423 | 0 | else if(parentElement != null){ |
| 424 | 0 | parentElement.setClassName("error"); |
| 425 | |
} |
| 426 | |
|
| 427 | 0 | setWarnState(false); |
| 428 | |
} |
| 429 | |
else{ |
| 430 | 0 | fieldTitle.removeStyleName("invalid"); |
| 431 | 0 | if(parentPanel != null){ |
| 432 | 0 | parentPanel.removeStyleName("error"); |
| 433 | |
} |
| 434 | 0 | else if(parentElement != null){ |
| 435 | 0 | parentElement.setClassName(""); |
| 436 | |
} |
| 437 | |
|
| 438 | 0 | setWarnState(validationPanel.hasWarnings()); |
| 439 | |
} |
| 440 | 0 | } |
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
public void setWarnState(boolean warn){ |
| 448 | 0 | if(warn){ |
| 449 | |
|
| 450 | 0 | if(parentPanel != null){ |
| 451 | 0 | parentPanel.addStyleName("warning"); |
| 452 | |
} |
| 453 | 0 | else if(parentElement != null){ |
| 454 | 0 | parentElement.setClassName("warning"); |
| 455 | |
} |
| 456 | |
|
| 457 | |
} |
| 458 | |
else{ |
| 459 | |
|
| 460 | 0 | if(parentPanel != null){ |
| 461 | 0 | parentPanel.removeStyleName("warning"); |
| 462 | |
} |
| 463 | 0 | else if(parentElement != null){ |
| 464 | 0 | parentElement.setClassName(""); |
| 465 | |
} |
| 466 | |
} |
| 467 | 0 | } |
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
public ErrorLevel processValidationResult(ValidationResultInfo vr) { |
| 476 | |
|
| 477 | 0 | if(getFieldWidget() instanceof ValidationProcessable){ |
| 478 | 0 | if(((ValidationProcessable)getFieldWidget()).shouldProcessValidationResult(vr)){ |
| 479 | 0 | if (fieldName != null && fieldName.trim() != "") |
| 480 | 0 | return ((ValidationProcessable)getFieldWidget()).processValidationResult(vr, fieldName); |
| 481 | |
else |
| 482 | 0 | return ((ValidationProcessable)getFieldWidget()).processValidationResult(vr); |
| 483 | |
} |
| 484 | |
} |
| 485 | |
|
| 486 | 0 | status = ErrorLevel.OK; |
| 487 | |
|
| 488 | 0 | if(vr.getLevel() == ErrorLevel.ERROR){ |
| 489 | 0 | String message = Application.getApplicationContext().getUILabel("validation", vr.getMessage()); |
| 490 | 0 | this.addValidationErrorMessage(message); |
| 491 | |
|
| 492 | 0 | if(status.getLevel() < ErrorLevel.ERROR.getLevel()){ |
| 493 | 0 | status = vr.getLevel(); |
| 494 | |
} |
| 495 | 0 | } |
| 496 | 0 | else if(vr.getLevel() == ErrorLevel.WARN){ |
| 497 | 0 | String message = Application.getApplicationContext().getUILabel("validation", vr.getMessage()); |
| 498 | 0 | this.addValidationWarningMessage(message); |
| 499 | |
|
| 500 | 0 | if(status.getLevel() < ErrorLevel.WARN.getLevel()){ |
| 501 | 0 | status = vr.getLevel(); |
| 502 | |
} |
| 503 | |
} |
| 504 | |
else{ |
| 505 | |
|
| 506 | |
} |
| 507 | 0 | return status; |
| 508 | |
} |
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
|
| 514 | |
public void addValidationErrorMessage(String text){ |
| 515 | 0 | if(validationPanel != null){ |
| 516 | |
KSLabel message; |
| 517 | 0 | if(fieldName != null && !fieldName.trim().equals("")){ |
| 518 | 0 | message = new KSLabel(fieldName + " - " + text); |
| 519 | |
} |
| 520 | |
else{ |
| 521 | 0 | message = new KSLabel(text); |
| 522 | |
} |
| 523 | 0 | message.setStyleName("ks-form-error-label"); |
| 524 | 0 | this.setErrorState(true); |
| 525 | 0 | this.validationPanel.addErrorMessage(message); |
| 526 | |
} |
| 527 | 0 | } |
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
public void addValidationWarningMessage(String text){ |
| 534 | 0 | if(validationPanel != null){ |
| 535 | 0 | SpanPanel message = new SpanPanel(); |
| 536 | 0 | if(fieldName != null && !fieldName.trim().equals("")){ |
| 537 | 0 | message.setHTML("<b> Warning </b> " + fieldName + " - " + text); |
| 538 | |
} |
| 539 | |
else{ |
| 540 | 0 | message.setHTML("<b> Warning </b> " + text); |
| 541 | |
} |
| 542 | 0 | message.setStyleName("ks-form-warn-label"); |
| 543 | |
|
| 544 | 0 | this.setWarnState((status != ErrorLevel.ERROR)); |
| 545 | 0 | this.validationPanel.addWarnMessage(message); |
| 546 | |
} |
| 547 | 0 | } |
| 548 | |
|
| 549 | |
|
| 550 | |
|
| 551 | |
|
| 552 | |
public void clearValidationErrors(){ |
| 553 | 0 | this.setErrorState(false); |
| 554 | 0 | if(validationPanel != null){ |
| 555 | 0 | this.validationPanel.clearErrors(); |
| 556 | |
} |
| 557 | |
|
| 558 | |
|
| 559 | 0 | if(getFieldWidget() instanceof ValidationProcessable){ |
| 560 | 0 | ((ValidationProcessable)getFieldWidget()).clearValidationErrors(); |
| 561 | |
} |
| 562 | 0 | } |
| 563 | |
|
| 564 | |
|
| 565 | |
|
| 566 | |
|
| 567 | |
public void clearValidationWarnings(){ |
| 568 | 0 | this.setWarnState(false); |
| 569 | 0 | if(validationPanel != null){ |
| 570 | 0 | this.validationPanel.clearWarnings(); |
| 571 | |
} |
| 572 | |
|
| 573 | |
|
| 574 | 0 | if(getFieldWidget() instanceof ValidationProcessable){ |
| 575 | 0 | ((ValidationProcessable)getFieldWidget()).clearValidationWarnings(); |
| 576 | |
} |
| 577 | 0 | } |
| 578 | |
|
| 579 | |
@Override |
| 580 | |
public String getKey() { |
| 581 | 0 | return fieldKey; |
| 582 | |
} |
| 583 | |
|
| 584 | |
@Override |
| 585 | |
public void setKey(String key) { |
| 586 | 0 | if(key == null){ |
| 587 | |
|
| 588 | 0 | key = HTMLPanel.createUniqueId(); |
| 589 | |
} |
| 590 | 0 | this.fieldKey = key; |
| 591 | 0 | } |
| 592 | |
|
| 593 | |
|
| 594 | |
|
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
public void setTitleDescLineHeight(LineNum margin) { |
| 599 | 0 | layout.removeStyleName("ks-form-module-single-line-margin"); |
| 600 | 0 | switch(margin){ |
| 601 | |
case TRIPLE: |
| 602 | 0 | if(firstLineExists() && secondLineExists()){ |
| 603 | 0 | layout.addStyleName("ks-form-module-single-line-margin"); |
| 604 | |
} |
| 605 | 0 | else if((firstLineExists() || secondLineExists())){ |
| 606 | 0 | layout.addStyleName("ks-form-module-double-line-margin"); |
| 607 | |
} |
| 608 | |
else{ |
| 609 | 0 | layout.addStyleName("ks-form-module-triple-line-margin"); |
| 610 | |
} |
| 611 | |
|
| 612 | 0 | break; |
| 613 | |
case DOUBLE: |
| 614 | 0 | if((firstLineExists() || secondLineExists())){ |
| 615 | 0 | layout.addStyleName("ks-form-module-single-line-margin"); |
| 616 | |
} |
| 617 | |
else{ |
| 618 | 0 | layout.addStyleName("ks-form-module-double-line-margin"); |
| 619 | |
} |
| 620 | 0 | break; |
| 621 | |
case SINGLE: |
| 622 | 0 | layout.addStyleName("ks-form-module-single-line-margin"); |
| 623 | |
break; |
| 624 | |
} |
| 625 | |
|
| 626 | 0 | } |
| 627 | |
|
| 628 | |
private boolean firstLineExists(){ |
| 629 | 0 | boolean exists = false; |
| 630 | 0 | if((fieldName != null && !fieldName.equals("")) || required.isVisible() || help.isVisible()){ |
| 631 | 0 | exists = true; |
| 632 | |
} |
| 633 | 0 | return exists; |
| 634 | |
} |
| 635 | |
|
| 636 | |
private boolean secondLineExists(){ |
| 637 | 0 | boolean exists = false; |
| 638 | 0 | if(instructions.isVisible()){ |
| 639 | 0 | exists = true; |
| 640 | |
} |
| 641 | 0 | return exists; |
| 642 | |
} |
| 643 | |
|
| 644 | |
|
| 645 | |
|
| 646 | |
|
| 647 | |
public void hideLabel() { |
| 648 | 0 | layout.removeStyleName("ks-form-module-double-line-margin"); |
| 649 | 0 | layout.removeStyleName("ks-form-module-triple-line-margin"); |
| 650 | 0 | layout.addStyleName("ks-form-module-single-line-margin"); |
| 651 | 0 | fieldTitle.setStyleName("accessibility-hidden"); |
| 652 | 0 | instructions.setVisible(false); |
| 653 | 0 | labelShown = false; |
| 654 | 0 | } |
| 655 | |
|
| 656 | |
public boolean isLabelShown(){ |
| 657 | 0 | return labelShown; |
| 658 | |
} |
| 659 | |
} |