public void addTestInfo(TaskDataDto test, Map<String, TestInfoDto> testInfoMap) {

    TreeItem testItem = getTestItem(test);

    String testInfoId = testItem.getKey() + TEST_INFO;
    if (treeStore.findModelWithKey(testInfoId) != null) {
      return;
    }

    String testItemName = getTestItemName(test);
    TreeItem testInfo = new TreeItem(testInfoId);
    testInfo.put(NAME, TEST_INFO);
    testInfo.put(TEST_DESCRIPTION, test.getDescription());
    testInfo.put(TEST_NAME, testItemName);
    treeStore.insert(testItem, 0, testInfo);

    TreeItem clock = new TreeItem(testItem.getKey() + "Clock");
    clock.put(NAME, "Clock");
    clock.put(TEST_DESCRIPTION, test.getDescription());
    clock.put(TEST_NAME, testItemName);
    clock.put(TEST_INFO, TEST_INFO);
    for (SessionDataDto session : chosenSessions) {
      if (testInfoMap.get(session.getSessionId()) != null)
        clock.put(
            SESSION_HEADER + session.getSessionId(),
            testInfoMap.get(session.getSessionId()).getClock());
    }
    treeStore.add(testInfo, clock);

    TreeItem termination = new TreeItem(testItem.getKey() + "Termination");
    termination.put(NAME, "Termination");
    termination.put(TEST_DESCRIPTION, test.getDescription());
    termination.put(TEST_NAME, testItemName);
    termination.put(TEST_INFO, TEST_INFO);
    for (SessionDataDto session : chosenSessions) {
      if (testInfoMap.get(session.getSessionId()) != null)
        termination.put(
            SESSION_HEADER + session.getSessionId(),
            testInfoMap.get(session.getSessionId()).getTermination());
    }
    treeStore.add(testInfo, termination);

    TreeItem startTime = new TreeItem(testItem.getKey() + "Start time");
    startTime.put(NAME, "Start time");
    startTime.put(TEST_DESCRIPTION, test.getDescription());
    startTime.put(TEST_NAME, testItemName);
    startTime.put(TEST_INFO, TEST_INFO);
    for (SessionDataDto session : chosenSessions) {
      if (testInfoMap.get(session.getSessionId()) != null) {
        Date date = testInfoMap.get(session.getSessionId()).getStartTime();
        startTime.put(SESSION_HEADER + session.getSessionId(), dateFormatter.format(date));
      }
    }
    treeStore.add(testInfo, startTime);
  }
  public void addSessionInfo() {
    TreeItem sessionInfo = new TreeItem(SESSION_INFO_ID);
    sessionInfo.put(NAME, "Session Info");
    treeStore.insert(0, sessionInfo);

    String tagsStr = "";
    TreeItem itemActiveKernels = new TreeItem(ACTIVE_KERNELS);
    TreeItem itemTaskExecuted = new TreeItem(TASKS_EXECUTED);
    TreeItem itemTaskFailed = new TreeItem(TASKS_FAILED);
    TreeItem itemDateStart = new TreeItem(START_DATE);
    TreeItem itemDateEnd = new TreeItem(END_DATE);
    TreeItem itemComment = new TreeItem(COMMENT);
    TreeItem itemUserComment = new TreeItem(USER_COMMENT);
    TreeItem itemTags = new TreeItem(SESSION_TAGS);

    itemActiveKernels.put(NAME, ACTIVE_KERNELS);
    itemTaskExecuted.put(NAME, TASKS_EXECUTED);
    itemTaskFailed.put(NAME, TASKS_FAILED);
    itemDateStart.put(NAME, START_DATE);
    itemDateEnd.put(NAME, END_DATE);
    itemComment.put(NAME, COMMENT);
    if (webClientProperties.isUserCommentStoreAvailable()) itemUserComment.put(NAME, USER_COMMENT);
    if (webClientProperties.isTagsStoreAvailable()) itemTags.put(NAME, SESSION_TAGS);

    for (SessionDataDto session : chosenSessions) {
      itemActiveKernels.put(
          SESSION_HEADER + session.getSessionId(), session.getActiveKernelsCount() + "");
      itemTaskExecuted.put(
          SESSION_HEADER + session.getSessionId(), session.getTasksExecuted() + "");
      itemTaskFailed.put(SESSION_HEADER + session.getSessionId(), session.getTasksFailed() + "");
      itemDateStart.put(
          SESSION_HEADER + session.getSessionId(), dateFormatter.format(session.getStartDate()));
      itemDateEnd.put(
          SESSION_HEADER + session.getSessionId(), dateFormatter.format(session.getEndDate()));
      itemComment.put(SESSION_HEADER + session.getSessionId(), session.getComment());
      if (webClientProperties.isUserCommentStoreAvailable()) {
        String userComment = session.getUserComment() == null ? "" : session.getUserComment();
        itemUserComment.put(SESSION_HEADER + session.getSessionId(), userComment);
      }
      if (webClientProperties.isTagsStoreAvailable()) {
        for (int i = 0; i < session.getTags().size(); i++) {
          if (i == session.getTags().size() - 1) tagsStr += session.getTags().get(i).getName();
          else tagsStr += session.getTags().get(i).getName() + ", ";
        }
        itemTags.put(SESSION_HEADER + session.getSessionId(), tagsStr);
        tagsStr = "";
      }
    }
    treeStore.add(sessionInfo, itemComment);
    if (webClientProperties.isUserCommentStoreAvailable())
      treeStore.add(sessionInfo, itemUserComment);
    if (webClientProperties.isTagsStoreAvailable()) treeStore.add(sessionInfo, itemTags);
    treeStore.add(sessionInfo, itemDateStart);
    treeStore.add(sessionInfo, itemDateEnd);

    treeStore.add(sessionInfo, itemActiveKernels);
    treeStore.add(sessionInfo, itemTaskExecuted);
    treeStore.add(sessionInfo, itemTaskFailed);
  }
 private void processFolder(TreeStore<BaseDto> store, FolderDto folder) {
   for (BaseDto child : folder.getChildren()) {
     store.add(folder, child);
     if (child instanceof FolderDto) {
       processFolder(store, (FolderDto) child);
     }
   }
 }
  private void addItemToStore(TreeItem record, SummarySingleDto metricDto) {

    TreeItem taskItem = getTestItem(metricDto.getMetricName().getTest());
    for (TreeItem rec : treeStore.getChildren(taskItem)) {
      if (rec.getKey().equals(record.getKey())) {
        return;
      }
    }
    treeStore.add(taskItem, record);
  }
 private TreeItem getTestDescriptionItem(String descriptionStr) {
   for (TreeItem item : treeStore.getRootItems()) {
     if (descriptionStr.equals(item.get(NAME))) {
       return item;
     }
   }
   TreeItem description = new TreeItem(descriptionStr);
   description.put(NAME, descriptionStr);
   treeStore.add(description);
   return description;
 }
  private TreeItem getTestItem(TaskDataDto tdd) {

    String key = getTestItemId(tdd);
    TreeItem taskItem = treeStore.findModelWithKey(key);
    if (taskItem != null) {
      return taskItem;
    }

    TreeItem description = getTestDescriptionItem(tdd.getDescription());

    taskItem = new TreeItem(key);
    taskItem.put(NAME, getTestItemName(tdd));
    taskItem.put(TEST_DESCRIPTION, tdd.getDescription());
    treeStore.add(description, taskItem);
    return taskItem;
  }
  @Override
  public Widget asWidget() {
    final Window complex = new Window();
    complex.setMaximizable(true);
    complex.setHeadingText("Accordion Window");
    complex.setWidth(200);
    complex.setHeight(350);

    AccordionLayoutContainer con = new AccordionLayoutContainer();
    con.setExpandMode(ExpandMode.SINGLE_FILL);
    complex.add(con);

    AccordionLayoutAppearance appearance =
        GWT.<AccordionLayoutAppearance>create(AccordionLayoutAppearance.class);

    ContentPanel cp = new ContentPanel(appearance);
    cp.setAnimCollapse(false);
    cp.setHeadingText("Online Users");
    cp.getHeader().addStyleName(ThemeStyles.getStyle().borderTop());
    con.add(cp);
    con.setActiveWidget(cp);

    TreeStore<NameImageModel> store = new TreeStore<NameImageModel>(NameImageModel.KP);

    Tree<NameImageModel, String> tree =
        new Tree<NameImageModel, String>(
            store,
            new ValueProvider<NameImageModel, String>() {

              @Override
              public String getValue(NameImageModel object) {
                return object.getName();
              }

              @Override
              public void setValue(NameImageModel object, String value) {}

              @Override
              public String getPath() {
                return "name";
              }
            });

    tree.setIconProvider(
        new IconProvider<NameImageModel>() {
          public ImageResource getIcon(NameImageModel model) {
            if (null == model.getImage()) {
              return null;
            } else if ("user-girl" == model.getImage()) {
              return ExampleImages.INSTANCE.userFemale();
            } else if ("user-kid" == model.getImage()) {
              return ExampleImages.INSTANCE.userKid();
            } else {
              return ExampleImages.INSTANCE.user();
            }
          }
        });

    NameImageModel m = newItem("Family", null);
    store.add(m);

    store.add(m, newItem("Darrell", "user"));
    store.add(m, newItem("Maro", "user-girl"));
    store.add(m, newItem("Lia", "user-kid"));
    store.add(m, newItem("Alec", "user-kid"));
    store.add(m, newItem("Andrew", "user-kid"));

    tree.setExpanded(m, true);

    m = newItem("Friends", null);
    store.add(m);

    store.add(m, newItem("Bob", "user"));
    store.add(m, newItem("Mary", "user-girl"));
    store.add(m, newItem("Sally", "user-girl"));
    store.add(m, newItem("Jack", "user"));

    tree.setExpanded(m, true);

    cp.add(tree);

    cp = new ContentPanel(appearance);
    cp.setAnimCollapse(false);
    cp.setBodyStyleName("pad-text");
    cp.setHeadingText("Settings");
    cp.add(new Label(TestData.DUMMY_TEXT_SHORT));
    con.add(cp);

    cp = new ContentPanel(appearance);
    cp.setAnimCollapse(false);
    cp.setBodyStyleName("pad-text");
    cp.setHeadingText("Stuff");
    cp.add(new Label(TestData.DUMMY_TEXT_SHORT));
    con.add(cp);

    cp = new ContentPanel(appearance);
    cp.setAnimCollapse(false);
    cp.setBodyStyleName("pad-text");
    cp.setHeadingText("More Stuff");
    cp.add(new Label(TestData.DUMMY_TEXT_SHORT));
    con.add(cp);

    TextButton b = new TextButton("Open");
    b.addSelectHandler(
        new SelectHandler() {

          @Override
          public void onSelect(SelectEvent event) {
            complex.show();
          }
        });

    VerticalPanel vp = new VerticalPanel();
    vp.setSpacing(10);
    vp.add(b);
    return vp;
  }
  @Override
  public Widget asWidget() {
    if (panel == null) {
      panel = new ContentPanel();
      panel.setHeadingText("Cell Action Tree");
      panel.setPixelSize(315, 400);
      panel.addStyleName("margin-10");

      VerticalLayoutContainer con = new VerticalLayoutContainer();
      panel.add(con);

      TreeStore<BaseDto> store = new TreeStore<BaseDto>(new KeyProvider());

      FolderDto root = TestData.getMusicRootFolder();
      for (BaseDto base : root.getChildren()) {
        store.add(base);
        if (base instanceof FolderDto) {
          processFolder(store, (FolderDto) base);
        }
      }

      SimpleSafeHtmlCell<String> cell =
          new SimpleSafeHtmlCell<String>(SimpleSafeHtmlRenderer.getInstance(), "click") {
            @Override
            public void onBrowserEvent(
                Context context,
                Element parent,
                String value,
                NativeEvent event,
                ValueUpdater<String> valueUpdater) {
              super.onBrowserEvent(context, parent, value, event, valueUpdater);
              if ("click".equals(event.getType())) {
                Info.display("Click", "You clicked \"" + value + "\"!");
              }
            }
          };

      final Tree<BaseDto, String> tree =
          new Tree<BaseDto, String>(
              store,
              new ValueProvider<BaseDto, String>() {

                @Override
                public String getValue(BaseDto object) {
                  return object.getName();
                }

                @Override
                public void setValue(BaseDto object, String value) {}

                @Override
                public String getPath() {
                  return "name";
                }
              });
      tree.setCell(cell);
      tree.setWidth(300);
      tree.getStyle().setLeafIcon(ExampleImages.INSTANCE.music());

      ToolBar buttonBar = new ToolBar();

      buttonBar.add(
          new TextButton(
              "Expand All",
              new SelectHandler() {

                @Override
                public void onSelect(SelectEvent event) {
                  tree.expandAll();
                }
              }));
      buttonBar.add(
          new TextButton(
              "Collapse All",
              new SelectHandler() {
                @Override
                public void onSelect(SelectEvent event) {
                  tree.collapseAll();
                }
              }));

      con.add(buttonBar, new VerticalLayoutData(1, -1));
      con.add(tree, new VerticalLayoutData(1, 1));
    }

    return panel;
  }
  public Widget asWidget() {
    FlowLayoutContainer con = new FlowLayoutContainer();
    con.addStyleName("margin-10");

    TreeStore<BaseDto> store = new TreeStore<BaseDto>(new KeyProvider());

    FolderDto root = TestData.getMusicRootFolder();
    for (BaseDto base : root.getChildren()) {
      store.add(base);
      if (base instanceof FolderDto) {
        processFolder(store, (FolderDto) base);
      }
    }

    StoreFilterField<BaseDto> filter =
        new StoreFilterField<BaseDto>() {

          @Override
          protected boolean doSelect(
              Store<BaseDto> store, BaseDto parent, BaseDto item, String filter) {
            if (item instanceof FolderDto) {
              return false;
            }

            String name = item.getName();
            name = name.toLowerCase();
            if (name.startsWith(filter.toLowerCase())) {
              return true;
            }
            return false;
          }
        };
    filter.bind(store);

    final Tree<BaseDto, String> tree =
        new Tree<BaseDto, String>(
            store,
            new ValueProvider<BaseDto, String>() {

              @Override
              public String getValue(BaseDto object) {
                return object.getName();
              }

              @Override
              public void setValue(BaseDto object, String value) {}

              @Override
              public String getPath() {
                return "name";
              }
            });
    tree.setWidth(300);
    tree.getStyle().setLeafIcon(ExampleImages.INSTANCE.music());
    ButtonBar buttonBar = new ButtonBar();

    buttonBar.add(
        new TextButton(
            "Expand All",
            new SelectHandler() {

              @Override
              public void onSelect(SelectEvent event) {
                tree.expandAll();
              }
            }));
    buttonBar.add(
        new TextButton(
            "Collapse All",
            new SelectHandler() {
              @Override
              public void onSelect(SelectEvent event) {
                tree.collapseAll();
              }
            }));

    buttonBar.setLayoutData(new MarginData(4));
    con.add(filter);
    con.add(buttonBar);
    con.add(tree);
    return con;
  }