コード例 #1
0
  public TreeNode asTree(MiniLocalization localizationToUse) {
    Collections.sort(allChoices, new ChoiceItemSorterByLabelTagType(localizationToUse));
    mergeSimilarDropdowns();
    sortAllChoicesWithinDropdowns();

    SearchFieldTreeNode root = new SearchFieldTreeNode("", localizationToUse);
    SearchableFieldChoiceItem[] choices = getChoicesAsArray();
    int index = 0;
    while (index < choices.length) {
      String label = choices[index].getSpec().getLabel();
      SearchFieldTreeNode node = new SearchFieldTreeNode(label, localizationToUse);
      node.add(new SearchFieldTreeNode(choices[index], localizationToUse));
      addSimilarNodes(node, choices, index + 1, localizationToUse);
      index += node.getChildCount();
      node = pullUpIfOnlyOneChild(node);
      differentiateChildNodes(node);
      root.add(node);
    }

    return root;
  }
コード例 #2
0
 private void addSimilarNodes(
     SearchFieldTreeNode parent,
     SearchableFieldChoiceItem[] choices,
     int startAt,
     MiniLocalization localizationToUse) {
   String label = parent.toString();
   int index = startAt;
   while (index < choices.length && choices[index].getSpec().getLabel().equals(label)) {
     SearchableFieldChoiceItem choice = choices[index];
     parent.add(new SearchFieldTreeNode(choice, localizationToUse));
     ++index;
   }
 }