Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourcesNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.datamodel;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.EnumSet;
24 import java.util.List;
25 import java.util.Set;
26 import java.util.logging.Level;
27 import java.util.stream.Collectors;
28 import org.openide.nodes.ChildFactory;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Node;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.NbBundle;
33 import org.openide.util.NbBundle.Messages;
34 import org.openide.util.WeakListeners;
35 import org.openide.util.lookup.Lookups;
39 import org.sleuthkit.datamodel.TskCoreException;
40 
50 @Messages({
51  "DataSourcesHostsNode_name=Data Sources"
52 })
53 public class DataSourcesNode extends DisplayableItemNode {
54 
55  /*
56  * Custom Keys implementation that listens for new data sources being added.
57  */
58  public static class DataSourcesByTypeChildren extends ChildFactory.Detachable<HostDataSources> {
59 
60  private static final Set<Case.Events> UPDATE_EVTS = EnumSet.of(Case.Events.DATA_SOURCE_ADDED,
64 
65  private static final Set<String> UPDATE_EVT_STRS = UPDATE_EVTS.stream()
66  .map(evt -> evt.name())
67  .collect(Collectors.toSet());
68 
69  private static final Logger logger = Logger.getLogger(DataSourcesByTypeChildren.class.getName());
70 
71  private final PropertyChangeListener pcl = new PropertyChangeListener() {
72  @Override
73  public void propertyChange(PropertyChangeEvent evt) {
74  String eventType = evt.getPropertyName();
75  if (UPDATE_EVT_STRS.contains(eventType)) {
76  refresh(true);
77  }
78  }
79  };
80 
81  private final PropertyChangeListener weakPcl = WeakListeners.propertyChange(pcl, null);
82 
83  @Override
84  protected void addNotify() {
85  Case.addEventTypeSubscriber(UPDATE_EVTS, weakPcl);
86  }
87 
88  @Override
89  protected void finalize() throws Throwable{
90  Case.removeEventTypeSubscriber(UPDATE_EVTS, weakPcl);
91  super.finalize();
92  }
93 
94  @Override
95  protected boolean createKeys(List<HostDataSources> toPopulate) {
96  try {
97  Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().getAllHosts().stream()
98  .map(HostDataSources::new)
99  .sorted()
100  .forEach(toPopulate::add);
101 
102  } catch (TskCoreException | NoCurrentCaseException ex) {
103  logger.log(Level.SEVERE, "Error getting data sources: {0}", ex.getMessage()); // NON-NLS
104  }
105 
106  return true;
107  }
108 
109  @Override
110  protected Node createNodeForKey(HostDataSources key) {
111  return new HostNode(key);
112  }
113 
114  }
115 
116  private static final String NAME = Bundle.DataSourcesHostsNode_name();
117 
121  public static String getNameIdentifier() {
122  return NAME;
123  }
124 
128  DataSourcesNode() {
129  super(Children.create(new DataSourcesByTypeChildren(), true), Lookups.singleton(NAME));
130  setName(NAME);
131  setDisplayName(NAME);
132  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png");
133  }
134 
135  @Override
136  public String getItemType() {
137  return getClass().getName();
138  }
139 
140  @Override
141  public boolean isLeafTypeNode() {
142  return false;
143  }
144 
145  @Override
146  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
147  return visitor.visit(this);
148  }
149 
150  @Override
151  protected Sheet createSheet() {
152  Sheet sheet = super.createSheet();
153  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
154  if (sheetSet == null) {
155  sheetSet = Sheet.createPropertiesSet();
156  sheet.put(sheetSet);
157  }
158 
159  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.name"),
160  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.displayName"),
161  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.desc"),
162  NAME));
163  return sheet;
164  }
165 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:711
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:756

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.