Esempio n. 1
0
 public static void shiftItemsLast(
     UISelectMany targetSelect, UISelectItems targetItems, UIEditableList hiddenTargetList) {
   String[] selected = (String[]) targetSelect.getSelectedValues();
   SelectItem[] all = (SelectItem[]) targetItems.getValue();
   if (selected == null) {
     // nothing to do
     return;
   }
   all = shiftLast(selected, all);
   targetItems.setValue(all);
   clearTargetList(hiddenTargetList);
   addToTargetList(hiddenTargetList, all);
 }
Esempio n. 2
0
  /** Move items from components to others. */
  public static void moveItems(
      UISelectMany sourceSelect,
      UISelectItems sourceItems,
      UISelectItems targetItems,
      UIEditableList hiddenTargetList,
      boolean setTargetIds) {
    String[] selected = (String[]) sourceSelect.getSelectedValues();
    if (selected == null) {
      // nothing to do
      return;
    }
    List<String> selectedList = Arrays.asList(selected);

    SelectItem[] all = (SelectItem[]) sourceItems.getValue();
    List<SelectItem> toMove = new ArrayList<SelectItem>();
    List<SelectItem> toKeep = new ArrayList<SelectItem>();
    List<String> hiddenIds = new ArrayList<String>();
    if (all != null) {
      for (SelectItem item : all) {
        String itemId = item.getValue().toString();
        if (selectedList.contains(itemId)) {
          toMove.add(item);
        } else {
          toKeep.add(item);
          if (!setTargetIds) {
            hiddenIds.add(itemId);
          }
        }
      }
    }
    // reset left values
    sourceItems.setValue(toKeep.toArray(new SelectItem[] {}));
    sourceSelect.setSelectedValues(new Object[0]);

    // change right values
    List<SelectItem> newSelectItems = new ArrayList<SelectItem>();
    SelectItem[] oldSelectItems = (SelectItem[]) targetItems.getValue();
    if (oldSelectItems == null) {
      newSelectItems.addAll(toMove);
    } else {
      newSelectItems.addAll(Arrays.asList(oldSelectItems));
      List<String> oldIds = new ArrayList<String>();
      for (SelectItem oldItem : oldSelectItems) {
        String id = oldItem.getValue().toString();
        oldIds.add(id);
      }
      if (setTargetIds) {
        hiddenIds.addAll(0, oldIds);
      }
      for (SelectItem toMoveItem : toMove) {
        String id = toMoveItem.getValue().toString();
        if (!oldIds.contains(id)) {
          newSelectItems.add(toMoveItem);
          if (setTargetIds) {
            hiddenIds.add(id);
          }
        }
      }
    }
    targetItems.setValue(newSelectItems.toArray(new SelectItem[] {}));

    // update hidden values
    int numValues = hiddenTargetList.getRowCount();
    if (numValues > 0) {
      for (int i = numValues - 1; i > -1; i--) {
        hiddenTargetList.removeValue(i);
      }
    }
    for (String newHiddenValue : hiddenIds) {
      hiddenTargetList.addValue(newHiddenValue);
    }
  }