Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DescriptionTreeItem.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-19 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.timeline.ui.detailview.tree;
20 
21 import java.util.Comparator;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import javafx.collections.FXCollections;
26 import javafx.scene.control.TreeItem;
27 import org.apache.commons.lang3.StringUtils;
30 import org.sleuthkit.datamodel.TimelineEventType;
31 
35 class DescriptionTreeItem extends EventsTreeItem {
36 
40  private final Map<String, DescriptionTreeItem> childMap = new HashMap<>();
41 
49  DescriptionTreeItem(DetailViewEvent event, Comparator<TreeItem<DetailViewEvent>> comparator) {
50  super(comparator);
51  setValue(event);
52  }
53 
54  @Override
55  public void insert(List<DetailViewEvent> path) {
56  DetailViewEvent head = path.remove(0);
57 
58  //strip off parent description
59  String substringAfter = StringUtils.substringAfter(head.getDescription(), head.getParentStripe().map(EventStripe::getDescription).orElse(""));
60 
61  //create or get existing tree item for the description
62  DescriptionTreeItem treeItem = childMap.computeIfAbsent(substringAfter,
63  description -> configureNewTreeItem(new DescriptionTreeItem(head, getComparator()))
64  );
65 
66  //insert rest of path in to tree item
67  if (path.isEmpty() == false) {
68  treeItem.insert(path);
69  }
70  }
71 
72  @Override
73  void remove(List<DetailViewEvent> path) {
74  DetailViewEvent head = path.remove(0);
75  //strip off parent description
76  String substringAfter = StringUtils.substringAfter(head.getDescription(), head.getParentStripe().map(EventStripe::getDescription).orElse(""));
77 
78  DescriptionTreeItem descTreeItem = childMap.get(substringAfter);
79 
80  //remove path from child too
81  if (descTreeItem != null) {
82  if (path.isEmpty() == false) {
83  descTreeItem.remove(path);
84  }
85  //if child item has no children, remove it also.
86  if (descTreeItem.getChildren().isEmpty()) {
87  childMap.remove(substringAfter);
88  getChildren().remove(descTreeItem);
89  }
90  }
91  }
92 
93  @Override
94  void sort(Comparator<TreeItem<DetailViewEvent>> comparator, Boolean recursive) {
95  setComparator(comparator);
96  FXCollections.sort(getChildren(), comparator); //sort children with new comparator
97  if (recursive) {
98  //resort children's children
99  childMap.values().forEach(treeItem -> treeItem.sort(comparator, true));
100  }
101  }
102 
103  @Override
104  public EventsTreeItem findTreeItemForEvent(DetailViewEvent event) {
105  if (getValue().getEventType() == event.getEventType()
106  && getValue().getDescription().equals(event.getDescription())) {
107  //if this tree item match the given event, return this.
108  return this;
109  } else {
110  //search children
111  return super.findTreeItemForEvent(event);
112  }
113  }
114 
115  @Override
116  String getDisplayText() {
117 
118  String text = getValue().getDescription() + " (" + getValue().getSize() + ")"; // NON-NLS
119 
120  TreeItem<DetailViewEvent> parent = getParent();
121  if (parent != null && parent.getValue() != null && (parent instanceof DescriptionTreeItem)) {
122  //strip off parent description
123  text = StringUtils.substringAfter(text, parent.getValue().getDescription());
124  }
125  return text;
126  }
127 
128  @Override
129  TimelineEventType getEventType() {
130  return getValue().getEventType();
131  }
132 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.