Autopsy  4.4
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-2016 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.Collections;
25 import java.util.List;
26 import java.util.logging.Level;
27 import org.openide.nodes.Sheet;
28 import org.openide.util.NbBundle;
29 import org.openide.util.lookup.Lookups;
32 import org.sleuthkit.datamodel.Content;
33 import org.sleuthkit.datamodel.TskCoreException;
34 
38 public class DataSourcesNode extends DisplayableItemNode {
39 
40  public static final String NAME = NbBundle.getMessage(DataSourcesNode.class, "DataSourcesNode.name");
41 
42  // NOTE: The images passed in via argument will be ignored.
43  @Deprecated
44  public DataSourcesNode(List<Content> images) {
45  super(new DataSourcesNodeChildren(), Lookups.singleton(NAME));
46  init();
47  }
48 
49  public DataSourcesNode() {
50  super(new DataSourcesNodeChildren(), Lookups.singleton(NAME));
51  init();
52  }
53 
54  private void init() {
55  setName(NAME);
56  setDisplayName(NAME);
57  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); //NON-NLS
58  }
59 
60  @Override
61  public String getItemType() {
62  return getClass().getName();
63  }
64 
65  /*
66  * Custom Keys implementation that listens for new data sources being added.
67  */
68  public static class DataSourcesNodeChildren extends AbstractContentChildren<Content> {
69 
70  private static final Logger logger = Logger.getLogger(DataSourcesNodeChildren.class.getName());
71 
72  List<Content> currentKeys;
73 
75  super();
76  this.currentKeys = new ArrayList<>();
77  }
78 
79  private final PropertyChangeListener pcl = new PropertyChangeListener() {
80  @Override
81  public void propertyChange(PropertyChangeEvent evt) {
82  String eventType = evt.getPropertyName();
83  if (eventType.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
84  reloadKeys();
85  }
86  }
87  };
88 
89  @Override
90  protected void addNotify() {
92  reloadKeys();
93  }
94 
95  @Override
96  protected void removeNotify() {
98  currentKeys.clear();
99  setKeys(Collections.<Content>emptySet());
100  }
101 
102  private void reloadKeys() {
103  try {
104  currentKeys = Case.getCurrentCase().getDataSources();
105  setKeys(currentKeys);
106  } catch (TskCoreException | IllegalStateException ex) {
107  logger.log(Level.SEVERE, "Error getting data sources: {0}", ex.getMessage()); // NON-NLS
108  setKeys(Collections.<Content>emptySet());
109  }
110  }
111 
115  public void refreshContentKeys() {
116  for (Content key : currentKeys) {
117  refreshKey(key);
118  }
119  }
120  }
121 
122  @Override
123  public boolean isLeafTypeNode() {
124  return false;
125  }
126 
127  @Override
128  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
129  return v.visit(this);
130  }
131 
132  @Override
133  protected Sheet createSheet() {
134  Sheet s = super.createSheet();
135  Sheet.Set ss = s.get(Sheet.PROPERTIES);
136  if (ss == null) {
137  ss = Sheet.createPropertiesSet();
138  s.put(ss);
139  }
140 
141  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.name"),
142  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.displayName"),
143  NbBundle.getMessage(this.getClass(), "DataSourcesNode.createSheet.name.desc"),
144  NAME));
145  return s;
146  }
147 }
List< Content > getDataSources()
Definition: Case.java:1266
static void removePropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:369
static void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:357
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Tue Jun 13 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.