1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
package org.kuali.student.common.ui.client.widgets; |
14 |
|
|
15 |
|
import org.kuali.student.common.assembly.data.Metadata; |
16 |
|
import org.kuali.student.common.assembly.data.MetadataInterrogator; |
17 |
|
import org.kuali.student.common.ui.client.application.Application; |
18 |
|
import org.kuali.student.common.ui.client.configurable.mvc.DefaultWidgetFactory; |
19 |
|
|
20 |
|
import com.google.gwt.event.dom.client.BlurHandler; |
21 |
|
import com.google.gwt.event.dom.client.HasBlurHandlers; |
22 |
|
import com.google.gwt.event.dom.client.KeyUpEvent; |
23 |
|
import com.google.gwt.event.dom.client.KeyUpHandler; |
24 |
|
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
25 |
|
import com.google.gwt.event.logical.shared.ValueChangeHandler; |
26 |
|
import com.google.gwt.event.shared.HandlerRegistration; |
27 |
|
import com.google.gwt.user.client.ui.Composite; |
28 |
|
import com.google.gwt.user.client.ui.HasText; |
29 |
|
import com.google.gwt.user.client.ui.TextBoxBase; |
30 |
|
import com.google.gwt.user.client.ui.VerticalPanel; |
31 |
|
import com.google.gwt.user.client.ui.Widget; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 55 (55) |
Complexity: 19 |
Complexity Density: 0.58 |
|
33 |
|
public class KSCharCount extends Composite implements HasText, HasInputWidget, HasBlurHandlers { |
34 |
|
VerticalPanel countingPanel; |
35 |
|
Widget inputWidget; |
36 |
|
KSLabel countingLabel; |
37 |
|
|
38 |
|
private int maxLength; |
39 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
40 |
0
|
public KSCharCount() {}... |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
42 |
0
|
public KSCharCount(Metadata metadata) {... |
43 |
0
|
countingPanel = new VerticalPanel(); |
44 |
0
|
countingLabel = new KSLabel(); |
45 |
0
|
super.initWidget(countingPanel); |
46 |
0
|
this.setWidget(DefaultWidgetFactory.getInstance().getWidget(metadata)); |
47 |
0
|
this.setMaxLength(metadata); |
48 |
|
|
49 |
0
|
if (this.inputWidget instanceof TextBoxBase) { |
50 |
0
|
((TextBoxBase) (this.inputWidget)).addKeyUpHandler(new KeyUpHandler() { |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0
|
@Override... |
53 |
|
public void onKeyUp(KeyUpEvent event) { |
54 |
0
|
countingLabel.setText(setLabel()); |
55 |
|
|
56 |
|
} |
57 |
|
}); |
58 |
|
|
59 |
0
|
((TextBoxBase) (this.inputWidget)).addValueChangeHandler(new ValueChangeHandler<String>() { |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
0
|
@Override... |
62 |
|
public void onValueChange(ValueChangeEvent<String> event) { |
63 |
0
|
countingLabel.setText(setLabel()); |
64 |
|
|
65 |
|
} |
66 |
|
|
67 |
|
}); |
68 |
|
} |
69 |
|
|
70 |
0
|
countingLabel.setStyleName("ks-form-module-elements-help-text"); |
71 |
0
|
countingLabel.setText(this.setLabel()); |
72 |
0
|
countingPanel.add(inputWidget); |
73 |
0
|
countingPanel.add(countingLabel); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0
|
public void setMaxLength(Metadata metadata) {... |
77 |
0
|
this.maxLength = MetadataInterrogator.getSmallestMaxLength(metadata); |
78 |
|
} |
79 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
80 |
0
|
public void setWidget(Widget widget) {... |
81 |
0
|
if (widget instanceof TextBoxBase) { |
82 |
0
|
this.inputWidget = widget; |
83 |
|
} else { |
84 |
0
|
this.inputWidget = new KSTextBox(); |
85 |
|
} |
86 |
|
|
87 |
|
} |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
89 |
0
|
public int getRemCount() {... |
90 |
0
|
int rem = 0; |
91 |
|
|
92 |
0
|
if ((this.getText() != null) && (this.getText().length() <= maxLength)) { |
93 |
0
|
rem = this.maxLength - ((TextBoxBase) (this.inputWidget)).getText().length(); |
94 |
|
} |
95 |
0
|
if (this.getText() == null) { |
96 |
0
|
rem = this.maxLength; |
97 |
|
} |
98 |
|
|
99 |
0
|
return rem; |
100 |
|
} |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
102 |
0
|
public String setLabel() {... |
103 |
0
|
int rem = getRemCount(); |
104 |
|
|
105 |
0
|
if ((rem <= (this.maxLength * 0.1)) || (rem <= 10)) { |
106 |
0
|
countingLabel.getElement().setAttribute("style", "color: red;"); |
107 |
|
} else { |
108 |
0
|
countingLabel.getElement().removeAttribute("style"); |
109 |
|
} |
110 |
|
|
111 |
0
|
return (rem + " " + Application.getApplicationContext().getUILabel("common", "remainingChars")); |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0
|
@Override... |
115 |
|
public String getText() { |
116 |
0
|
return ((TextBoxBase) (this.inputWidget)).getText(); |
117 |
|
} |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
0
|
@Override... |
120 |
|
public void setText(String text) { |
121 |
0
|
((TextBoxBase) (this.inputWidget)).setText(text); |
122 |
|
|
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
0
|
@Override... |
126 |
|
public Widget getInputWidget() { |
127 |
0
|
return this.inputWidget; |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0
|
@Override... |
131 |
|
public HandlerRegistration addBlurHandler(BlurHandler handler) { |
132 |
0
|
return ((TextBoxBase) (this.inputWidget)).addBlurHandler(handler); |
133 |
|
} |
134 |
|
|
135 |
|
} |