Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
BaseTypeTreeItem.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-16 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 java.util.function.Supplier;
26 import javafx.scene.control.TreeItem;
29 import org.sleuthkit.datamodel.TimelineEventType;
30 
34 class BaseTypeTreeItem extends EventTypeTreeItem {
35 
40  private final Map<Object, EventsTreeItem> childMap = new HashMap<>();
41 
49  BaseTypeTreeItem(DetailViewEvent event, Comparator<TreeItem<DetailViewEvent>> comparator) {
50  super(event.getEventType().getBaseType(), comparator);
51  }
52 
54  @Override
55  public void insert(List<DetailViewEvent> path) {
56  DetailViewEvent head = path.get(0);
57 
58  Supplier< EventsTreeItem> treeItemConstructor;
59  String descriptionKey;
60  /*
61  * if the stripe and this tree item have the same type, create a
62  * description tree item, else create a sub-type tree item
63  */
64  if (head.getEventType().getTypeLevel() == TimelineEventType.TypeLevel.SUB_TYPE) {
65  descriptionKey = head.getEventType().getDisplayName();
66  treeItemConstructor = () -> configureNewTreeItem(new SubTypeTreeItem(head, getComparator()));
67  } else {
68  descriptionKey = head.getDescription();
69  DetailViewEvent stripe = path.remove(0); //remove head of list if we are going straight to description
70  treeItemConstructor = () -> configureNewTreeItem(new DescriptionTreeItem(stripe, getComparator()));
71  }
72 
73  EventsTreeItem treeItem = childMap.computeIfAbsent(descriptionKey, key -> treeItemConstructor.get());
74 
75  //insert (rest of) path in to new treeItem
76  if (path.isEmpty() == false) {
77  treeItem.insert(path);
78  }
79  }
80 
81  @Override
82  void remove(List<DetailViewEvent> path) {
83  DetailViewEvent head = path.get(0);
84 
85  EventsTreeItem descTreeItem;
86  /*
87  * if the stripe and this tree item have the same type, get the child
88  * item keyed on event type, else keyed on description.
89  */
90  if (head.getEventType().getTypeLevel() == TimelineEventType.TypeLevel.SUB_TYPE) {
91  descTreeItem = childMap.get(head.getEventType().getDisplayName());
92  } else {
93  path.remove(0); //remove head of list if we are going straight to description
94  descTreeItem = childMap.get(head.getDescription());
95  }
96 
97  //remove path from child too
98  if (descTreeItem != null) {
99  if (path.isEmpty() == false) {
100  descTreeItem.remove(path);
101  }
102  //if child item has no children, remove it also.
103  if (descTreeItem.getChildren().isEmpty()) {
104  childMap.remove(head.getDescription());
105  getChildren().remove(descTreeItem);
106  }
107  }
108  }
109 }

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.