Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestJobInfoPanel.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.casemodule;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.text.DateFormat;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.logging.Level;
28 import javax.swing.JOptionPane;
29 import javax.swing.event.ListSelectionEvent;
30 import javax.swing.table.AbstractTableModel;
31 import org.openide.util.NbBundle.Messages;
34 import org.sleuthkit.datamodel.IngestJobInfo;
35 import org.sleuthkit.datamodel.IngestModuleInfo;
36 import org.sleuthkit.datamodel.SleuthkitCase;
37 import org.sleuthkit.datamodel.TskCoreException;
38 
42 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
43 public final class IngestJobInfoPanel extends javax.swing.JPanel {
44 
45  private static final Logger logger = Logger.getLogger(IngestJobInfoPanel.class.getName());
46  private List<IngestJobInfo> ingestJobs;
47  private IngestJobTableModel ingestJobTableModel = new IngestJobTableModel();
48  private IngestModuleTableModel ingestModuleTableModel = new IngestModuleTableModel(null);
49  private final DateFormat datetimeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
50 
54  public IngestJobInfoPanel() {
55  initComponents();
56  customizeComponents();
57  }
58 
59  @Messages({"IngestJobInfoPanel.loadIngestJob.error.text=Failed to load ingest jobs.",
60  "IngestJobInfoPanel.loadIngestJob.error.title=Load Failure"})
61  private void customizeComponents() {
62  refresh();
63  this.ingestJobTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
64  this.ingestModuleTableModel = new IngestModuleTableModel(this.ingestJobs.get(ingestJobTable.getSelectedRow()));
65  this.ingestModuleTable.setModel(this.ingestModuleTableModel);
66  });
67 
68  IngestManager.getInstance().addIngestJobEventListener((PropertyChangeEvent evt) -> {
69  if (evt.getPropertyName().equals(IngestManager.IngestJobEvent.STARTED.toString())
70  || evt.getPropertyName().equals(IngestManager.IngestJobEvent.CANCELLED.toString())
71  || evt.getPropertyName().equals(IngestManager.IngestJobEvent.COMPLETED.toString())) {
72  refresh();
73  }
74  });
75  }
76 
77  private void refresh() {
78  try {
79  SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
80  List<IngestJobInfo> ingestJobs = skCase.getIngestJobs();
81  this.ingestJobs = ingestJobs;
82  this.repaint();
83  } catch (TskCoreException | NoCurrentCaseException ex) {
84  logger.log(Level.SEVERE, "Failed to load ingest jobs.", ex);
85  JOptionPane.showMessageDialog(this, Bundle.IngestJobInfoPanel_loadIngestJob_error_text(), Bundle.IngestJobInfoPanel_loadIngestJob_error_title(), JOptionPane.ERROR_MESSAGE);
86  }
87  }
88 
89  @Messages({"IngestJobInfoPanel.IngestJobTableModel.DataSource.header=Data Source",
90  "IngestJobInfoPanel.IngestJobTableModel.StartTime.header=Start Time",
91  "IngestJobInfoPanel.IngestJobTableModel.EndTime.header=End Time",
92  "IngestJobInfoPanel.IngestJobTableModel.IngestStatus.header=Ingest Status"})
93  private class IngestJobTableModel extends AbstractTableModel {
94 
95  private final List<String> columnHeaders = new ArrayList<>();
96 
98  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestJobTableModel_DataSource_header());
99  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestJobTableModel_StartTime_header());
100  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestJobTableModel_EndTime_header());
101  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestJobTableModel_IngestStatus_header());
102  }
103 
104  @Override
105  public int getRowCount() {
106  return ingestJobs.size();
107  }
108 
109  @Override
110  public int getColumnCount() {
111  return columnHeaders.size();
112  }
113 
114  @Override
115  public Object getValueAt(int rowIndex, int columnIndex) {
116  IngestJobInfo currIngestJob = ingestJobs.get(rowIndex);
117  if (columnIndex == 0) {
118  try {
119  SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
120  return skCase.getContentById(currIngestJob.getObjectId()).getName();
121  } catch (TskCoreException | NoCurrentCaseException ex) {
122  logger.log(Level.SEVERE, "Failed to get content from db", ex);
123  return "";
124  }
125  } else if (columnIndex == 1) {
126  return datetimeFormat.format(currIngestJob.getStartDateTime());
127  } else if (columnIndex == 2) {
128  Date endDate = currIngestJob.getEndDateTime();
129  if (endDate.getTime() == 0) {
130  return "N/A";
131  }
132  return datetimeFormat.format(currIngestJob.getEndDateTime());
133  } else if (columnIndex == 3) {
134  return currIngestJob.getStatus().getDisplayName();
135  }
136  return null;
137  }
138 
139  @Override
140  public String getColumnName(int column) {
141  return columnHeaders.get(column);
142  }
143 
144  }
145 
146  @Messages({"IngestJobInfoPanel.IngestModuleTableModel.ModuleName.header=Module Name",
147  "IngestJobInfoPanel.IngestModuleTableModel.ModuleVersion.header=Module Version"})
148  private class IngestModuleTableModel extends AbstractTableModel {
149 
150  private final List<String> columnHeaders = new ArrayList<>();
151  private final IngestJobInfo currJob;
152 
153  IngestModuleTableModel(IngestJobInfo currJob) {
154  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestModuleTableModel_ModuleName_header());
155  columnHeaders.add(Bundle.IngestJobInfoPanel_IngestModuleTableModel_ModuleVersion_header());
156  this.currJob = currJob;
157  }
158 
159  @Override
160  public int getRowCount() {
161  if (currJob == null) {
162  return 0;
163  }
164  return currJob.getIngestModuleInfo().size();
165  }
166 
167  @Override
168  public int getColumnCount() {
169  return columnHeaders.size();
170  }
171 
172  @Override
173  public Object getValueAt(int rowIndex, int columnIndex) {
174  if (currJob != null) {
175  IngestModuleInfo currIngestModule = currJob.getIngestModuleInfo().get(rowIndex);
176  if (columnIndex == 0) {
177  return currIngestModule.getDisplayName();
178  } else if (columnIndex == 1) {
179  return currIngestModule.getVersion();
180  }
181  return null;
182  }
183  return null;
184  }
185 
186  @Override
187  public String getColumnName(int column) {
188  return columnHeaders.get(column);
189  }
190 
191  }
192 
198  @SuppressWarnings("unchecked")
199  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
200  private void initComponents() {
201 
202  jScrollPane1 = new javax.swing.JScrollPane();
203  ingestJobTable = new javax.swing.JTable();
204  jLabel1 = new javax.swing.JLabel();
205  jLabel2 = new javax.swing.JLabel();
206  jScrollPane2 = new javax.swing.JScrollPane();
207  ingestModuleTable = new javax.swing.JTable();
208 
209  jScrollPane1.setBorder(null);
210 
211  ingestJobTable.setModel(ingestJobTableModel);
212  ingestJobTable.getTableHeader().setReorderingAllowed(false);
213  jScrollPane1.setViewportView(ingestJobTable);
214  ingestJobTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
215 
216  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(IngestJobInfoPanel.class, "IngestJobInfoPanel.jLabel1.text")); // NOI18N
217 
218  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(IngestJobInfoPanel.class, "IngestJobInfoPanel.jLabel2.text")); // NOI18N
219 
220  ingestModuleTable.setModel(ingestModuleTableModel);
221  jScrollPane2.setViewportView(ingestModuleTable);
222 
223  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
224  this.setLayout(layout);
225  layout.setHorizontalGroup(
226  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
227  .addGroup(layout.createSequentialGroup()
228  .addGap(15, 15, 15)
229  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
230  .addComponent(jLabel2)
231  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE))
232  .addGap(8, 8, 8)
233  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
234  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
235  .addComponent(jLabel1))
236  .addContainerGap())
237  );
238  layout.setVerticalGroup(
239  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240  .addGroup(layout.createSequentialGroup()
241  .addGap(8, 8, 8)
242  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
243  .addComponent(jLabel1)
244  .addComponent(jLabel2))
245  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
246  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
248  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
249  .addGap(10, 10, 10))
250  );
251  }// </editor-fold>//GEN-END:initComponents
252 
253 
254  // Variables declaration - do not modify//GEN-BEGIN:variables
255  private javax.swing.JTable ingestJobTable;
256  private javax.swing.JTable ingestModuleTable;
257  private javax.swing.JLabel jLabel1;
258  private javax.swing.JLabel jLabel2;
259  private javax.swing.JScrollPane jScrollPane1;
260  private javax.swing.JScrollPane jScrollPane2;
261  // End of variables declaration//GEN-END:variables
262 }
static synchronized IngestManager getInstance()
void addIngestJobEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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.