Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourcesByTypeNode.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.lookup.Lookups;
38 import org.sleuthkit.datamodel.TskCoreException;
39 
43 @Messages({
44  "DataSourcesHostsNode_name=Data Sources"
45 })
47 
48  /*
49  * Custom Keys implementation that listens for new data sources being added.
50  */
51  public static class DataSourcesByTypeChildren extends ChildFactory.Detachable<HostDataSources> {
52 
53  private static final Set<Case.Events> UPDATE_EVTS = EnumSet.of(
58 
59  private static final Set<String> UPDATE_EVT_STRS = UPDATE_EVTS.stream()
60  .map(evt -> evt.name())
61  .collect(Collectors.toSet());
62 
63  private static final Logger logger = Logger.getLogger(DataSourcesByTypeChildren.class.getName());
64 
65  private final PropertyChangeListener pcl = new PropertyChangeListener() {
66  @Override
67  public void propertyChange(PropertyChangeEvent evt) {
68  String eventType = evt.getPropertyName();
69  if (UPDATE_EVT_STRS.contains(eventType)) {
70  refresh(true);
71  }
72  }
73  };
74 
75  @Override
76  protected void addNotify() {
77  Case.addEventTypeSubscriber(UPDATE_EVTS, pcl);
78  }
79 
80  @Override
81  protected void removeNotify() {
82  Case.removeEventTypeSubscriber(UPDATE_EVTS, pcl);
83  }
84 
85  @Override
86  protected boolean createKeys(List<HostDataSources> toPopulate) {
87  try {
88  Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().getAllHosts().stream()
89  .map(HostDataSources::new)
90  .sorted()
91  .forEach(toPopulate::add);
92 
93  } catch (TskCoreException | NoCurrentCaseException ex) {
94  logger.log(Level.SEVERE, "Error getting data sources: {0}", ex.getMessage()); // NON-NLS
95  }
96 
97  return true;
98  }
99 
100  @Override
101  protected Node createNodeForKey(HostDataSources key) {
102  return new HostNode(key);
103  }
104 
105  }
106 
107  private static final String NAME = Bundle.DataSourcesHostsNode_name();
108 
112  public static String getNameIdentifier() {
113  return NAME;
114  }
115 
120  super(Children.create(new DataSourcesByTypeChildren(), false), Lookups.singleton(NAME));
121  setName(NAME);
122  setDisplayName(NAME);
123  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png");
124  }
125 
126  @Override
127  public String getItemType() {
128  return getClass().getName();
129  }
130 
131  @Override
132  public boolean isLeafTypeNode() {
133  return false;
134  }
135 
136  @Override
137  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
138  return visitor.visit(this);
139  }
140 
141  @Override
142  protected Sheet createSheet() {
143  Sheet sheet = super.createSheet();
144  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
145  if (sheetSet == null) {
146  sheetSet = Sheet.createPropertiesSet();
147  sheet.put(sheetSet);
148  }
149 
150  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.name"),
151  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.displayName"),
152  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.desc"),
153  NAME));
154  return sheet;
155  }
156 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:658
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:703

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