Clover Coverage Report - Kuali Student 1.3.0-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Apr 28 2011 05:03:32 EDT
../../../../../../../img/srcFileCovDistChart0.png 2% of files have more coverage
38   107   15   4.22
10   93   0.39   9
9     1.67  
1    
 
  ListOfStringWidget       Line # 23 38 0% 15 57 0% 0.0
 
No Tests
 
1    package org.kuali.student.common.ui.client.widgets;
2   
3    import java.util.ArrayList;
4    import java.util.List;
5   
6    import org.kuali.student.common.assembly.data.QueryPath;
7    import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
8    import org.kuali.student.common.ui.client.validator.DataModelValidator;
9    import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrButton;
10    import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrButton.AbbrButtonType;
11    import org.kuali.student.common.ui.client.widgets.field.layout.element.LabelPanel;
12    import org.kuali.student.common.validation.dto.ValidationResultInfo;
13   
14    import com.google.gwt.event.dom.client.BlurHandler;
15    import com.google.gwt.event.dom.client.ClickEvent;
16    import com.google.gwt.event.dom.client.ClickHandler;
17    import com.google.gwt.event.dom.client.HasBlurHandlers;
18    import com.google.gwt.event.shared.HandlerRegistration;
19    import com.google.gwt.user.client.ui.Composite;
20    import com.google.gwt.user.client.ui.FlowPanel;
21    import com.google.gwt.user.client.ui.HTMLPanel;
22   
 
23    public class ListOfStringWidget extends Composite implements HasBlurHandlers{
24    private String addItemText;
25   
26    private boolean loaded = false;
27    private FlowPanel mainPanel = new FlowPanel();
28    private FlowPanel itemsPanel = new FlowPanel();
29    private ArrayList<String> values = new ArrayList<String>();
30    final KSTextBox inputText = new KSTextBox();
31    private FieldDescriptor fd;
32    private DataModelValidator validator = new DataModelValidator();
 
33  0 toggle public ListOfStringWidget(String addItemText) {
34  0 super();
35  0 super.initWidget(mainPanel);
36  0 this.addItemText = addItemText;
37    }
38   
 
39  0 toggle public void onLoad() {
40  0 if (!loaded) {
41  0 KSButton addItemButton = new KSButton(addItemText);
42  0 addItemButton.addClickHandler(new ClickHandler(){
 
43  0 toggle public void onClick(ClickEvent event) {
44    //add validate
45  0 List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>();
46  0 validator.doValidateString(inputText.getText(),QueryPath.parse(fd.getFieldKey()), fd.getMetadata(), results);
47  0 if(results.isEmpty()){
48  0 addListItem(inputText.getText());
49  0 inputText.setText("");
50  0 }else if(fd != null && fd.getFieldElement() != null){
51  0 for(ValidationResultInfo vr:results){
52  0 fd.getFieldElement().processValidationResult(vr);
53    }
54    }
55    }
56    });
57  0 mainPanel.add(inputText);
58  0 mainPanel.add(addItemButton);
59  0 mainPanel.add(itemsPanel);
60  0 loaded = true;
61    }
62    }
63   
 
64  0 toggle public ArrayList<String> getStringValues(){
65  0 return values;
66    }
67   
 
68  0 toggle public void setStringValues(ArrayList<String> values){
69  0 itemsPanel.clear();
70  0 if(values!=null){
71  0 for(String value:values){
72  0 addListItem(value);
73    }
74    }
75    }
76   
 
77  0 toggle protected void addListItem(String itemValue){
78  0 final FlowPanel item = new FlowPanel();
79  0 final String curVal = itemValue;
80  0 if (!values.contains(itemValue)) {
81   
82  0 String fieldHTMLId = HTMLPanel.createUniqueId();
83  0 LabelPanel fieldTitle = new LabelPanel(itemValue, fieldHTMLId);
84   
85  0 AbbrButton delButton = new AbbrButton(AbbrButtonType.DELETE);
86  0 delButton.addClickHandler(new ClickHandler() {
 
87  0 toggle public void onClick(ClickEvent event) {
88  0 itemsPanel.remove(item);
89  0 values.remove(curVal);
90    }
91    });
92  0 fieldTitle.add(delButton);
93  0 item.add(fieldTitle);
94  0 itemsPanel.add(item);
95  0 values.add(curVal);
96    }
97    }
98   
 
99  0 toggle @Override
100    public HandlerRegistration addBlurHandler(BlurHandler handler) {
101  0 return inputText.addBlurHandler(handler);
102    }
103   
 
104  0 toggle public void setFd(FieldDescriptor fd) {
105  0 this.fd = fd;
106    }
107    }