Beispiel #1
0
  public void fill() {
    GHACache.INSTANCE.getBsps(
        new GHAAsyncCallback<List<Bsp>>() {
          @Override
          public void onSuccess(List<Bsp> result) {
            bsps = new HashMap<Long, Bsp>();

            LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
            for (Bsp bsp : result) {
              Obu obu = bsp.getObu();
              valueMap.put(bsp.getId() + "", obu.getName());
              bsps.put(bsp.getId(), bsp);
            }
            setValueMap(valueMap);
          }
        });
  }
  private void fill() {
    final Tree tree = new Tree();
    GHACache.INSTANCE.getMaterialCategories(
        new GHAAsyncCallback<List<ServicesResourceCategory>>() {

          @Override
          public void onSuccess(List<ServicesResourceCategory> result) {
            Collections.sort(result);

            final String codes[] = new String[result.size()];
            final TreeNode nodes[] = new TreeNode[result.size()];

            for (int i = 0; i < result.size(); ++i) {
              codes[i] = result.get(i).getCode();

              nodes[i] = new TreeNode(result.get(i).getName());
              nodes[i].setAttribute("categoryCode", result.get(i).getCode());
              nodes[i].setAttribute("categoryName", result.get(i).getName());
            }

            final int parent[] = GHAUtil.buildParentsByCode(codes, 0);

            for (int i = 0; i < result.size(); ++i) {
              final List<Integer> children = new ArrayList<Integer>();

              // get the children of i
              for (int j = 0; j < result.size(); ++j) {
                if (parent[j] == i) children.add(j);
              }

              final TreeNode theChildren[] = new TreeNode[children.size()];
              for (int j = 0; j < children.size(); ++j) {
                theChildren[j] = nodes[children.get(j)];
              }

              if (children.size() > 0) nodes[i].setChildren(theChildren);
            }
            root.setChildren(new TreeNode[] {nodes[0]});
            tree.setRoot(root);
            GHAMaterialCategoryPickTreeItem.this.setValueTree(tree);
          }
        });
  }