| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.common.ui.client.widgets.suggestbox; |
| 17 |
|
|
| 18 |
|
import java.util.Map; |
| 19 |
|
|
| 20 |
|
import org.kuali.student.common.ui.client.mvc.Callback; |
| 21 |
|
import org.kuali.student.common.ui.client.mvc.TranslatableValueWidget; |
| 22 |
|
import org.kuali.student.common.ui.client.util.UtilConstants; |
| 23 |
|
import org.kuali.student.common.ui.client.widgets.HasWatermark; |
| 24 |
|
import org.kuali.student.common.ui.client.widgets.KSTextBox; |
| 25 |
|
import org.kuali.student.common.ui.client.widgets.list.HasSelectionChangeHandlers; |
| 26 |
|
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent; |
| 27 |
|
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler; |
| 28 |
|
import org.kuali.student.common.ui.client.widgets.suggestbox.IdableSuggestOracle.IdableSuggestion; |
| 29 |
|
|
| 30 |
|
import com.google.gwt.event.dom.client.BlurEvent; |
| 31 |
|
import com.google.gwt.event.dom.client.BlurHandler; |
| 32 |
|
import com.google.gwt.event.logical.shared.SelectionEvent; |
| 33 |
|
import com.google.gwt.event.logical.shared.SelectionHandler; |
| 34 |
|
import com.google.gwt.event.shared.HandlerRegistration; |
| 35 |
|
import com.google.gwt.user.client.ui.SuggestBox; |
| 36 |
|
import com.google.gwt.user.client.ui.SuggestOracle; |
| 37 |
|
|
| 38 |
|
|
|
|
|
| 0% |
Uncovered Elements: 163 (163) |
Complexity: 52 |
Complexity Density: 0.5 |
|
| 39 |
|
public class KSSuggestBox extends SuggestBox implements HasSelectionChangeHandlers, TranslatableValueWidget, HasWatermark{ |
| 40 |
|
|
| 41 |
|
private IdableSuggestion currentSuggestion = null; |
| 42 |
|
private IdableSuggestOracle oracle; |
| 43 |
|
private String currentId = ""; |
| 44 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 45 |
0
|
public KSSuggestBox(IdableSuggestOracle oracle) {... |
| 46 |
0
|
this(oracle, true); |
| 47 |
|
} |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 49 |
0
|
public KSSuggestBox(IdableSuggestOracle oracle, boolean enabled){... |
| 50 |
0
|
super(oracle, new KSTextBox()); |
| 51 |
0
|
super.getTextBox().setEnabled(enabled); |
| 52 |
0
|
this.oracle = oracle; |
| 53 |
0
|
oracle.addSearchCompletedCallback(new Callback<IdableSuggestion>() { |
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 54 |
0
|
@Override... |
| 55 |
|
public void exec(IdableSuggestion result) { |
| 56 |
0
|
currentSuggestion = result; |
| 57 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 58 |
0
|
SelectionChangeEvent.fire(KSSuggestBox.this); |
| 59 |
|
} |
| 60 |
|
}); |
| 61 |
0
|
this.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>(){ |
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 63 |
0
|
@Override... |
| 64 |
|
public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) { |
| 65 |
0
|
currentSuggestion = (IdableSuggestion)(event.getSelectedItem()); |
| 66 |
0
|
getTextBox().setFocus(true); |
| 67 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 68 |
0
|
SelectionChangeEvent.fire(KSSuggestBox.this); |
| 69 |
|
} |
| 70 |
|
}); |
| 71 |
|
|
| 72 |
0
|
this.getTextBox().addBlurHandler(new BlurHandler(){ |
| 73 |
|
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 12 |
Complexity Density: 0.5 |
|
| 74 |
0
|
@Override... |
| 75 |
|
public void onBlur(BlurEvent event) { |
| 76 |
0
|
String currentText = KSSuggestBox.this.getText(); |
| 77 |
0
|
boolean isEmpty = false; |
| 78 |
0
|
if(currentText != null && !currentText.equals("")){ |
| 79 |
0
|
if((currentSuggestion != null && !KSSuggestBox.this.getText().equals(currentSuggestion.getReplacementString())) |
| 80 |
|
|| currentSuggestion == null){ |
| 81 |
0
|
currentSuggestion = KSSuggestBox.this.oracle.getSuggestionByText(currentText); |
| 82 |
|
} |
| 83 |
|
|
| 84 |
0
|
if(currentSuggestion == null){ |
| 85 |
0
|
currentSuggestion = new IdableSuggestion(); |
| 86 |
0
|
String impossibleCharacters = UtilConstants.IMPOSSIBLE_CHARACTERS; |
| 87 |
0
|
currentSuggestion.setId(impossibleCharacters); |
| 88 |
0
|
currentSuggestion.setDisplayString(impossibleCharacters); |
| 89 |
0
|
currentSuggestion.setReplacementString(impossibleCharacters); |
| 90 |
|
} |
| 91 |
|
} |
| 92 |
0
|
else if(currentText == null || currentText.equals("")){ |
| 93 |
0
|
isEmpty = true; |
| 94 |
0
|
currentId = ""; |
| 95 |
0
|
currentSuggestion = new IdableSuggestion(); |
| 96 |
0
|
currentSuggestion.setId(""); |
| 97 |
0
|
currentSuggestion.setDisplayString(""); |
| 98 |
0
|
currentSuggestion.setReplacementString(""); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
0
|
if(!KSSuggestBox.this.getSelectedId().equals(currentId)){ |
| 102 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 103 |
0
|
if(isEmpty){ |
| 104 |
0
|
currentId = ""; |
| 105 |
|
} |
| 106 |
0
|
if (!currentId.equals(UtilConstants.IMPOSSIBLE_CHARACTERS)) { |
| 107 |
0
|
SelectionChangeEvent.fire(KSSuggestBox.this); |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
|
}); |
| 112 |
|
} |
| 113 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 114 |
0
|
public void reset(){... |
| 115 |
0
|
this.setText(""); |
| 116 |
0
|
currentSuggestion = null; |
| 117 |
|
} |
| 118 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 119 |
0
|
public IdableSuggestion getSelectedSuggestion() {... |
| 120 |
0
|
return currentSuggestion; |
| 121 |
|
} |
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 6 |
Complexity Density: 1 |
|
| 123 |
0
|
public String getSelectedId() {... |
| 124 |
0
|
String id = ""; |
| 125 |
0
|
if(currentSuggestion != null){ |
| 126 |
0
|
id = currentSuggestion.getId(); |
| 127 |
|
} |
| 128 |
0
|
if(currentId!=null && !currentId.isEmpty() && (id==null || id.isEmpty())){ |
| 129 |
0
|
id = UtilConstants.IMPOSSIBLE_CHARACTERS; |
| 130 |
|
} |
| 131 |
0
|
return id; |
| 132 |
|
} |
| 133 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
0
|
public IdableSuggestOracle getOracle() {... |
| 135 |
0
|
return oracle; |
| 136 |
|
} |
| 137 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 138 |
0
|
@Override... |
| 139 |
|
public String getValue() { |
| 140 |
0
|
return this.getSelectedId(); |
| 141 |
|
} |
| 142 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 143 |
0
|
@Override... |
| 144 |
|
public void setValue(String id) { |
| 145 |
0
|
if(id == null || id.equals("")){ |
| 146 |
0
|
currentSuggestion = new IdableSuggestion(); |
| 147 |
0
|
currentSuggestion.setId(""); |
| 148 |
0
|
currentSuggestion.setDisplayString(""); |
| 149 |
0
|
currentSuggestion.setReplacementString(""); |
| 150 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 151 |
0
|
KSSuggestBox.this.setText(""); |
| 152 |
|
} |
| 153 |
|
else |
| 154 |
|
{ |
| 155 |
0
|
oracle.getSuggestionByIdSearch(id, new Callback<IdableSuggestion>(){ |
| 156 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 157 |
0
|
@Override... |
| 158 |
|
public void exec(IdableSuggestion result) { |
| 159 |
0
|
currentSuggestion = result; |
| 160 |
0
|
KSSuggestBox.this.setText((currentSuggestion == null) ? "" : currentSuggestion.getReplacementString()); |
| 161 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 162 |
|
} |
| 163 |
|
}); |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 167 |
0
|
public void setValue(String id, final Callback<IdableSuggestion> callback) {... |
| 168 |
0
|
if(id == null || id.equals("")){ |
| 169 |
0
|
currentSuggestion = new IdableSuggestion(); |
| 170 |
0
|
currentSuggestion.setId(""); |
| 171 |
0
|
currentSuggestion.setDisplayString(""); |
| 172 |
0
|
currentSuggestion.setReplacementString(""); |
| 173 |
0
|
KSSuggestBox.this.setText(""); |
| 174 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 175 |
0
|
callback.exec(currentSuggestion); |
| 176 |
|
} |
| 177 |
|
else |
| 178 |
|
{ |
| 179 |
0
|
oracle.getSuggestionByIdSearch(id, new Callback<IdableSuggestion>(){ |
| 180 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 181 |
0
|
@Override... |
| 182 |
|
public void exec(IdableSuggestion result) { |
| 183 |
0
|
currentSuggestion = result; |
| 184 |
0
|
KSSuggestBox.this.setText((currentSuggestion == null) ? "" : currentSuggestion.getReplacementString()); |
| 185 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 186 |
0
|
callback.exec(currentSuggestion); |
| 187 |
|
} |
| 188 |
|
}); |
| 189 |
|
} |
| 190 |
|
} |
| 191 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 192 |
0
|
public void setValue(String id, String translation) {... |
| 193 |
0
|
currentSuggestion = new IdableSuggestion(); |
| 194 |
0
|
currentSuggestion.setId(id); |
| 195 |
0
|
currentSuggestion.setDisplayString(translation); |
| 196 |
0
|
currentSuggestion.setReplacementString(translation); |
| 197 |
0
|
KSSuggestBox.this.setText(translation); |
| 198 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 199 |
|
} |
| 200 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 201 |
0
|
@Override... |
| 202 |
|
public void setValue(String id, boolean fireEvents) { |
| 203 |
0
|
if(fireEvents == true){ |
| 204 |
|
|
| 205 |
0
|
if(id == null || id.equals("")){ |
| 206 |
0
|
currentSuggestion = new IdableSuggestion(); |
| 207 |
0
|
currentSuggestion.setId(""); |
| 208 |
0
|
currentSuggestion.setDisplayString(""); |
| 209 |
0
|
currentSuggestion.setReplacementString(""); |
| 210 |
0
|
KSSuggestBox.this.setText(""); |
| 211 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 212 |
|
} |
| 213 |
|
else |
| 214 |
|
{ |
| 215 |
0
|
oracle.getSuggestionByIdSearch(id, new Callback<IdableSuggestion>(){ |
| 216 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 217 |
0
|
@Override... |
| 218 |
|
public void exec(IdableSuggestion result) { |
| 219 |
0
|
currentSuggestion = result; |
| 220 |
0
|
KSSuggestBox.this.setText((currentSuggestion == null) ? "" : currentSuggestion.getReplacementString()); |
| 221 |
0
|
if(!KSSuggestBox.this.getSelectedId().equals(currentId)){ |
| 222 |
0
|
SelectionChangeEvent.fire(KSSuggestBox.this); |
| 223 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
}); |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
} |
| 230 |
|
else |
| 231 |
|
{ |
| 232 |
0
|
this.setValue(id); |
| 233 |
|
} |
| 234 |
|
|
| 235 |
|
} |
| 236 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 237 |
0
|
public void setValue(IdableSuggestion theSuggestion) {... |
| 238 |
0
|
currentSuggestion = theSuggestion; |
| 239 |
0
|
SelectionChangeEvent.fire(KSSuggestBox.this); |
| 240 |
0
|
KSSuggestBox.this.setText((currentSuggestion == null) ? "" : currentSuggestion.getReplacementString()); |
| 241 |
0
|
currentId = KSSuggestBox.this.getSelectedId(); |
| 242 |
|
} |
| 243 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 244 |
0
|
@Override... |
| 245 |
|
public HandlerRegistration addSelectionChangeHandler( |
| 246 |
|
SelectionChangeHandler handler) { |
| 247 |
0
|
return addHandler(handler, SelectionChangeEvent.getType()); |
| 248 |
|
} |
| 249 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 250 |
0
|
public IdableSuggestion getCurrentSuggestion() {... |
| 251 |
0
|
return currentSuggestion; |
| 252 |
|
} |
| 253 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 254 |
0
|
@Override... |
| 255 |
|
public void setValue(Map<String, String> translations) { |
| 256 |
|
|
| 257 |
|
|
| 258 |
|
} |
| 259 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 260 |
0
|
@Override... |
| 261 |
|
public void setWatermarkText(String text) { |
| 262 |
0
|
((KSTextBox)super.getTextBox()).setWatermarkText(text); |
| 263 |
|
} |
| 264 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 265 |
0
|
@Override... |
| 266 |
|
public boolean hasWatermark(){ |
| 267 |
0
|
return ((KSTextBox)super.getTextBox()).hasWatermark(); |
| 268 |
|
} |
| 269 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 270 |
0
|
@Override... |
| 271 |
|
public boolean watermarkShowing() { |
| 272 |
0
|
return ((KSTextBox)super.getTextBox()).hasWatermark(); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
} |