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

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