19 package org.sleuthkit.autopsy.timeline.ui.detailview.tree;
21 import java.util.Comparator;
22 import java.util.HashMap;
23 import java.util.List;
25 import javafx.collections.FXCollections;
26 import javafx.scene.control.TreeItem;
27 import org.apache.commons.lang3.StringUtils;
35 class DescriptionTreeItem
extends EventsTreeItem {
40 private final Map<String, DescriptionTreeItem> childMap =
new HashMap<>();
49 DescriptionTreeItem(TimeLineEvent event, Comparator<TreeItem<TimeLineEvent>> comparator) {
55 public void insert(List<TimeLineEvent> path) {
56 TimeLineEvent head = path.remove(0);
59 String substringAfter = StringUtils.substringAfter(head.getDescription(), head.getParentStripe().map(
EventStripe::getDescription).orElse(
""));
62 DescriptionTreeItem treeItem = childMap.computeIfAbsent(substringAfter,
63 description -> configureNewTreeItem(
new DescriptionTreeItem(head, getComparator()))
67 if (path.isEmpty() ==
false) {
68 treeItem.insert(path);
73 void remove(List<TimeLineEvent> path) {
74 TimeLineEvent head = path.remove(0);
76 String substringAfter = StringUtils.substringAfter(head.getDescription(), head.getParentStripe().map(
EventStripe::getDescription).orElse(
""));
78 DescriptionTreeItem descTreeItem = childMap.get(substringAfter);
81 if (descTreeItem != null) {
82 if (path.isEmpty() ==
false) {
83 descTreeItem.remove(path);
86 if (descTreeItem.getChildren().isEmpty()) {
87 childMap.remove(substringAfter);
88 getChildren().remove(descTreeItem);
94 void sort(Comparator<TreeItem<TimeLineEvent>> comparator, Boolean recursive) {
95 setComparator(comparator);
96 FXCollections.sort(getChildren(), comparator);
99 childMap.values().forEach(ti -> ti.sort(comparator,
true));
104 public EventsTreeItem findTreeItemForEvent(TimeLineEvent event) {
105 if (getValue().getEventType() == event.getEventType()
106 && getValue().getDescription().equals(event.getDescription())) {
111 return super.findTreeItemForEvent(event);
116 String getDisplayText() {
118 String text = getValue().getDescription() +
" (" + getValue().getSize() +
")";
120 TreeItem<TimeLineEvent> parent = getParent();
121 if (parent != null && parent.getValue() != null && (parent instanceof DescriptionTreeItem)) {
123 text = StringUtils.substringAfter(text, parent.getValue().getDescription());
129 EventType getEventType() {
130 return getValue().getEventType();