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

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