Exemplo n.º 1
0
  public void setRootItem(TaxonomyNode rootItem) {
    this.rootItem = rootItem;

    for (Control control : this.getChildren()) control.dispose();

    boolean hasParent = false;

    List<TaxonomyNode> path = rootItem.getPath();
    for (int ii = 1; ii < path.size(); ii++) {
      hasParent = true;
      TaxonomyNode item = path.get(ii);
      new LegendItem(this, item);
    }

    if (hasParent && !rootItem.getChildren().isEmpty()) {
      Label l = new Label(this, SWT.NONE);
      l.setText(">>"); // $NON-NLS-1$
      l.setBackground(this.getBackground());
    }

    List<TaxonomyNode> children = new ArrayList<TaxonomyNode>(rootItem.getChildren());
    Collections.sort(
        children,
        new Comparator<TaxonomyNode>() {
          @Override
          public int compare(TaxonomyNode o1, TaxonomyNode o2) {
            return o1.getActual() > o2.getActual() ? -1 : o1.getActual() == o2.getActual() ? 0 : 1;
          }
        });
    for (TaxonomyNode child : children) {
      if (model.isUnassignedCategoryInChartsExcluded() && child.isUnassignedCategory()) continue;
      new LegendItem(this, child);
    }

    pack();
    getParent().layout();
  }