Autopsy  4.20.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;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
41 public class EventRootNode extends DisplayableItemNode {
42 
43  private static final long serialVersionUID = 1L;
44 
50  public static final int MAX_EVENTS_TO_DISPLAY = 5000;
51 
52  public EventRootNode(Collection<Long> eventIds, EventsModel filteredEvents) {
53  super(Children.create(new EventNodeChildFactory(eventIds, filteredEvents), true), Lookups.singleton(eventIds));
54  }
55 
56  @Override
57  public boolean isLeafTypeNode() {
58  return false;
59  }
60 
61  @Override
62  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
63  return null;
64  }
65 
66  @Override
67  public String getItemType() {
68  return getClass().getName();
69  }
70 
74  private static class EventNodeChildFactory extends ChildFactory<Long> {
75 
76  private static final Logger LOGGER = Logger.getLogger(EventNodeChildFactory.class.getName());
77 
81  private final Collection<Long> eventIDs;
82 
86  private final EventsModel filteredEvents;
87  private final Map<Long, Node> nodesMap = new HashMap<>();
88 
89  EventNodeChildFactory(Collection<Long> eventIds, EventsModel filteredEvents) {
90  this.eventIDs = eventIds;
91  this.filteredEvents = filteredEvents;
92  }
93 
94  @Override
95  protected boolean createKeys(List<Long> toPopulate) {
100  if (eventIDs.size() < MAX_EVENTS_TO_DISPLAY) {
101  for (Long eventId : eventIDs) {
102  nodesMap.computeIfAbsent(eventId, this::createNode);
103  toPopulate.add(eventId);
104  }
105  } else {
106  nodesMap.computeIfAbsent(-1L, this::createNode);
107  toPopulate.add(-1L);
108  }
109  return true;
110  }
111 
112  @Override
113  protected Node createNodeForKey(Long eventID) {
114  return nodesMap.get(eventID);
115  }
116 
117  private Node createNode(Long eventID) {
118  if (eventID < 0) {
119  /*
120  * If the eventId is a the special value ( -1 ), return a node
121  * with a warning that their are too many evens
122  */
123  return new TooManyNode(eventIDs.size());
124  } else {
125  try {
126  return EventNode.createEventNode(eventID, filteredEvents);
127  } catch (TskCoreException ex) {
128  /*
129  * Just log it: There might be lots of these errors, and we
130  * don't want to flood the user with notifications. It will
131  * be obvious the UI is broken anyways
132  */
133  LOGGER.log(Level.SEVERE, "Error creating explorer node for event id " + eventID + ".", ex); // NON-NLS
134  return null;
135  }
136  }
137  }
138  }
139 
143  private static class TooManyNode extends AbstractNode {
144 
145  @NbBundle.Messages({
146  "# {0} - maximum number of events to display",
147  "# {1} - the number of events that is too many",
148  "EventRoodNode.tooManyNode.displayName=Too many events to display. Maximum = {0}. But there are {1} to display."})
149  TooManyNode(int size) {
150  super(Children.LEAF);
151  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/info-icon-16.png"); // NON-NLS
152  setDisplayName(Bundle.EventRoodNode_tooManyNode_displayName(MAX_EVENTS_TO_DISPLAY, size));
153  }
154  }
155 }
static EventNode createEventNode(final Long eventID, EventsModel eventsModel)
Definition: EventNode.java:264
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
EventRootNode(Collection< Long > eventIds, EventsModel filteredEvents)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.