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 org.kuali.student.common.ui.client.widgets.KSLabel;
19 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
20 import org.kuali.student.common.ui.client.widgets.menus.KSListPanel;
21
22 import com.google.gwt.user.client.ui.Composite;
23 import com.google.gwt.user.client.ui.Widget;
24
25
26
27
28
29
30
31
32 public class ValidationMessagePanel extends Composite{
33
34 private VerticalFlowPanel container = new VerticalFlowPanel();
35 private KSListPanel errorListPanel = new KSListPanel();
36 private KSListPanel warnListPanel = new KSListPanel();
37 private int warnCount = 0;
38 private int errorCount = 0;
39 private boolean topMargin = true;
40
41 public ValidationMessagePanel(){
42 this.initWidget(container);
43 container.add(errorListPanel);
44 container.add(warnListPanel);
45 errorListPanel.addStyleName("ks-form-module-validation-errors");
46 warnListPanel.addStyleName("ks-form-module-validation-warnings");
47 }
48
49 public ValidationMessagePanel(boolean topMargin){
50 this.initWidget(errorListPanel);
51 this.topMargin = topMargin;
52 }
53
54 public void addErrorMessage(KSLabel message){
55 if(getMessageCount() == 0 && topMargin){
56 message.addStyleName("ks-form-module-single-line-margin");
57 }
58 errorListPanel.add(message);
59 errorCount++;
60 }
61
62 public void addWarnMessage(Widget message){
63 if(getMessageCount() == 0 && topMargin){
64 message.addStyleName("ks-form-module-single-line-margin");
65 }
66 warnListPanel.add(message);
67 warnCount++;
68 }
69
70 public boolean hasWarnings(){
71 return (warnCount > 0);
72 }
73
74 public void clearErrors(){
75 errorListPanel.clear();
76 errorCount = 0;
77 }
78
79 public void clearWarnings(){
80 warnListPanel.clear();
81 warnCount = 0;
82 }
83
84 public int getMessageCount(){
85 return errorCount + warnCount;
86 }
87 }