Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EventRootNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-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.explorernodes;
20 
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.logging.Level;
26 import org.openide.nodes.AbstractNode;
27 import org.openide.nodes.ChildFactory;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.Lookups;
37 import org.sleuthkit.datamodel.TskCoreException;
38 
42 public class EventRootNode extends DisplayableItemNode {
43 
44  private static final long serialVersionUID = 1L;
45 
51  public static final int MAX_EVENTS_TO_DISPLAY = 5000;
52 
53  public EventRootNode(Collection<Long> fileIds, FilteredEventsModel filteredEvents) {
54  super(Children.create(new EventNodeChildFactory(fileIds, filteredEvents), true), Lookups.singleton(fileIds));
55  }
56 
57  @Override
58  public boolean isLeafTypeNode() {
59  return false;
60  }
61 
62  @Override
63  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
64  return null;
65  }
66 
67  @Override
68  public String getItemType() {
69  return getClass().getName();
70  }
71 
75  private static class EventNodeChildFactory extends ChildFactory<Long> {
76 
77  private static final Logger LOGGER = Logger.getLogger(EventNodeChildFactory.class.getName());
78 
82  private final Collection<Long> eventIDs;
83 
88  private Map<Long, Node > nodesMap = new HashMap<>();
89 
90 
91  EventNodeChildFactory(Collection<Long> fileIds, FilteredEventsModel filteredEvents) {
92  this.eventIDs = fileIds;
93  this.filteredEvents = filteredEvents;
94  }
95 
96  @Override
97  protected boolean createKeys(List<Long> toPopulate) {
102  if (eventIDs.size() < MAX_EVENTS_TO_DISPLAY) {
103  for (Long eventId: eventIDs){
104  if (!nodesMap.containsKey(eventId)) {
105  nodesMap.put(eventId, createNode(eventId));
106  }
107  toPopulate.add(eventId);
108  }
109  } else {
110  if (!nodesMap.containsKey(-1L)) {
111  nodesMap.put(-1L, createNode(-1L));
112  }
113  toPopulate.add(-1L);
114  }
115  return true;
116  }
117 
118  @Override
119  protected Node createNodeForKey(Long eventID) {
120  return nodesMap.get(eventID);
121  }
122 
123  private Node createNode(Long eventID) {
124 
125  if (eventID < 0) {
126  /*
127  * If the eventId is a the special value ( -1 ), return a node
128  * with a warning that their are too many evens
129  */
130  return new TooManyNode(eventIDs.size());
131  } else {
132  try {
133  return EventNode.createEventNode(eventID, filteredEvents);
134  } catch (NoCurrentCaseException ex) {
135  //Since the case is closed, the user probably doesn't care about this, just log it as a precaution.
136  LOGGER.log(Level.SEVERE, "There was no case open to lookup the Sleuthkit object backing a SingleEvent.", ex); // NON-NLS
137  return null;
138  } catch (TskCoreException ex) {
139  /*
140  * Just log it: There might be lots of these errors, and we
141  * don't want to flood the user with notifications. It will
142  * be obvious the UI is broken anyways
143  */
144  LOGGER.log(Level.SEVERE, "Failed to lookup Sleuthkit object backing a SingleEvent.", ex); // NON-NLS
145  return null;
146  }
147  }
148  }
149  }
150 
154  private static class TooManyNode extends AbstractNode {
155 
156  @NbBundle.Messages({
157  "# {0} - maximum number of events to display",
158  "# {1} - the number of events that is too many",
159  "EventRoodNode.tooManyNode.displayName=Too many events to display. Maximum = {0}. But there are {1} to display."})
160  TooManyNode(int size) {
161  super(Children.LEAF);
162  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/info-icon-16.png"); // NON-NLS
163  setDisplayName(Bundle.EventRoodNode_tooManyNode_displayName(MAX_EVENTS_TO_DISPLAY, size));
164  }
165  }
166 }
static EventNode createEventNode(final Long eventID, FilteredEventsModel eventsModel)
Definition: EventNode.java:219
EventRootNode(Collection< Long > fileIds, FilteredEventsModel filteredEvents)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.