Autopsy  4.10.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.List;
23 import javax.swing.table.AbstractTableModel;
24 import org.openide.util.NbBundle.Messages;
25 
29 public class OtherOccurrencesFilesTableModel extends AbstractTableModel {
30 
31  private static final long serialVersionUID = 1L;
32 
33  @Messages({"OtherOccurrencesFilesTableModel.device=Device",
34  "OtherOccurrencesFilesTableModel.dataSource=Data Source",
35  "OtherOccurrencesFilesTableModel.path=Path",
36  "OtherOccurrencesFilesTableModel.attribute=Matched Attribute",
37  "OtherOccurrencesFilesTableModel.value=Attribute Value",
38  "OtherOccurrencesFilesTableModel.known=Known",
39  "OtherOccurrencesFilesTableModel.comment=Comment",
40  "OtherOccurrencesFilesTableModel.noData=No Data.",})
41  enum TableColumns {
42  // Ordering here determines displayed column order in Content Viewer.
43  // If order is changed, update the CellRenderer to ensure correct row coloring.
44  ATTRIBUTE(Bundle.OtherOccurrencesFilesTableModel_attribute(), 75),
45  VALUE(Bundle.OtherOccurrencesFilesTableModel_value(), 190),
46  KNOWN(Bundle.OtherOccurrencesFilesTableModel_known(), 25),
47  FILE_PATH(Bundle.OtherOccurrencesFilesTableModel_path(), 470),
48  COMMENT(Bundle.OtherOccurrencesFilesTableModel_comment(), 190);
49 
50  private final String columnName;
51  private final int columnWidth;
52 
53  TableColumns(String columnName, int columnWidth) {
54  this.columnName = columnName;
55  this.columnWidth = columnWidth;
56  }
57 
58  public String columnName() {
59  return columnName;
60  }
61 
62  public int columnWidth() {
63  return columnWidth;
64  }
65  };
66 
67  private final List<OtherOccurrenceNodeData> nodeDataList = new ArrayList<>();
68 
70 
71  }
72 
73  @Override
74  public int getColumnCount() {
75  return TableColumns.values().length;
76  }
77 
88  public int getColumnPreferredWidth(int colIdx) {
89  return TableColumns.values()[colIdx].columnWidth();
90  }
91 
92  @Override
93  public int getRowCount() {
94  return nodeDataList.size();
95  }
96 
97  @Override
98  public String getColumnName(int colIdx) {
99  return TableColumns.values()[colIdx].columnName();
100  }
101 
102  @Override
103  public Object getValueAt(int rowIdx, int colIdx) {
104  if (0 == nodeDataList.size()) {
105  return Bundle.OtherOccurrencesFilesTableModel_noData();
106  }
107 
108  OtherOccurrenceNodeData nodeData = nodeDataList.get(rowIdx);
109  TableColumns columnId = TableColumns.values()[colIdx];
110  if (nodeData instanceof OtherOccurrenceNodeMessageData) {
111  return mapNodeMessageData((OtherOccurrenceNodeMessageData) nodeData, columnId);
112  }
113  return mapNodeInstanceData((OtherOccurrenceNodeInstanceData) nodeData, columnId);
114  }
115 
124  private Object mapNodeMessageData(OtherOccurrenceNodeMessageData nodeData, TableColumns columnId) {
125  if (columnId == TableColumns.ATTRIBUTE) {
126  return nodeData.getDisplayMessage();
127  }
128  return "";
129  }
130 
139  private Object mapNodeInstanceData(OtherOccurrenceNodeInstanceData nodeData, TableColumns columnId) {
140  String value = Bundle.OtherOccurrencesFilesTableModel_noData();
141 
142  switch (columnId) {
143  case FILE_PATH:
144  value = nodeData.getFilePath();
145  break;
146  case ATTRIBUTE:
147  value = nodeData.getType();
148  break;
149  case VALUE:
150  value = nodeData.getValue();
151  break;
152  case KNOWN:
153  value = nodeData.getKnown().getName();
154  break;
155  case COMMENT:
156  value = nodeData.getComment();
157  break;
158  default: //Use default "No data" value.
159  break;
160  }
161  return value;
162  }
163 
164  Object getRow(int rowIdx) {
165  return nodeDataList.get(rowIdx);
166  }
167 
168  @Override
169  public Class<String> getColumnClass(int colIdx) {
170  return String.class;
171  }
172 
178  void addNodeData(OtherOccurrenceNodeData newNodeData) {
179  nodeDataList.add(newNodeData);
180  fireTableDataChanged();
181  }
182 
186  void clearTable() {
187  nodeDataList.clear();
188  fireTableDataChanged();
189  }
190 
191 }
Object mapNodeMessageData(OtherOccurrenceNodeMessageData nodeData, TableColumns columnId)
Object mapNodeInstanceData(OtherOccurrenceNodeInstanceData nodeData, TableColumns columnId)

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