Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OtherOccurrencesFilesTableModel.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-2019 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.centralrepository.contentviewer;
20 
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import javax.swing.table.AbstractTableModel;
26 import org.openide.util.NbBundle.Messages;
27 import org.apache.commons.io.FilenameUtils;
28 
33 public class OtherOccurrencesFilesTableModel extends AbstractTableModel {
34 
35  private static final long serialVersionUID = 1L;
36  private final List<String> nodeKeys = new ArrayList<>();
37  private final Map<String, List<OtherOccurrenceNodeData>> nodeMap = new HashMap<>();
38 
43  // This constructor is intentionally empty.
44  }
45 
46  @Override
47  public int getColumnCount() {
48  return 1;
49  }
50 
51  @Override
52  public int getRowCount() {
53  return nodeKeys.size();
54  }
55 
56  @Messages({"OtherOccurrencesFilesTableModel.fileName=File Name",
57  "OtherOccurrencesFilesTableModel.noData=No Data."})
58  @Override
59  public String getColumnName(int colIdx) {
60  return Bundle.OtherOccurrencesFilesTableModel_fileName();
61  }
62 
63  @Override
64  public Object getValueAt(int rowIdx, int colIdx) {
65  //if anything would prevent this from working we will consider it no data for the sake of simplicity
66  if (nodeMap.isEmpty() || nodeKeys.isEmpty() || rowIdx < 0
67  || rowIdx >= nodeKeys.size() || nodeKeys.get(rowIdx) == null
68  || nodeMap.get(nodeKeys.get(rowIdx)) == null
69  || nodeMap.get(nodeKeys.get(rowIdx)).isEmpty()) {
70  return Bundle.OtherOccurrencesFilesTableModel_noData();
71  }
72  return FilenameUtils.getName(((OtherOccurrenceNodeInstanceData) nodeMap.get(nodeKeys.get(rowIdx)).get(0)).getFilePath());
73  }
74 
84  List<OtherOccurrenceNodeData> getListOfNodesForFile(int rowIdx) {
85  //if anything would prevent this from working return an empty list
86  if (nodeMap.isEmpty() || nodeKeys.isEmpty() || rowIdx < 0
87  || rowIdx >= nodeKeys.size() || nodeKeys.get(rowIdx) == null
88  || nodeMap.get(nodeKeys.get(rowIdx)) == null) {
89  return new ArrayList<>();
90  }
91  return nodeMap.get(nodeKeys.get(rowIdx));
92  }
93 
94  @Override
95  public Class<String> getColumnClass(int colIdx) {
96  return String.class;
97  }
98 
104  void addNodeData(OtherOccurrenceNodeData newNodeData) {
105  String newNodeKey = createNodeKey((OtherOccurrenceNodeInstanceData) newNodeData);//FilenameUtils.getName(((OtherOccurrenceNodeInstanceData)newNodeData).getFilePath());
106  List<OtherOccurrenceNodeData> nodeList = nodeMap.get(newNodeKey);
107  if (nodeList == null) {
108  nodeKeys.add(newNodeKey);
109  nodeList = new ArrayList<>();
110  }
111  nodeList.add(newNodeData);
112  nodeMap.put(newNodeKey, nodeList);
113  fireTableDataChanged();
114  }
115 
116  private String createNodeKey(OtherOccurrenceNodeInstanceData nodeData) {
117  return nodeData.getCaseName() + nodeData.getDataSourceName() + nodeData.getDeviceID() + nodeData.getFilePath();
118  }
119 
123  void clearTable() {
124  nodeKeys.clear();
125  nodeMap.clear();
126  fireTableDataChanged();
127  }
128 
129 }

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