View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
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   * The validation message panel used for field elements, adds validation errors to a list and styles
27   * them appropriately.
28   * 
29   * @author Kuali Student Team
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  }