| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.common.ui.client.widgets.list; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.ArrayList; | 
  | 19 |  |  import java.util.HashSet; | 
  | 20 |  |  import java.util.Iterator; | 
  | 21 |  |  import java.util.List; | 
  | 22 |  |  import java.util.Map; | 
  | 23 |  |  import java.util.Map.Entry; | 
  | 24 |  |   | 
  | 25 |  |  import org.kuali.student.common.assembly.data.Data; | 
  | 26 |  |  import org.kuali.student.common.assembly.data.Data.DataValue; | 
  | 27 |  |  import org.kuali.student.common.assembly.data.Data.Property; | 
  | 28 |  |  import org.kuali.student.common.assembly.data.Data.StringKey; | 
  | 29 |  |  import org.kuali.student.common.assembly.data.Data.Value; | 
  | 30 |  |  import org.kuali.student.common.ui.client.configurable.mvc.WidgetConfigInfo; | 
  | 31 |  |  import org.kuali.student.common.ui.client.mvc.Callback; | 
  | 32 |  |  import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; | 
  | 33 |  |  import org.kuali.student.common.ui.client.mvc.HasDataValue; | 
  | 34 |  |  import org.kuali.student.common.ui.client.mvc.HasFocusLostCallbacks; | 
  | 35 |  |  import org.kuali.student.common.ui.client.mvc.HasWidgetReadyCallback; | 
  | 36 |  |  import org.kuali.student.common.ui.client.mvc.TranslatableValueWidget; | 
  | 37 |  |  import org.kuali.student.common.ui.client.util.UtilConstants; | 
  | 38 |  |  import org.kuali.student.common.ui.client.widgets.DataHelper; | 
  | 39 |  |  import org.kuali.student.common.ui.client.widgets.HasInputWidget; | 
  | 40 |  |  import org.kuali.student.common.ui.client.widgets.KSButton; | 
  | 41 |  |  import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; | 
  | 42 |  |  import org.kuali.student.common.ui.client.widgets.KSDropDown; | 
  | 43 |  |  import org.kuali.student.common.ui.client.widgets.KSItemLabel; | 
  | 44 |  |  import org.kuali.student.common.ui.client.widgets.field.layout.element.ValidationProcessable; | 
  | 45 |  |  import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; | 
  | 46 |  |  import org.kuali.student.common.ui.client.widgets.menus.KSListPanel; | 
  | 47 |  |  import org.kuali.student.common.ui.client.widgets.menus.KSListPanel.ListType; | 
  | 48 |  |  import org.kuali.student.common.ui.client.widgets.search.KSPicker; | 
  | 49 |  |  import org.kuali.student.common.ui.client.widgets.search.SelectedResults; | 
  | 50 |  |  import org.kuali.student.common.ui.client.widgets.suggestbox.KSSuggestBox; | 
  | 51 |  |  import org.kuali.student.common.validation.dto.ValidationResultInfo; | 
  | 52 |  |  import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel; | 
  | 53 |  |   | 
  | 54 |  |  import com.google.gwt.event.dom.client.ClickEvent; | 
  | 55 |  |  import com.google.gwt.event.dom.client.ClickHandler; | 
  | 56 |  |  import com.google.gwt.event.logical.shared.CloseEvent; | 
  | 57 |  |  import com.google.gwt.event.logical.shared.CloseHandler; | 
  | 58 |  |  import com.google.gwt.event.shared.HandlerRegistration; | 
  | 59 |  |  import com.google.gwt.user.client.Timer; | 
  | 60 |  |  import com.google.gwt.user.client.ui.Composite; | 
  | 61 |  |  import com.google.gwt.user.client.ui.HasName; | 
  | 62 |  |  import com.google.gwt.user.client.ui.HorizontalPanel; | 
  | 63 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 64 |  |   | 
  | 65 | 0 |  public class KSSelectedList extends Composite implements HasDataValue, HasName, HasSelectionChangeHandlers, | 
  | 66 |  |          HasWidgetReadyCallback, TranslatableValueWidget, HasInputWidget, HasFocusLostCallbacks, HasCrossConstraints, | 
  | 67 |  |          ValidationProcessable { | 
  | 68 |  |      private static final String VALUE = "value"; | 
  | 69 |  |      private static final String DISPLAY = "display"; | 
  | 70 |  |   | 
  | 71 |  |      private String name; | 
  | 72 |  |      private boolean initialized; | 
  | 73 |  |      private VerticalFlowPanel mainPanel; | 
  | 74 |  |      private HorizontalPanel pickerPanel; | 
  | 75 |  |      private KSPicker picker; | 
  | 76 |  |      private KSButton addItemButton; | 
  | 77 |  |      private KSListPanel valuesPanel; | 
  | 78 |  |       | 
  | 79 |  |       | 
  | 80 |  |   | 
  | 81 | 0 |      private List<KSItemLabel> selectedItems = new ArrayList<KSItemLabel>(); | 
  | 82 | 0 |      private List<KSItemLabel> removedItems = new ArrayList<KSItemLabel>(); | 
  | 83 | 0 |      public static ItemDataHelper itemDataHelper = new ItemDataHelper(); | 
  | 84 |  |   | 
  | 85 | 0 |      private final List<SelectionChangeHandler> selectionChangeHandlers = new ArrayList<SelectionChangeHandler>(); | 
  | 86 | 0 |      private final List<Callback<Widget>> widgetReadyCallbacks = new ArrayList<Callback<Widget>>(); | 
  | 87 | 0 |      private boolean hasDetails = false; | 
  | 88 |  |   | 
  | 89 |  |      private WidgetConfigInfo config; | 
  | 90 |  |   | 
  | 91 | 0 |      public KSSelectedList(WidgetConfigInfo config, boolean hasDetails) { | 
  | 92 | 0 |          init(config, hasDetails); | 
  | 93 | 0 |      } | 
  | 94 |  |   | 
  | 95 | 0 |      public KSSelectedList(WidgetConfigInfo config) { | 
  | 96 | 0 |          init(config, false); | 
  | 97 | 0 |      } | 
  | 98 |  |   | 
  | 99 |  |      public WidgetConfigInfo getConfig() { | 
  | 100 | 0 |          return config; | 
  | 101 |  |      } | 
  | 102 |  |   | 
  | 103 |  |      private void init(WidgetConfigInfo config, final boolean hasDetails) { | 
  | 104 | 0 |          this.config = config; | 
  | 105 | 0 |          this.hasDetails = hasDetails; | 
  | 106 | 0 |          mainPanel = new VerticalFlowPanel(); | 
  | 107 | 0 |          initWidget(mainPanel); | 
  | 108 | 0 |          if (config.canEdit) { | 
  | 109 | 0 |              pickerPanel = new HorizontalPanel(); | 
  | 110 | 0 |              pickerPanel.addStyleName("ks-selected-list-picker"); | 
  | 111 | 0 |              addItemButton = new KSButton("Add to list", ButtonStyle.SECONDARY_SMALL); | 
  | 112 | 0 |              addItemButton.setEnabled(false); | 
  | 113 | 0 |              picker = new KSPicker(config); | 
  | 114 | 0 |              picker.setAdvancedSearchCallback(createAdvancedSearchCallback()); | 
  | 115 | 0 |              addSelectionChangeHandler(); | 
  | 116 |  |   | 
  | 117 | 0 |              addItemButton.addClickHandler(new ClickHandler() { | 
  | 118 |  |                  @Override | 
  | 119 |  |                  public void onClick(ClickEvent event) { | 
  | 120 | 0 |                      Value v = picker.getValue(); | 
  | 121 | 0 |                      if (v instanceof DataValue) { | 
  | 122 | 0 |                          Data d = ((DataValue) picker.getValue()).get(); | 
  | 123 |  |   | 
  | 124 | 0 |                          Iterator<Property> iter = d.realPropertyIterator(); | 
  | 125 | 0 |                          while (iter.hasNext()) { | 
  | 126 | 0 |                              Property p = iter.next(); | 
  | 127 | 0 |                              String s = p.getValue(); | 
  | 128 | 0 |                              KSItemLabel selectedItem = createItem(s, picker.getDisplayValue(), | 
  | 129 |  |                                      hasDetails); | 
  | 130 | 0 |                              addItem(selectedItem); | 
  | 131 | 0 |                          } | 
  | 132 | 0 |                      } else { | 
  | 133 | 0 |                          String s = v.get(); | 
  | 134 | 0 |                          KSItemLabel selectedItem = createItem(s, picker.getDisplayValue(), | 
  | 135 |  |                                      hasDetails); | 
  | 136 | 0 |                          addItem(selectedItem); | 
  | 137 |  |                      } | 
  | 138 | 0 |                      picker.clear(); | 
  | 139 | 0 |                      addItemButton.setEnabled(false); | 
  | 140 | 0 |                  } | 
  | 141 |  |              }); | 
  | 142 |  |   | 
  | 143 | 0 |              pickerPanel.add(picker); | 
  | 144 | 0 |              pickerPanel.add(addItemButton); | 
  | 145 |  |   | 
  | 146 | 0 |              mainPanel.add(pickerPanel); | 
  | 147 |  |          } | 
  | 148 |  |   | 
  | 149 | 0 |          valuesPanel = new KSListPanel(ListType.UNORDERED); | 
  | 150 | 0 |          if (config.canEdit) { | 
  | 151 | 0 |              valuesPanel.setStyleName("ks-selected-list"); | 
  | 152 |  |          } else { | 
  | 153 | 0 |              valuesPanel.setStyleName("ks-selected-list-readOnly"); | 
  | 154 |  |          } | 
  | 155 | 0 |          mainPanel.add(valuesPanel); | 
  | 156 | 0 |          initialized = true; | 
  | 157 | 0 |          widgetReady(); | 
  | 158 | 0 |      } | 
  | 159 |  |   | 
  | 160 |  |      public KSListPanel separateValuesPanel() { | 
  | 161 | 0 |          mainPanel.remove(valuesPanel); | 
  | 162 | 0 |          return valuesPanel; | 
  | 163 |  |      } | 
  | 164 |  |   | 
  | 165 |  |      private void widgetReady() { | 
  | 166 | 0 |          for (Callback<Widget> callback : widgetReadyCallbacks) { | 
  | 167 | 0 |              callback.exec(this); | 
  | 168 |  |          } | 
  | 169 | 0 |      } | 
  | 170 |  |   | 
  | 171 |  |      private Callback<List<SelectedResults>> createAdvancedSearchCallback() { | 
  | 172 | 0 |          Callback<List<SelectedResults>> result = new Callback<List<SelectedResults>>() { | 
  | 173 |  |              public void exec(List<SelectedResults> results) { | 
  | 174 | 0 |                  if (results.size() > 0) { | 
  | 175 | 0 |                      for (SelectedResults res : results) { | 
  | 176 | 0 |                          KSItemLabel item = createItem(res.getReturnKey(), res.getDisplayKey(), hasDetails); | 
  | 177 | 0 |                          addItem(item, false); | 
  | 178 | 0 |                      } | 
  | 179 | 0 |                      picker.clear(); | 
  | 180 | 0 |                      addItemButton.setEnabled(false); | 
  | 181 | 0 |                      selectionChanged(); | 
  | 182 |  |                  } | 
  | 183 | 0 |              } | 
  | 184 |  |   | 
  | 185 |  |          }; | 
  | 186 | 0 |          return result; | 
  | 187 |  |      } | 
  | 188 |  |   | 
  | 189 |  |       | 
  | 190 |  |   | 
  | 191 |  |   | 
  | 192 |  |   | 
  | 193 |  |      private void addSelectionChangeHandler() { | 
  | 194 | 0 |          if (picker.getInputWidget() instanceof KSSuggestBox) { | 
  | 195 | 0 |              KSSuggestBox suggestBox = (KSSuggestBox) picker.getInputWidget(); | 
  | 196 | 0 |              suggestBox.addSelectionChangeHandler(new SelectionChangeHandler() { | 
  | 197 |  |                  @Override | 
  | 198 |  |                  public void onSelectionChange(SelectionChangeEvent event) { | 
  | 199 |  |                       | 
  | 200 |  |                       | 
  | 201 |  |                       | 
  | 202 |  |                       | 
  | 203 |  |                       | 
  | 204 | 0 |                      String userValue = ((KSSuggestBox) picker.getInputWidget()).getText(); | 
  | 205 | 0 |                      String displayValue = picker.getDisplayValue(); | 
  | 206 | 0 |                      boolean enabled = displayValue != null && !displayValue.isEmpty() && displayValue.equals(userValue); | 
  | 207 | 0 |                      addItemButton.setEnabled(enabled); | 
  | 208 | 0 |                  } | 
  | 209 |  |              }); | 
  | 210 | 0 |          } else if (picker.getInputWidget() instanceof KSDropDown) { | 
  | 211 | 0 |              KSDropDown dropDown = (KSDropDown) picker.getInputWidget(); | 
  | 212 | 0 |              dropDown.addSelectionChangeHandler(new SelectionChangeHandler() { | 
  | 213 |  |                  @Override | 
  | 214 |  |                  public void onSelectionChange(SelectionChangeEvent event) { | 
  | 215 |  |                       | 
  | 216 | 0 |                      String displayValue = picker.getDisplayValue(); | 
  | 217 | 0 |                      boolean enabled = displayValue != null && !displayValue.isEmpty(); | 
  | 218 | 0 |                      addItemButton.setEnabled(enabled); | 
  | 219 | 0 |                  } | 
  | 220 |  |              }); | 
  | 221 |  |          } | 
  | 222 | 0 |      } | 
  | 223 |  |   | 
  | 224 |  |      public void addItem(String value, String display) { | 
  | 225 | 0 |          addItem(createItem(value, display, hasDetails)); | 
  | 226 | 0 |      } | 
  | 227 |  |   | 
  | 228 |  |      public void addItem(final KSItemLabel item) { | 
  | 229 | 0 |          addItem(item, true); | 
  | 230 | 0 |      } | 
  | 231 |  |   | 
  | 232 |  |      public void addItem(final KSItemLabel item, boolean fireChangeListeners) { | 
  | 233 | 0 |          if (removedItems.contains(item)) { | 
  | 234 | 0 |              removedItems.remove(item); | 
  | 235 |  |          } | 
  | 236 | 0 |          if (!selectedItems.contains(item)) { | 
  | 237 | 0 |              selectedItems.add(item); | 
  | 238 |  |   | 
  | 239 | 0 |              valuesPanel.add(item); | 
  | 240 | 0 |              if (fireChangeListeners) { | 
  | 241 | 0 |                  selectionChanged(); | 
  | 242 |  |              } | 
  | 243 | 0 |              if (config.canEdit && fireChangeListeners) { | 
  | 244 | 0 |                  item.setHighlighted(true); | 
  | 245 | 0 |                  new Timer() { | 
  | 246 |  |                      @Override | 
  | 247 |  |                      public void run() { | 
  | 248 | 0 |                          item.setHighlighted(false); | 
  | 249 | 0 |                      } | 
  | 250 |  |                  }.schedule(5000); | 
  | 251 |  |              } else { | 
  | 252 | 0 |                  item.removeHighlight(); | 
  | 253 |  |              } | 
  | 254 |  |          } | 
  | 255 | 0 |      } | 
  | 256 |  |   | 
  | 257 |  |      private void selectionChanged() { | 
  | 258 | 0 |          for (SelectionChangeHandler handler : selectionChangeHandlers) { | 
  | 259 | 0 |              handler.onSelectionChange(new SelectionChangeEvent(this)); | 
  | 260 |  |          } | 
  | 261 | 0 |      } | 
  | 262 |  |   | 
  | 263 |  |      public void clear() { | 
  | 264 | 0 |          selectedItems = new ArrayList<KSItemLabel>(); | 
  | 265 | 0 |          removedItems = new ArrayList<KSItemLabel>(); | 
  | 266 | 0 |          valuesPanel.clear(); | 
  | 267 | 0 |      } | 
  | 268 |  |   | 
  | 269 |  |      @Override | 
  | 270 |  |      public String getName() { | 
  | 271 |  |   | 
  | 272 | 0 |          return name; | 
  | 273 |  |      } | 
  | 274 |  |   | 
  | 275 |  |      @Override | 
  | 276 |  |      public void setName(String name) { | 
  | 277 | 0 |          this.name = name; | 
  | 278 | 0 |      } | 
  | 279 |  |   | 
  | 280 |  |      @Override | 
  | 281 |  |      public HandlerRegistration addSelectionChangeHandler(final SelectionChangeHandler handler) { | 
  | 282 | 0 |          selectionChangeHandlers.add(handler); | 
  | 283 | 0 |          HandlerRegistration result = new HandlerRegistration() { | 
  | 284 |  |              @Override | 
  | 285 |  |              public void removeHandler() { | 
  | 286 | 0 |                  selectionChangeHandlers.remove(handler); | 
  | 287 | 0 |              } | 
  | 288 |  |          }; | 
  | 289 | 0 |          return result; | 
  | 290 |  |      } | 
  | 291 |  |   | 
  | 292 |  |      @Override | 
  | 293 |  |      public void addWidgetReadyCallback(Callback<Widget> callback) { | 
  | 294 | 0 |          widgetReadyCallbacks.add(callback); | 
  | 295 | 0 |      } | 
  | 296 |  |   | 
  | 297 |  |      @Override | 
  | 298 |  |      public boolean isInitialized() { | 
  | 299 | 0 |          return initialized; | 
  | 300 |  |      } | 
  | 301 |  |   | 
  | 302 |  |      @Override | 
  | 303 |  |      public void setInitialized(boolean initialized) { | 
  | 304 | 0 |          this.initialized = initialized; | 
  | 305 | 0 |      } | 
  | 306 |  |   | 
  | 307 |  |      @Override | 
  | 308 |  |      public void addValueChangeCallback(Callback<Value> callback) { | 
  | 309 |  |           | 
  | 310 |  |   | 
  | 311 | 0 |      } | 
  | 312 |  |   | 
  | 313 |  |      @Override | 
  | 314 |  |      public Value getValue() { | 
  | 315 | 0 |          Data data = new Data(); | 
  | 316 | 0 |          for (KSItemLabel item : selectedItems) { | 
  | 317 | 0 |              data.add(item.getKey()); | 
  | 318 |  |          } | 
  | 319 | 0 |          if (picker.getDisplayValue().equals(UtilConstants.IMPOSSIBLE_CHARACTERS)) { | 
  | 320 | 0 |              data.add(UtilConstants.IMPOSSIBLE_CHARACTERS); | 
  | 321 |  |          } | 
  | 322 | 0 |          DataValue result = new DataValue(data); | 
  | 323 | 0 |          return result; | 
  | 324 |  |      } | 
  | 325 |  |   | 
  | 326 |  |      public List<KSItemLabel> getSelectedItems() { | 
  | 327 | 0 |          return selectedItems; | 
  | 328 |  |      } | 
  | 329 |  |   | 
  | 330 |  |       | 
  | 331 |  |   | 
  | 332 |  |   | 
  | 333 |  |   | 
  | 334 |  |   | 
  | 335 |  |      public Value getValueWithTranslations() { | 
  | 336 | 0 |          Data data = new Data(); | 
  | 337 | 0 |          Data _runtimeData = new Data(); | 
  | 338 |  |   | 
  | 339 | 0 |          for (KSItemLabel item : selectedItems) { | 
  | 340 | 0 |              data.add(item.getKey()); | 
  | 341 | 0 |              Data displayData = new Data(); | 
  | 342 | 0 |              displayData.set("id-translation", item.getDisplayText()); | 
  | 343 | 0 |              _runtimeData.add(displayData); | 
  | 344 | 0 |          } | 
  | 345 | 0 |          if (picker.getDisplayValue().equals(UtilConstants.IMPOSSIBLE_CHARACTERS)) { | 
  | 346 | 0 |              data.add(UtilConstants.IMPOSSIBLE_CHARACTERS); | 
  | 347 | 0 |              Data displayData = new Data(); | 
  | 348 | 0 |              displayData.set("id-translation", UtilConstants.IMPOSSIBLE_CHARACTERS); | 
  | 349 | 0 |              _runtimeData.add(displayData); | 
  | 350 |  |          } | 
  | 351 | 0 |          data.set(new StringKey("_runtimeData"), _runtimeData); | 
  | 352 | 0 |          DataValue result = new DataValue(data); | 
  | 353 | 0 |          return result; | 
  | 354 |  |      } | 
  | 355 |  |   | 
  | 356 |  |      private KSItemLabel createItem(String value, String display, boolean hasDetails) { | 
  | 357 | 0 |          Data itemData = toItemData(value, display); | 
  | 358 | 0 |          DataValue itemDataValue = new DataValue(itemData); | 
  | 359 | 0 |          KSItemLabel item = new KSItemLabel(KSSelectedList.this.config.canEdit, hasDetails, | 
  | 360 |  |                  itemDataHelper); | 
  | 361 | 0 |          item.setValue(itemDataValue); | 
  | 362 | 0 |          item.addCloseHandler(new CloseHandler<KSItemLabel>() { | 
  | 363 |  |              @Override | 
  | 364 |  |              public void onClose(CloseEvent<KSItemLabel> event) { | 
  | 365 | 0 |                  KSItemLabel itemToBeDeleted = event.getTarget(); | 
  | 366 | 0 |                  selectedItems.remove(itemToBeDeleted); | 
  | 367 | 0 |                  removedItems.add(itemToBeDeleted); | 
  | 368 | 0 |                  valuesPanel.remove(itemToBeDeleted); | 
  | 369 | 0 |                  selectionChanged(); | 
  | 370 | 0 |              } | 
  | 371 |  |          }); | 
  | 372 | 0 |          return item; | 
  | 373 |  |      } | 
  | 374 |  |   | 
  | 375 |  |      private Data toItemData(String value, String display) { | 
  | 376 | 0 |          Data data = new Data(); | 
  | 377 | 0 |          data.set(VALUE, value); | 
  | 378 | 0 |          data.set(DISPLAY, display); | 
  | 379 | 0 |          return data; | 
  | 380 |  |      } | 
  | 381 |  |   | 
  | 382 |  |      @Override | 
  | 383 |  |      public void setValue(Value value) { | 
  | 384 | 0 |          clear(); | 
  | 385 | 0 |          if (value != null) { | 
  | 386 |  |              try { | 
  | 387 | 0 |                  if (value instanceof DataValue) { | 
  | 388 | 0 |                      Data data = ((DataValue) value).get(); | 
  | 389 | 0 |                      Iterator<Property> iter = data.realPropertyIterator(); | 
  | 390 | 0 |                      while (iter.hasNext()) { | 
  | 391 | 0 |                          Property p = iter.next(); | 
  | 392 | 0 |                          setSingleValue(p.getValue()); | 
  | 393 | 0 |                      } | 
  | 394 | 0 |                  } else { | 
  | 395 | 0 |                      setSingleValue(value.get()); | 
  | 396 |  |                  } | 
  | 397 | 0 |              } catch (ClassCastException cce) { | 
  | 398 | 0 |                  String errorMsg = "ClassCastException in KSSelectedList.java::setValue \n " + | 
  | 399 |  |                                      "Trying to cast Value from: " + value.getClass().getName() + "\n " + | 
  | 400 |  |                                      "TO DataValue.java. \n Value was of type " + value.getType().getName() + "\n "; | 
  | 401 |  |                  try { | 
  | 402 | 0 |                      errorMsg += "Value=[" + value.get().toString() + "]"; | 
  | 403 | 0 |                  } catch (Exception ex) { | 
  | 404 | 0 |                      errorMsg += "Error printing error value: " + ex.getMessage(); | 
  | 405 | 0 |                  } | 
  | 406 |  |   | 
  | 407 | 0 |                  throw new ClassCastException(errorMsg); | 
  | 408 | 0 |              } | 
  | 409 |  |          } | 
  | 410 | 0 |      } | 
  | 411 |  |   | 
  | 412 |  |      private void setSingleValue(Object pVal) { | 
  | 413 | 0 |          String v = null; | 
  | 414 | 0 |          if (pVal != null) { | 
  | 415 | 0 |              v = pVal.toString(); | 
  | 416 |  |          } | 
  | 417 |  |           | 
  | 418 | 0 |          KSItemLabel item = createItem(v, "Display: " + v, hasDetails); | 
  | 419 | 0 |          addItem(item); | 
  | 420 | 0 |      } | 
  | 421 |  |   | 
  | 422 |  |      @Override | 
  | 423 |  |      public void addFocusLostCallback(Callback<Boolean> callback) { | 
  | 424 | 0 |          if (picker != null) | 
  | 425 | 0 |              picker.addFocusLostCallback(callback); | 
  | 426 | 0 |      } | 
  | 427 |  |   | 
  | 428 | 0 |      public static class ItemDataHelper implements DataHelper { | 
  | 429 |  |   | 
  | 430 |  |          @Override | 
  | 431 |  |          public String parse(Data data) { | 
  | 432 |  |              String result; | 
  | 433 | 0 |              if (data == null) { | 
  | 434 | 0 |                  return null; | 
  | 435 |  |              } | 
  | 436 | 0 |              result = (String) data.get(DISPLAY); | 
  | 437 | 0 |              return result; | 
  | 438 |  |          } | 
  | 439 |  |   | 
  | 440 |  |          @Override | 
  | 441 |  |          public String getKey(Data data) { | 
  | 442 |  |              String result; | 
  | 443 | 0 |              if (data == null) { | 
  | 444 | 0 |                  return null; | 
  | 445 |  |              } | 
  | 446 | 0 |              result = (String) data.get(VALUE); | 
  | 447 | 0 |              return result; | 
  | 448 |  |          } | 
  | 449 |  |   | 
  | 450 |  |      } | 
  | 451 |  |   | 
  | 452 |  |      @Override | 
  | 453 |  |      public void setValue(String id, String translation) { | 
  | 454 | 0 |          clear(); | 
  | 455 | 0 |          if (id != null && translation != null) { | 
  | 456 | 0 |              addItem(createItem(id, translation, hasDetails), false); | 
  | 457 |  |          } | 
  | 458 | 0 |      } | 
  | 459 |  |   | 
  | 460 |  |      @Override | 
  | 461 |  |      public void setValue(Map<String, String> translations) { | 
  | 462 | 0 |          clear(); | 
  | 463 | 0 |          if (translations != null) { | 
  | 464 | 0 |              for (Entry<String, String> e : translations.entrySet()) { | 
  | 465 | 0 |                  addItem(createItem(e.getKey(), e.getValue(), hasDetails), false); | 
  | 466 |  |              } | 
  | 467 |  |          } | 
  | 468 | 0 |      } | 
  | 469 |  |   | 
  | 470 |  |      @Override | 
  | 471 |  |      public Widget getInputWidget() { | 
  | 472 | 0 |          if (picker == null) { | 
  | 473 | 0 |              return valuesPanel; | 
  | 474 |  |          } | 
  | 475 | 0 |          return picker.getInputWidget(); | 
  | 476 |  |      } | 
  | 477 |  |   | 
  | 478 |  |      @Override | 
  | 479 |  |      public HashSet<String> getCrossConstraints() { | 
  | 480 | 0 |          if (picker != null) { | 
  | 481 | 0 |              return picker.getCrossConstraints(); | 
  | 482 |  |          } | 
  | 483 | 0 |          return new HashSet<String>(); | 
  | 484 |  |      } | 
  | 485 |  |   | 
  | 486 |  |      @Override | 
  | 487 |  |      public void reprocessWithUpdatedConstraints() { | 
  | 488 | 0 |          if (picker != null) { | 
  | 489 | 0 |              picker.reprocessWithUpdatedConstraints(); | 
  | 490 |  |          } | 
  | 491 | 0 |      } | 
  | 492 |  |   | 
  | 493 |  |      public KSButton getAddItemButton() { | 
  | 494 | 0 |          return addItemButton; | 
  | 495 |  |      } | 
  | 496 |  |   | 
  | 497 |  |      public VerticalFlowPanel getMainPanel() { | 
  | 498 | 0 |          return mainPanel; | 
  | 499 |  |      } | 
  | 500 |  |   | 
  | 501 |  |      public KSPicker getPicker() { | 
  | 502 | 0 |          return picker; | 
  | 503 |  |      } | 
  | 504 |  |   | 
  | 505 |  |      @Override | 
  | 506 |  |      public ErrorLevel processValidationResult(ValidationResultInfo vr) { | 
  | 507 |  |           | 
  | 508 | 0 |          String indexNumber = vr.getElement().substring(vr.getElement().lastIndexOf('/') + 1); | 
  | 509 | 0 |          int index = Integer.parseInt(indexNumber); | 
  | 510 | 0 |          if (index < getSelectedItems().size()) { | 
  | 511 | 0 |              KSItemLabel itemLabel = getSelectedItems().get(index); | 
  | 512 | 0 |              return itemLabel | 
  | 513 |  |                      .processValidationResult(vr, vr.getElement().substring(0, vr.getElement().lastIndexOf('/'))); | 
  | 514 |  |          } else { | 
  | 515 | 0 |              return ErrorLevel.OK; | 
  | 516 |  |          } | 
  | 517 |  |      } | 
  | 518 |  |   | 
  | 519 |  |      public ErrorLevel processValidationResult(ValidationResultInfo vr, String fieldName) { | 
  | 520 |  |           | 
  | 521 | 0 |          String indexNumber = vr.getElement().substring(vr.getElement().lastIndexOf('/') + 1); | 
  | 522 | 0 |          int index = Integer.parseInt(indexNumber); | 
  | 523 | 0 |          if (index < getSelectedItems().size()) { | 
  | 524 | 0 |              KSItemLabel itemLabel = getSelectedItems().get(index); | 
  | 525 | 0 |              return itemLabel.processValidationResult(vr, fieldName); | 
  | 526 |  |          } else { | 
  | 527 | 0 |              return ErrorLevel.OK; | 
  | 528 |  |          } | 
  | 529 |  |      } | 
  | 530 |  |   | 
  | 531 |  |      @Override | 
  | 532 |  |      public boolean shouldProcessValidationResult(ValidationResultInfo vr) { | 
  | 533 |  |           | 
  | 534 | 0 |          if (vr.getElement() != null && vr.getElement().matches("^\\S+/[0-9]+$")) { | 
  | 535 | 0 |              return true; | 
  | 536 |  |          } | 
  | 537 | 0 |          return false; | 
  | 538 |  |      } | 
  | 539 |  |   | 
  | 540 |  |      @Override | 
  | 541 |  |      public void clearValidationErrors() { | 
  | 542 | 0 |          for (KSItemLabel itemLabel : selectedItems) { | 
  | 543 | 0 |              itemLabel.clearValidationErrors(); | 
  | 544 |  |          } | 
  | 545 | 0 |      } | 
  | 546 |  |   | 
  | 547 |  |      @Override | 
  | 548 |  |      public void clearValidationWarnings() { | 
  | 549 | 0 |          for (KSItemLabel itemLabel : selectedItems) { | 
  | 550 | 0 |              itemLabel.clearValidationWarnings(); | 
  | 551 |  |          } | 
  | 552 | 0 |      } | 
  | 553 |  |   | 
  | 554 |  |      @Override | 
  | 555 |  |      protected void onEnsureDebugId(String baseID) { | 
  | 556 | 0 |          super.onEnsureDebugId(baseID); | 
  | 557 | 0 |          if (addItemButton != null) { | 
  | 558 | 0 |              addItemButton.ensureDebugId(baseID + "-Add-to-list"); | 
  | 559 |  |          } | 
  | 560 | 0 |          if (picker != null) { | 
  | 561 | 0 |              picker.ensureDebugId(baseID); | 
  | 562 |  |          } | 
  | 563 | 0 |      } | 
  | 564 |  |   | 
  | 565 |  |  } |