| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 15 |
Complexity Density: 0.39 |
|
| 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(); |
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 33 |
0
|
public ListOfStringWidget(String addItemText) {... |
| 34 |
0
|
super(); |
| 35 |
0
|
super.initWidget(mainPanel); |
| 36 |
0
|
this.addItemText = addItemText; |
| 37 |
|
} |
| 38 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 39 |
0
|
public void onLoad() {... |
| 40 |
0
|
if (!loaded) { |
| 41 |
0
|
KSButton addItemButton = new KSButton(addItemText); |
| 42 |
0
|
addItemButton.addClickHandler(new ClickHandler(){ |
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 43 |
0
|
public void onClick(ClickEvent event) {... |
| 44 |
|
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
0
|
public ArrayList<String> getStringValues(){... |
| 65 |
0
|
return values; |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 68 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
| 77 |
0
|
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() { |
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 87 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
0
|
@Override... |
| 100 |
|
public HandlerRegistration addBlurHandler(BlurHandler handler) { |
| 101 |
0
|
return inputText.addBlurHandler(handler); |
| 102 |
|
} |
| 103 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 104 |
0
|
public void setFd(FieldDescriptor fd) {... |
| 105 |
0
|
this.fd = fd; |
| 106 |
|
} |
| 107 |
|
} |