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

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.