@Override
    public String getValue(TreeItem object) {
      String penImageResource =
          "<img src=\""
              + JaggerResources.INSTANCE.getPencilImage().getSafeUri().asString()
              + "\" height=\"15\" width=\"15\">"
              + "<ins font-size='10px'>double click to edit</ins><br><br>";
      String toShow;

      // Only for columns with data
      if (!field.equals(NAME)) {
        if (webClientProperties.isUserCommentEditAvailable()) {
          if (object.get(NAME).equals(USER_COMMENT)) {
            toShow = object.get(field).replaceAll("\n", "<br>");
            return penImageResource + toShow;
          }
        }
        if (webClientProperties.isTagsAvailable()) {
          if (object.get(NAME).equals(SESSION_TAGS)) {
            toShow = object.get(field).replaceAll("\n", "<br>");
            return penImageResource + toShow;
          }
        }
      }

      return object.get(field);
    }
Example #2
0
 private void setupGraphic() {
   TreeItem<DbTreeValue> treeItem = getTreeItem();
   if (treeItem != null && treeItem.getGraphic() != null) {
     setGraphic(treeItem.getGraphic());
   } else {
     setGraphic(null);
   }
 }
Example #3
0
 public static TreeItem getTreeItem(Tree tree, Object data) {
   for (TreeItem item : tree.getItems()) {
     if (item.getData() == data) {
       return item;
     }
   }
   return null;
 }
Example #4
0
  public void onDisconnectDb(ActionEvent ev) {
    TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
    if (selectedItem == null) {
      return;
    }

    selectedItem.getValue().getMongoConnection().close();
    removeFromRoot(selectedItem);
  }
  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);
  }
Example #6
0
 private Optional<DynamicTreeItem> findParentOfType(
     TreeItem<DbTreeValue> selectedItem, Class<DynamicTreeItem> class1) {
   if (selectedItem == null) {
     return Optional.empty();
   }
   if (class1.isAssignableFrom(selectedItem.getClass())) {
     return Optional.of((DynamicTreeItem) selectedItem);
   }
   return findParentOfType(selectedItem.getParent(), class1);
 }
Example #7
0
 public static int getColumnAtPos(TreeItem item, int x, int y) {
   int columnCount = item.getParent().getColumnCount();
   for (int i = 0; i < columnCount; i++) {
     Rectangle rect = item.getBounds(i);
     if (rect.contains(x, y)) {
       return i;
     }
   }
   return -1;
 }
  public void removeTestInfo(TaskDataDto test) {

    String id = getTestItemId(test);
    TreeItem testItem = treeStore.findModelWithKey(id);
    if (testItem == null) {
      return;
    }
    TreeItem testInfo = treeStore.getFirstChild(testItem);
    if (testInfo != null && TEST_INFO.equals(testInfo.get(NAME))) removeWithParent(testInfo);
  }
 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;
 }
Example #10
0
 public static void packColumns(@NotNull Tree tree, boolean fit, @Nullable float[] ratios) {
   tree.setRedraw(false);
   try {
     // Check for disposed items
     // TODO: it looks like SWT error. Sometimes tree items are disposed and NPE is thrown from
     // column.pack
     for (TreeItem item : tree.getItems()) {
       if (item.isDisposed()) {
         return;
       }
     }
     int totalWidth = 0;
     final TreeColumn[] columns = tree.getColumns();
     for (TreeColumn column : columns) {
       column.pack();
       totalWidth += column.getWidth();
     }
     Rectangle clientArea = tree.getClientArea();
     if (clientArea.isEmpty()) {
       return;
     }
     if (fit) {
       int areaWidth = clientArea.width;
       if (tree.getVerticalBar() != null) {
         areaWidth -= tree.getVerticalBar().getSize().x;
       }
       if (totalWidth > areaWidth) {
         int extraSpace = totalWidth - areaWidth;
         for (TreeColumn tc : columns) {
           double ratio = (double) tc.getWidth() / totalWidth;
           tc.setWidth((int) (tc.getWidth() - extraSpace * ratio));
         }
       } else if (totalWidth < areaWidth) {
         float extraSpace = areaWidth - totalWidth;
         if (columns.length > 0) {
           if (ratios == null || ratios.length < columns.length) {
             extraSpace /= columns.length;
             extraSpace--;
             for (TreeColumn tc : columns) {
               tc.setWidth((int) (tc.getWidth() + extraSpace));
             }
           } else {
             for (int i = 0; i < columns.length; i++) {
               TreeColumn tc = columns[i];
               tc.setWidth((int) (tc.getWidth() + extraSpace * ratios[i]));
             }
           }
         }
       }
     }
   } finally {
     tree.setRedraw(true);
   }
 }
Example #11
0
    public void compactWithChildIfOnlyOneChild() {
      if (branches.size() == 1) {
        TreeItem child = branches.get(0);
        if (!child.isTest()) {
          name += "." + child.name;
          fullName += "." + child.name;
          branches = child.branches;

          compactWithChildIfOnlyOneChild();
        }
      }
    }
Example #12
0
 private void buildCollectionDetail(MongoDatabase db, TreeItem<DbTreeValue> ti) {
   DbTreeValue indexCategory = new DbTreeValue(db, "Indexes", TreeValueType.CATEGORY);
   indexCategory.setCollectionName(ti.getValue().getDisplayValue());
   ti.getChildren()
       .add(
           new DynamicTreeItem(
               indexCategory,
               new FontAwesomeIconView(FontAwesomeIcon.FOLDER),
               executor,
               popupService,
               this::buildIndexes));
 }
  private void removeRecord(SummarySingleDto metric) {

    TreeItem testItem = getTestItem(metric.getMetricName().getTest());
    String key = testItem.getKey() + metric.getMetricName().getMetricName();

    for (TreeItem item : treeStore.getChildren(testItem)) {
      if (item.getKey().equals(key)) {
        removeWithParent(item);
        return;
      }
    }
  }
Example #14
0
    void doRecursive(RecursiveTreeMethod method, int level) {
      if (method.shouldDoItemBeforeBranches() && (level != 0)) {
        method.doMethod(this);
      }

      for (TreeItem branch : branches) {
        branch.doRecursive(method, level + 1);
      }

      if (!method.shouldDoItemBeforeBranches() && (level != 0)) {
        method.doMethod(this);
      }
    }
  @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);
  }
Example #16
0
 public void treeViewClicked(MouseEvent ev) {
   if (ev.getClickCount() == 2) {
     // don't process click on triangle
     EventTarget target = ev.getTarget();
     if (target instanceof Node && !"arrow".equals(((Node) target).getStyleClass())) {
       TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
       if (selectedItem != null
           && selectedItem.getValue().getValueType() == TreeValueType.COLLECTION) {
         mainFrameController.openTab();
         ev.consume();
       }
     }
   }
 }
Example #17
0
 void addItem(String[] itemPath, int currentIndex) {
   if (currentIndex < itemPath.length) {
     // special case for this tree only, that all the titles should be organised before we start.
     if (nameSameAsLastName(itemPath[currentIndex])) {
       branches.get(branches.size() - 1).addItem(itemPath, ++currentIndex);
     } else {
       String branchName = itemPath[currentIndex];
       String branchFullName = fullName;
       branchFullName += (fullName.length() > 0) ? "." + branchName : branchName;
       TreeItem branch = new TreeItem(branchName, branchFullName);
       branches.add(branch);
       branch.addItem(itemPath, ++currentIndex);
     }
   }
 }
Example #18
0
 private void makeTree(List<String> pageList) {
   for (String pageName : pageList) {
     String[] splits = pageName.split("\\.");
     treeRoot.addItem(splits, 0);
   }
   compactTree();
 }
  // clear everything but Session Information
  public void clearTreeStore() {

    for (TreeItem root : treeStore.getRootItems()) {
      if (root.getKey().equals(SESSION_INFO_ID)) {
        continue;
      }
      for (TreeItem test : treeStore.getChildren(root)) {
        for (TreeItem item : treeStore.getChildren(test)) {
          if (TEST_INFO.equals(item.get(NAME))) {
            continue;
          }
          removeWithParent(item);
        }
      }
    }
  }
  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;
  }
Example #21
0
  private void buildLessonTree(Response response) {
    TreeItem item = null;
    JsArray<LessonCategoryJS> lessonJSArray = JsonUtils.safeEval(response.getText());

    for (int i = 0; i < lessonJSArray.length(); i++) {
      LessonCategoryJS lessonCategoryJS = lessonJSArray.get(i);
      TreeItem category = new TreeItem();
      category.setText(lessonCategoryJS.getName());

      JsArray<LessonJS> lessons = lessonCategoryJS.getChildren();
      for (int j = 0; j < lessons.length(); j++) {
        LessonJS lesson = lessons.get(j);

        TreeItem lessonItem = new TreeItem();
        Storage sessionStorage = Storage.getSessionStorageIfSupported();
        String lastUrl = sessionStorage.getItem("lastUrl");
        lessonItem.setText(lesson.getText());
        category.addItem(lessonItem);
        lessonsTreeMap.put(lessonItem.getText(), lesson);
        if (lesson.getTechnology().equals(LessonTechnology.GWT.toString())) {
          addLessonToMap(lesson);
        }
        if (lastUrl != null && lastUrl.equals(lesson.getUrl())) {
          item = lessonItem;
          lessonPanel.setSelectedLesson(lesson);
          category.setState(true);
        }
      }
      lessonTree.addItem(category);
    }
    lessonTree.setSelectedItem(item);
  }
 static TreeItem PreviousItem(Tree tree, TreeItem item) {
   if (item == null) return null;
   TreeItem childItem = item;
   TreeItem parentItem = childItem.getParentItem();
   int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem);
   if (index == 0) {
     return parentItem;
   } else {
     TreeItem nextItem =
         parentItem == null ? tree.getItem(index - 1) : parentItem.getItem(index - 1);
     int count = nextItem.getItemCount();
     while (count > 0 && nextItem.getExpanded()) {
       nextItem = nextItem.getItem(count - 1);
       count = nextItem.getItemCount();
     }
     return nextItem;
   }
 }
Example #23
0
 public static <DO> DO findDataObjectInPath(TreeItem treeItem, Class<DO> doClass) {
   Iterator itr = treeItem.iterator();
   while (itr.hasNext()) {
     Object dataObj = itr.next();
     if (doClass.isInstance(dataObj)) {
       return doClass.cast(dataObj);
     }
   }
   return null;
 }
Example #24
0
 private void compactTree() {
   RecursiveTreeMethod compactBranch =
       new RecursiveTreeMethod() {
         @Override
         public void doMethod(TreeItem item) {
           item.compactWithChildIfOnlyOneChild();
         }
       };
   treeRoot.doRecursive(compactBranch, 0);
 }
Example #25
0
  private void onReanameCollection(ActionEvent actionEvent) {
    TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
    if (selectedItem == null) {
      return;
    }

    DbTreeValue value = selectedItem.getValue();
    TextInputDialog dialog = new TextInputDialog(value.getDisplayValue());
    dialog.setContentText("New collection name:");
    dialog.setHeaderText("Rename collection");
    dialog
        .showAndWait()
        .ifPresent(
            targetCollection -> {
              MongoCollection<Document> collection =
                  value.getMongoDatabase().getMongoDb().getCollection(value.getDisplayValue());
              collection.renameCollection(
                  new MongoNamespace(value.getMongoDatabase().getName(), targetCollection));
              ((DynamicTreeItem) selectedItem.getParent()).reload();
            });
  }
Example #26
0
 public boolean equals(Object obj) {
   if (!obj.getClass().equals(this.getClass())) return false;
   StateTreeString s = (StateTreeString) obj;
   boolean ans =
       (state.equals(s.state)
           && i.equals(s.i)
           && o.equals(s.o)
           && align[0] == s.align[0]
           && align[1] == s.align[1]
           && align[2] == s.align[2]
           && align[3] == s.align[3]);
   return ans;
 }
Example #27
0
 public void findLatestResults(final File historyDirectory) {
   RecursiveTreeMethod findLatestResult =
       new RecursiveTreeMethod() {
         @Override
         public void doMethod(TreeItem item) {
           if (item.isTest()) {
             File directory = new File(historyDirectory, item.fullName);
             MostRecentPageHistoryReader reader = new MostRecentPageHistoryReader(directory);
             item.result = reader.findMostRecentTestRun();
           }
         }
       };
   treeRoot.doRecursive(findLatestResult, 0);
 }
Example #28
0
  public void onCreateNewDb(ActionEvent ev) {
    TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
    if (selectedItem == null
        || selectedItem.getValue().getValueType() != TreeValueType.CONNECTION) {
      return;
    }

    TextInputDialog dialog = new TextInputDialog();
    dialog.setContentText("Enter Name:");
    dialog.setHeaderText("Create new db");
    dialog
        .showAndWait()
        .ifPresent(
            r ->
                selectedItem
                    .getChildren()
                    .add(
                        createDbItem(
                            selectedItem
                                .getValue()
                                .getMongoConnection()
                                .createMongoDB(dialog.getResult()))));
  }
  public void writeDataToExcel(Sheet sheet) {
    LOGGER.debug("[{}] Exporting data to excel", getText());

    List<ExcelColumnRenderer> columnRendererList = new ArrayList<>();
    columnRendererList.add(new TaskStatusExcelColumn());
    columnRendererList.add(new TaskDescriptionExcelColumn());

    TimerangeProvider timerangeProvider = fetchTimereportContext.get().getTimerangeProvider();
    LocalDate startDate = timerangeProvider.getStartDate();
    LocalDate endDate = timerangeProvider.getEndDate();

    long amountOfDaysToDisplay = ChronoUnit.DAYS.between(startDate, endDate);
    for (int days = 0; days <= amountOfDaysToDisplay; days++) {
      LocalDate currentColumnDate = timerangeProvider.getStartDate().plus(days, ChronoUnit.DAYS);
      String displayDate = FormattingUtil.formatDate(currentColumnDate);
      columnRendererList.add(new WorklogExcelColumn(displayDate, currentColumnDate));
    }

    columnRendererList.add(new TaskWorklogSummaryExcelColumn());

    TreeItem<DisplayRow> root = taskTableView.getRoot();
    ObservableList<TreeItem<DisplayRow>> children = root.getChildren();

    for (int columnIndex = 0; columnIndex < columnRendererList.size(); columnIndex++) {
      ExcelColumnRenderer excelColumnRenderer = columnRendererList.get(columnIndex);
      excelColumnRenderer.renderCells(
          columnIndex,
          sheet,
          children,
          fetchTimereportContext.get().getGroupByCategory().isPresent());
    }

    // autosize column widths
    for (int i = 0; i < columnRendererList.size(); i++) {
      sheet.autoSizeColumn(i);
    }
  }
Example #30
0
  public void countResults() {
    RecursiveTreeMethod countResults =
        new RecursiveTreeMethod() {
          @Override
          public boolean shouldDoItemBeforeBranches() {
            return false;
          }

          @Override
          public void doMethod(TreeItem item) {
            item.calculateResults();
          }
        };
    treeRoot.doRecursive(countResults, 0);
  }