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

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.