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

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.