Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
RootItem.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.ArrayDeque;
22 import java.util.Comparator;
23 import java.util.Deque;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Optional;
27 import javafx.scene.control.TreeItem;
31 
35 class RootItem extends NavTreeItem {
36 
40  private final Map<EventType, EventTypeTreeItem> childMap = new HashMap<>();
41 
45  private Comparator<TreeItem<EventBundle<?>>> comparator = TreeComparator.Type.reversed();
46 
47  RootItem(Comparator<TreeItem<EventBundle<?>>> comp) {
48  comp = comp;
49  }
50 
51  @Override
52  public long getCount() {
53  return getValue().getCount();
54  }
55 
61  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
62  public void insert(EventBundle<?> bundle) {
63 
64  EventTypeTreeItem treeItem = childMap.computeIfAbsent(bundle.getEventType().getBaseType(),
65  baseType -> {
66  EventTypeTreeItem newTreeItem = new EventTypeTreeItem(bundle, comparator);
67  newTreeItem.setExpanded(true);
68  getChildren().add(newTreeItem);
69  return newTreeItem;
70  });
71  treeItem.insert(getTreePath(bundle));
72 
73  }
74 
75  void remove(EventBundle<?> bundle) {
76  EventTypeTreeItem typeTreeItem = childMap.get(bundle.getEventType().getBaseType());
77  if (typeTreeItem != null) {
78  typeTreeItem.remove(getTreePath(bundle));
79 
80  if (typeTreeItem.getChildren().isEmpty()) {
81  childMap.remove(bundle.getEventType().getBaseType());
82  getChildren().remove(typeTreeItem);
83  }
84  }
85  }
86 
87  static Deque< EventBundle<?>> getTreePath(EventBundle<?> g) {
88  Deque<EventBundle<?>> path = new ArrayDeque<>();
89  Optional<? extends EventBundle<?>> p = Optional.of(g);
90 
91  while (p.isPresent()) {
92  EventBundle<?> parent = p.get();
93  path.addFirst(parent);
94  p = parent.getParentBundle();
95  }
96 
97  return path;
98  }
99 
100  @Override
101  void resort(Comparator<TreeItem<EventBundle<?>>> comp, Boolean recursive) {
102  comparator = comp;
103  childMap.values().forEach(ti -> ti.resort(comp, true));
104  }
105 
106  @Override
107  public NavTreeItem findTreeItemForEvent(EventBundle<?> t) {
108  for (EventTypeTreeItem child : childMap.values()) {
109  final NavTreeItem findTreeItemForEvent = child.findTreeItemForEvent(t);
110  if (findTreeItemForEvent != null) {
111  return findTreeItemForEvent;
112  }
113  }
114  return null;
115  }
116 }

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.