Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentViewerOtherCasesTableModel.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-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.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 DataContentViewerOtherCasesTableModel extends AbstractTableModel {
30 
31  private static final long serialVersionUID = 1L;
32 
33  @Messages({"DataContentViewerOtherCasesTableModel.case=Case",
34  "DataContentViewerOtherCasesTableModel.device=Device",
35  "DataContentViewerOtherCasesTableModel.dataSource=Data Source",
36  "DataContentViewerOtherCasesTableModel.path=Path",
37  "DataContentViewerOtherCasesTableModel.attribute=Matched Attribute",
38  "DataContentViewerOtherCasesTableModel.value=Attribute Value",
39  "DataContentViewerOtherCasesTableModel.known=Known",
40  "DataContentViewerOtherCasesTableModel.comment=Comment",
41  "DataContentViewerOtherCasesTableModel.noData=No Data.",})
42  enum TableColumns {
43  // Ordering here determines displayed column order in Content Viewer.
44  // If order is changed, update the CellRenderer to ensure correct row coloring.
45  CASE_NAME(Bundle.DataContentViewerOtherCasesTableModel_case(), 100),
46  DATA_SOURCE(Bundle.DataContentViewerOtherCasesTableModel_dataSource(), 100),
47  ATTRIBUTE(Bundle.DataContentViewerOtherCasesTableModel_attribute(), 125),
48  VALUE(Bundle.DataContentViewerOtherCasesTableModel_value(), 200),
49  KNOWN(Bundle.DataContentViewerOtherCasesTableModel_known(), 50),
50  FILE_PATH(Bundle.DataContentViewerOtherCasesTableModel_path(), 450),
51  COMMENT(Bundle.DataContentViewerOtherCasesTableModel_comment(), 200),
52  DEVICE(Bundle.DataContentViewerOtherCasesTableModel_device(), 250);
53 
54  private final String columnName;
55  private final int columnWidth;
56 
57  TableColumns(String columnName, int columnWidth) {
58  this.columnName = columnName;
59  this.columnWidth = columnWidth;
60  }
61 
62  public String columnName() {
63  return columnName;
64  }
65 
66  public int columnWidth() {
67  return columnWidth;
68  }
69  };
70 
71  private final List<OtherOccurrenceNodeData> nodeDataList;
72 
74  nodeDataList = new ArrayList<>();
75  }
76 
77  @Override
78  public int getColumnCount() {
79  return TableColumns.values().length;
80  }
81 
92  public int getColumnPreferredWidth(int colIdx) {
93  return TableColumns.values()[colIdx].columnWidth();
94  }
95 
96  @Override
97  public int getRowCount() {
98  return nodeDataList.size();
99  }
100 
101  @Override
102  public String getColumnName(int colIdx) {
103  return TableColumns.values()[colIdx].columnName();
104  }
105 
106  @Override
107  public Object getValueAt(int rowIdx, int colIdx) {
108  if (0 == nodeDataList.size()) {
109  return Bundle.DataContentViewerOtherCasesTableModel_noData();
110  }
111 
112  OtherOccurrenceNodeData nodeData = nodeDataList.get(rowIdx);
113  TableColumns columnId = TableColumns.values()[colIdx];
114  if (nodeData instanceof OtherOccurrenceNodeMessageData) {
115  return mapNodeMessageData((OtherOccurrenceNodeMessageData) nodeData, columnId);
116  }
117  return mapNodeInstanceData((OtherOccurrenceNodeInstanceData) nodeData, columnId);
118  }
119 
128  private Object mapNodeMessageData(OtherOccurrenceNodeMessageData nodeData, TableColumns columnId) {
129  if (columnId == TableColumns.CASE_NAME) {
130  return nodeData.getDisplayMessage();
131  }
132  return "";
133  }
134 
143  private Object mapNodeInstanceData(OtherOccurrenceNodeInstanceData nodeData, TableColumns columnId) {
144  String value = Bundle.DataContentViewerOtherCasesTableModel_noData();
145 
146  switch (columnId) {
147  case CASE_NAME:
148  if (null != nodeData.getCaseName()) {
149  value = nodeData.getCaseName();
150  }
151  break;
152  case DEVICE:
153  if (null != nodeData.getDeviceID()) {
154  value = nodeData.getDeviceID();
155  }
156  break;
157  case DATA_SOURCE:
158  if (null != nodeData.getDataSourceName()) {
159  value = nodeData.getDataSourceName();
160  }
161  break;
162  case FILE_PATH:
163  value = nodeData.getFilePath();
164  break;
165  case ATTRIBUTE:
166  value = nodeData.getType();
167  break;
168  case VALUE:
169  value = nodeData.getValue();
170  break;
171  case KNOWN:
172  value = nodeData.getKnown().getName();
173  break;
174  case COMMENT:
175  value = nodeData.getComment();
176  break;
177  default: // This shouldn't occur! Use default "No data" value.
178  break;
179  }
180  return value;
181  }
182 
183  Object getRow(int rowIdx) {
184  return nodeDataList.get(rowIdx);
185  }
186 
187  @Override
188  public Class<String> getColumnClass(int colIdx) {
189  return String.class;
190  }
191 
197  void addNodeData(OtherOccurrenceNodeData newNodeData) {
198  nodeDataList.add(newNodeData);
199  fireTableDataChanged();
200  }
201 
205  void clearTable() {
206  nodeDataList.clear();
207  fireTableDataChanged();
208  }
209 
210 }

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