Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EventTypeTreeItem.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-14 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.Deque;
23 import java.util.HashMap;
24 import java.util.Map;
25 import javafx.collections.FXCollections;
26 import javafx.scene.control.TreeItem;
29 
30 class EventTypeTreeItem extends NavTreeItem {
31 
35  private final Map<String, EventDescriptionTreeItem> childMap = new HashMap<>();
36 
37  private Comparator<TreeItem<EventBundle<?>>> comparator = TreeComparator.Description;
38 
39  EventTypeTreeItem(EventBundle<?> g, Comparator<TreeItem<EventBundle<?>>> comp) {
40  setValue(g);
41  comparator = comp;
42  }
43 
44  @Override
45  public long getCount() {
46  return getValue().getCount();
47  }
48 
49  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
50  public void insert(Deque<EventBundle<?>> path) {
51  EventBundle<?> head = path.removeFirst();
52  EventDescriptionTreeItem treeItem = childMap.computeIfAbsent(head.getDescription(), description -> {
53  EventDescriptionTreeItem newTreeItem = new EventDescriptionTreeItem(head, comparator);
54  newTreeItem.setExpanded(true);
55  childMap.put(head.getDescription(), newTreeItem);
56  getChildren().add(newTreeItem);
57  resort(comparator, false);
58  return newTreeItem;
59  });
60 
61  if (path.isEmpty() == false) {
62  treeItem.insert(path);
63  }
64  }
65 
66  void remove(Deque<EventBundle<?>> path) {
67  EventBundle<?> head = path.removeFirst();
68  EventDescriptionTreeItem descTreeItem = childMap.get(head.getDescription());
69  if (descTreeItem != null) {
70  if (path.isEmpty() == false) {
71  descTreeItem.remove(path);
72  }
73  if (descTreeItem.getChildren().isEmpty()) {
74  childMap.remove(head.getDescription());
75  getChildren().remove(descTreeItem);
76  }
77  }
78  }
79 
80  @Override
81  public NavTreeItem findTreeItemForEvent(EventBundle<?> t) {
82  if (t.getEventType().getBaseType() == getValue().getEventType().getBaseType()) {
83 
84  for (EventDescriptionTreeItem child : childMap.values()) {
85  final NavTreeItem findTreeItemForEvent = child.findTreeItemForEvent(t);
86  if (findTreeItemForEvent != null) {
87  return findTreeItemForEvent;
88  }
89  }
90  }
91  return null;
92  }
93 
94  @Override
95  void resort(Comparator<TreeItem<EventBundle<?>>> comp, Boolean recursive) {
96  this.comparator = comp;
97  FXCollections.sort(getChildren(), comp);
98  if (recursive) {
99  childMap.values().forEach(ti -> ti.resort(comp, true));
100  }
101  }
102 }

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.