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

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.