Autopsy  4.1
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;
30 
34 class BaseTypeTreeItem extends EventTypeTreeItem {
35 
40  private final Map<Object, EventsTreeItem> childMap = new HashMap<>();
41 
49  BaseTypeTreeItem(TimeLineEvent event, Comparator<TreeItem<TimeLineEvent>> comparator) {
50  super(event.getEventType().getBaseType(), comparator);
51  }
52 
54  @Override
55  public void insert(List<TimeLineEvent> path) {
56  TimeLineEvent 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  */
65  descriptionKey = head.getEventType().getDisplayName();
66  treeItemConstructor = () -> configureNewTreeItem(new SubTypeTreeItem(head, getComparator()));
67  } else {
68  descriptionKey = head.getDescription();
69  TimeLineEvent 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<TimeLineEvent> path) {
83  TimeLineEvent 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  */
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-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.