Beispiel #1
0
  /**
   * Set the value of the parent pack of the given pack to SELECTED, PARTIAL_SELECT, or DESELECTED.
   * Value of the pack is dependent of its children values.
   *
   * @param childPack
   */
  private void updateParent(Pack childPack) {
    String parentName = childPack.getParent();
    Pack parentPack = nameToPack.get(parentName);
    int parentPosition = nameToRow.get(parentName);

    int childrenSelected = 0;
    for (String childName : parentPack.getChildren()) {
      int childPosition = nameToRow.get(childName);
      if (isChecked(childPosition)) {
        childrenSelected += 1;
      }
    }

    if (parentPack.getChildren().size() == childrenSelected) {
      if (checkValues[parentPosition] < 0) {
        checkValues[parentPosition] = REQUIRED_SELECTED;
      } else {
        checkValues[parentPosition] = SELECTED;
      }
    } else if (childrenSelected > 0) {

      if (checkValues[parentPosition] < 0) {
        checkValues[parentPosition] = REQUIRED_PARTIAL_SELECTED;
      } else {
        checkValues[parentPosition] = PARTIAL_SELECTED;
      }
    } else {
      if (checkValues[parentPosition] < 0) {
        checkValues[parentPosition] = REQUIRED_DESELECTED;
      } else {
        checkValues[parentPosition] = DESELECTED;
      }
    }
  }
Beispiel #2
0
  /**
   * Ensure that parent packs know which packs are their children. Ensure that packs who have
   * dependants know which packs depend on them
   *
   * @param packs packs visible to the user
   * @param nameToPack mapping from pack names to pack objects
   * @return packs
   */
  private List<Pack> setPackProperties(List<Pack> packs, Map<String, Pack> nameToPack) {
    Pack parent;
    for (Pack pack : packs) {
      if (pack.hasParent()) {
        String parentName = pack.getParent();
        parent = nameToPack.get(parentName);
        parent.addChild(pack.getName());
      }

      if (pack.hasDependencies()) {
        for (String name : pack.getDependencies()) {
          parent = nameToPack.get(name);
          parent.addDependant(pack.getName());
        }
      }
    }
    return packs;
  }