Autopsy  4.10.0
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 2011-2018 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.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.Comparator;
27 import java.util.EnumSet;
28 import java.util.List;
29 import java.util.logging.Level;
30 import org.openide.nodes.Sheet;
31 import org.openide.util.NbBundle;
32 import org.openide.util.lookup.Lookups;
36 import org.sleuthkit.datamodel.Content;
37 import org.sleuthkit.datamodel.TskCoreException;
38 import org.sleuthkit.datamodel.TskDataException;
39 
43 public class DataSourcesNode extends DisplayableItemNode {
44 
45  public static final String NAME = NbBundle.getMessage(DataSourcesNode.class, "DataSourcesNode.name");
46  private final String displayName;
47 
48  // NOTE: The images passed in via argument will be ignored.
49  @Deprecated
50  public DataSourcesNode(List<Content> images) {
51  this(0);
52  }
53 
54  public DataSourcesNode() {
55  this(0);
56  }
57 
58  public DataSourcesNode(long dsObjId) {
59  super(new DataSourcesNodeChildren(dsObjId), Lookups.singleton(NAME));
60  displayName = (dsObjId > 0) ? NbBundle.getMessage(DataSourcesNode.class, "DataSourcesNode.group_by_datasource.name") : NAME;
61  init();
62  }
63 
64  private void init() {
65  setName(NAME);
66  setDisplayName(displayName);
67  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); //NON-NLS
68  }
69 
70  @Override
71  public String getItemType() {
72  return getClass().getName();
73  }
74 
75  /*
76  * Custom Keys implementation that listens for new data sources being added.
77  */
78  public static class DataSourcesNodeChildren extends AbstractContentChildren<Content> {
79 
80  private static final Logger logger = Logger.getLogger(DataSourcesNodeChildren.class.getName());
81  private final long datasourceObjId;
82 
83  List<Content> currentKeys;
84 
86  this(0);
87  }
88 
89  public DataSourcesNodeChildren(long dsObjId) {
90  super();
91  this.currentKeys = new ArrayList<>();
92  this.datasourceObjId = dsObjId;
93  }
94 
95  private final PropertyChangeListener pcl = new PropertyChangeListener() {
96  @Override
97  public void propertyChange(PropertyChangeEvent evt) {
98  String eventType = evt.getPropertyName();
99  if (eventType.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
100  reloadKeys();
101  }
102  }
103  };
104 
105  @Override
106  protected void addNotify() {
108  reloadKeys();
109  }
110 
111  @Override
112  protected void removeNotify() {
114  currentKeys.clear();
115  setKeys(Collections.<Content>emptySet());
116  }
117 
118  private void reloadKeys() {
119  try {
120  if (datasourceObjId == 0) {
121  currentKeys = Case.getCurrentCaseThrows().getDataSources();
122  }
123  else {
124  Content content = Case.getCurrentCaseThrows().getSleuthkitCase().getDataSource(datasourceObjId);
125  currentKeys = new ArrayList<>(Arrays.asList(content));
126  }
127 
128  Collections.sort(currentKeys, new Comparator<Content>() {
129  @Override
130  public int compare(Content content1, Content content2) {
131  String content1Name = content1.getName().toLowerCase();
132  String content2Name = content2.getName().toLowerCase();
133  return content1Name.compareTo(content2Name);
134  }
135 
136  });
137 
138  setKeys(currentKeys);
139  } catch (TskCoreException | NoCurrentCaseException | TskDataException ex) {
140  logger.log(Level.SEVERE, "Error getting data sources: {0}", ex.getMessage()); // NON-NLS
141  setKeys(Collections.<Content>emptySet());
142  }
143  }
144 
148  public void refreshContentKeys() {
149  for (Content key : currentKeys) {
150  refreshKey(key);
151  }
152  }
153  }
154 
155  @Override
156  public boolean isLeafTypeNode() {
157  return false;
158  }
159 
160  @Override
161  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
162  return visitor.visit(this);
163  }
164 
165  @Override
166  protected Sheet createSheet() {
167  Sheet sheet = super.createSheet();
168  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
169  if (sheetSet == null) {
170  sheetSet = Sheet.createPropertiesSet();
171  sheet.put(sheetSet);
172  }
173 
174  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.name"),
175  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.displayName"),
176  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.desc"),
177  NAME));
178  return sheet;
179  }
180 }
List< Content > getDataSources()
Definition: Case.java:1495
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:437
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:482

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.