Beispiel #1
0
 public void addChild(TreeItem parent) throws Exception {
   boolean childFlag = false;
   TreeItem last = null;
   int index = -1;
   for (int i = this.items.size() - 1; i >= 0; i--) {
     if (this.items.get(i) == parent) {
       index = i;
       break;
     }
   }
   ArrayList list = new ArrayList();
   for (int i = 0; i < this.DataSource.getRowCount(); i++) {
     DataRow dr = this.DataSource.getDataRow(i);
     String pid = dr.getString(this.ParentIdentifierColumnName);
     String id = dr.getString(this.IdentifierColumnName);
     if ((parent.getID().equals(pid)) && (!XString.isEmpty(id)) && (!id.equals(pid))) {
       childFlag = true;
       if ((parent.getLevel() >= this.level) && ((!this.lazyLoad) || (!this.expand))) {
         parent.setLazy(this.lazy);
         parent.setExpanded(false);
         parent.setBranch(childFlag);
         return;
       }
       TreeItem item = new TreeItem();
       item.setData(dr);
       item.parseHtml(getItemInnerHtml(dr));
       item.setAction(this);
       item.setID(dr.getString(this.IdentifierColumnName));
       item.setParentID(parent.getID());
       item.setLevel(parent.getLevel() + 1);
       item.setParent(parent);
       if (this.lazyLoad) {
         item.setLevelStr((String) getParams().get("LevelStr"));
       }
       list.add(item);
       this.items.add(index + list.size(), item);
       last = item;
     }
   }
   for (int i = 0; i < list.size(); i++) {
     addChild((TreeItem) list.get(i));
   }
   if (last != null) {
     last.setLast(true);
   }
   if ((!this.lazy) && (parent.getLevel() + 1 == this.level)) {
     parent.setExpanded(false);
   }
   parent.setBranch(childFlag);
 }
  @Test
  public void testPackRespectSubItems() {
    TreeItem item = new TreeItem(tree, SWT.NONE);
    item.setText("Item 0");
    TreeItem subitem = new TreeItem(item, SWT.NONE);
    subitem.setText("Subitem 0.0");
    column.pack();
    int columnWidth = column.getWidth();
    item.setExpanded(true);

    column.pack();

    assertTrue(column.getWidth() > columnWidth);
  }
  private void processWithGrouping(List<TaskWithWorklogs> tasks, DisplayData displayData) {
    LOGGER.debug("Processing with grouping");
    List<String> distinctGroupByCriteria =
        tasks
            .stream()
            .map(TaskWithWorklogs::getDistinctGroupByCriteriaValues)
            .flatMap(Collection::stream)
            .distinct()
            .sorted(COLLATOR)
            .collect(Collectors.toList());

    distinctGroupByCriteria.forEach(
        groupByCriteria -> {
          LOGGER.debug("Gathering data for group criteria value {}", groupByCriteria);
          DisplayRow groupCaptionRow = new DisplayRow();
          groupCaptionRow.setIsGroupContainer(true);
          groupCaptionRow.setLabel(groupByCriteria);

          TreeItem<DisplayRow> groupRow = new TreeItem<>(groupCaptionRow);
          groupRow.setExpanded(true);
          Map<String, DisplayRow> ticketIdToDisplayRow = Maps.newHashMap();

          // add sub rows to groupRow
          tasks
              .stream()
              .filter(
                  taskWithWorklogs ->
                      taskWithWorklogs.getDistinctGroupByCriteriaValues().contains(groupByCriteria))
              .sorted((o1, o2) -> COLLATOR.compare(o1.getIssue(), o2.getIssue()))
              .forEach(
                  taskWithWorklogs -> {
                    // this task with worklogs contains at least one workitem
                    // having the group by criteria

                    DisplayRow ticketRowWithinThisGroup =
                        ticketIdToDisplayRow.get(taskWithWorklogs.getIssue());
                    if (ticketRowWithinThisGroup == null) {
                      ticketRowWithinThisGroup = new DisplayRow();
                      ticketRowWithinThisGroup.setLabel(taskWithWorklogs.getSummary());
                      ticketRowWithinThisGroup.setIssueId(taskWithWorklogs.getIssue());
                      ticketRowWithinThisGroup.setResolvedDate(taskWithWorklogs.getResolved());
                      groupRow.getChildren().add(new TreeItem<>(ticketRowWithinThisGroup));
                      ticketIdToDisplayRow.put(
                          taskWithWorklogs.getIssue(), ticketRowWithinThisGroup);
                    }

                    DisplayRow ticketRowWithinThisGroupAsFinal = ticketRowWithinThisGroup;

                    taskWithWorklogs
                        .getWorklogItemList()
                        .stream()
                        .filter(
                            worklogItem ->
                                StringUtils.equals(worklogItem.getGroup(), groupByCriteria))
                        .sorted((o1, o2) -> o1.getDate().compareTo(o2.getDate()))
                        .forEach(
                            worklogItem -> {
                              // this worklog item matches the critera
                              // add workday entry to current row
                              LocalDate date = worklogItem.getDate();

                              DisplayDayEntry workdayEntry =
                                  ticketRowWithinThisGroupAsFinal
                                      .getWorkdayEntry(date)
                                      .orElseGet(
                                          () -> {
                                            DisplayDayEntry displayDayEntry = new DisplayDayEntry();
                                            displayDayEntry.setDate(date);
                                            ticketRowWithinThisGroupAsFinal.addDisplayDayEntry(
                                                displayDayEntry);

                                            return displayDayEntry;
                                          });

                              workdayEntry
                                  .getSpentTime()
                                  .addAndGet(worklogItem.getDurationInMinutes());

                              // also add up the spent time in the group header per group
                              workdayEntry =
                                  groupCaptionRow
                                      .getWorkdayEntry(date)
                                      .orElseGet(
                                          () -> {
                                            DisplayDayEntry newWorkdayEntry = new DisplayDayEntry();
                                            newWorkdayEntry.setDate(date);
                                            groupCaptionRow.addDisplayDayEntry(newWorkdayEntry);
                                            return newWorkdayEntry;
                                          });
                              workdayEntry
                                  .getSpentTime()
                                  .addAndGet(worklogItem.getDurationInMinutes());
                            });
                  });

          // add groupRow to result
          displayData.addRow(groupRow);
        });
  }