Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AutopsyTreeChildFactory.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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.Objects;
30 import java.util.logging.Level;
31 import org.openide.nodes.ChildFactory;
32 import org.openide.nodes.Node;
37 import org.sleuthkit.datamodel.DataSource;
38 import org.sleuthkit.datamodel.SleuthkitCase;
39 import org.sleuthkit.datamodel.SleuthkitVisitableItem;
40 import org.sleuthkit.datamodel.TskCoreException;
41 
42 
47 public final class AutopsyTreeChildFactory extends ChildFactory.Detachable<Object> {
48 
49  private static final Logger logger = Logger.getLogger(AutopsyTreeChildFactory.class.getName());
50 
54  private final PropertyChangeListener pcl = new PropertyChangeListener() {
55  @Override
56  public void propertyChange(PropertyChangeEvent evt) {
57  String eventType = evt.getPropertyName();
58  if (eventType.equals(Case.Events.DATA_SOURCE_ADDED.toString()) &&
59  Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(), true)) {
61  }
62  }
63  };
64 
65  @Override
66  protected void addNotify() {
67  super.addNotify();
69  }
70 
71  @Override
72  protected void removeNotify() {
73  super.removeNotify();
75  }
76 
83  @Override
84  protected boolean createKeys(List<Object> list) {
85 
86  try {
87  SleuthkitCase tskCase = Case.getCurrentCaseThrows().getSleuthkitCase();
88 
89  if (Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(), true)) {
90  List<DataSource> dataSources = tskCase.getDataSources();
91 
92  Collections.sort(dataSources, new Comparator<DataSource>() {
93  @Override
94  public int compare(DataSource dataS1, DataSource dataS2) {
95  String dataS1Name = dataS1.getName().toLowerCase();
96  String dataS2Name = dataS2.getName().toLowerCase();
97  return dataS1Name.compareTo(dataS2Name);
98  }
99  });
100 
101  List<DataSourceGrouping> keys = new ArrayList<>();
102  dataSources.forEach((datasource) -> {
103  keys.add(new DataSourceGrouping(datasource));
104  });
105  list.addAll(keys);
106 
107  list.add(new Reports());
108  } else {
109  List<AutopsyVisitableItem> keys = new ArrayList<>(Arrays.asList(
110  new DataSources(),
111  new Views(tskCase),
112  new Results(tskCase),
113  new Tags(),
114  new Reports()));
115 
116  list.addAll(keys);
117  }
118 
119  } catch (TskCoreException tskCoreException) {
120  logger.log(Level.SEVERE, "Error getting datas sources list from the database.", tskCoreException);
121  } catch (NoCurrentCaseException ex) {
122  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
123  }
124  return true;
125  }
126 
134  @Override
135  protected Node createNodeForKey(Object key) {
136 
137  if (key instanceof SleuthkitVisitableItem) {
138  return ((SleuthkitVisitableItem) key).accept(new CreateSleuthkitNodeVisitor());
139  } else if (key instanceof AutopsyVisitableItem) {
140  return ((AutopsyVisitableItem) key).accept(new RootContentChildren.CreateAutopsyNodeVisitor());
141  }
142  else {
143  logger.log(Level.SEVERE, "Unknown key type ", key.getClass().getName());
144  return null;
145  }
146  }
147 
151  public void refreshChildren() {
152  refresh(true);
153  }
154 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:477
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:522

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.