Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
RecentFilesPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.datasourcesummary.ui;
20 
21 import java.text.DateFormat;
22 import java.text.SimpleDateFormat;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.function.Function;
29 import java.util.function.Supplier;
30 import java.util.stream.Collectors;
31 import java.util.stream.Stream;
32 import org.openide.util.NbBundle.Messages;
48 import org.sleuthkit.datamodel.DataSource;
49 
53 @Messages({
54  "RecentFilesPanel_docsTable_tabName=Recently Opened Documents",
55  "RecentFilesPanel_downloadsTable_tabName=Recently Downloads",
56  "RecentFilesPanel_attachmentsTable_tabName=Recent Attachments",})
57 public final class RecentFilesPanel extends BaseDataSourceSummaryPanel {
58 
59  private static final long serialVersionUID = 1L;
60  private static final String DATETIME_FORMAT_STR = "yyyy/MM/dd HH:mm:ss";
61  private static final DateFormat DATETIME_FORMAT = new SimpleDateFormat(DATETIME_FORMAT_STR, Locale.getDefault());
62 
63  private final List<JTablePanel<?>> tablePanelList = new ArrayList<>();
64  private final List<DataFetchWorker.DataFetchComponents<DataSource, ?>> dataFetchComponents = new ArrayList<>();
65 
66  private final IngestRunningLabel ingestRunningLabel = new IngestRunningLabel();
67 
71 
72  private final List<ColumnModel<RecentFileDetails, DefaultCellModel<?>>> docsTemplate = Arrays.asList(
73  new ColumnModel<>(Bundle.RecentFilePanel_col_header_path(),
74  (prog) -> {
75  return new DefaultCellModel<>(prog.getPath())
76  .setPopupMenuRetriever(getPopupFunct(prog));
77  }, 250),
78  new ColumnModel<>(Bundle.RecentFilesPanel_col_head_date(),
79  getDateFunct(),
80  80));
81 
82  private final List<ColumnModel<RecentDownloadDetails, DefaultCellModel<?>>> downloadsTemplate = Arrays.asList(
83  new ColumnModel<>(Bundle.RecentFilePanel_col_header_domain(),
84  (prog) -> {
85  return new DefaultCellModel<>(prog.getWebDomain())
86  .setPopupMenuRetriever(getPopupFunct(prog));
87  }, 100),
88  new ColumnModel<>(Bundle.RecentFilePanel_col_header_path(),
89  (prog) -> {
90  return new DefaultCellModel<>(prog.getPath())
91  .setPopupMenuRetriever(getPopupFunct(prog));
92  }, 250),
93  new ColumnModel<>(Bundle.RecentFilesPanel_col_head_date(),
94  getDateFunct(),
95  80));
96 
97  private final List<ColumnModel<RecentAttachmentDetails, DefaultCellModel<?>>> attachmentsTemplate = Arrays.asList(
98  new ColumnModel<>(Bundle.RecentFilePanel_col_header_path(),
99  (prog) -> {
100  return new DefaultCellModel<>(prog.getPath())
101  .setPopupMenuRetriever(getPopupFunct(prog));
102  }, 250),
103  new ColumnModel<>(Bundle.RecentFilesPanel_col_head_date(),
104  getDateFunct(),
105  80),
106  new ColumnModel<>(Bundle.RecentFilePanel_col_header_sender(),
107  (prog) -> {
108  return new DefaultCellModel<>(prog.getSender())
109  .setPopupMenuRetriever(getPopupFunct(prog));
110  }, 150));
111 
115  @Messages({
116  "RecentFilesPanel_col_head_date=Date",
117  "RecentFilePanel_col_header_domain=Domain",
118  "RecentFilePanel_col_header_path=Path",
119  "RecentFilePanel_col_header_sender=Sender",
120  "RecentFilePanel_emailParserModuleName=Email Parser"
121  })
122  public RecentFilesPanel() {
123  this(new RecentFilesSummary());
124  }
125 
129  public RecentFilesPanel(RecentFilesSummary dataHandler) {
130  super(dataHandler);
131  docsFetcher = (dataSource) -> dataHandler.getRecentlyOpenedDocuments(dataSource, 10);
132  downloadsFetcher = (dataSource) -> dataHandler.getRecentDownloads(dataSource, 10);
133  attachmentsFetcher = (dataSource) -> dataHandler.getRecentAttachments(dataSource, 10);
134 
135  initComponents();
136  initalizeTables();
137  }
138 
145  private <T extends RecentFileDetails> Function<T, DefaultCellModel<?>> getDateFunct() {
146  return (T lastAccessed) -> {
147  Function<Date, String> dateParser = (dt) -> dt == null ? "" : DATETIME_FORMAT.format(dt);
148  return new DefaultCellModel<>(new Date(lastAccessed.getDateAsLong() * 1000), dateParser, DATETIME_FORMAT_STR)
149  .setPopupMenuRetriever(getPopupFunct(lastAccessed));
150  };
151  }
152 
162  private Supplier<List<MenuItem>> getPopupFunct(RecentFileDetails record) {
163  return () -> {
164  if (record == null) {
165  return null;
166  }
167 
168  List<MenuItem> toRet = new ArrayList<>();
169 
170  MenuItem fileNav = getFileNavigateItem(record.getPath());
171  if (fileNav != null) {
172  toRet.add(fileNav);
173  }
174 
175  if (record.getArtifact() != null) {
176  toRet.add(getArtifactNavigateItem(record.getArtifact()));
177  }
178 
179  return (toRet.size() > 0) ? toRet : null;
180  };
181  }
182 
183  @Override
184  protected void fetchInformation(DataSource dataSource) {
185  fetchInformation(dataFetchComponents, dataSource);
186  }
187 
188  @Override
189  protected void onNewDataSource(DataSource dataSource) {
190  onNewDataSource(dataFetchComponents, tablePanelList, dataSource);
191  }
192 
193  @Override
194  List<ExcelExport.ExcelSheetExport> getExports(DataSource dataSource) {
195  return Stream.of(
196  getTableExport(docsFetcher, docsTemplate, Bundle.RecentFilesPanel_docsTable_tabName(), dataSource),
197  getTableExport(downloadsFetcher, downloadsTemplate, Bundle.RecentFilesPanel_downloadsTable_tabName(), dataSource),
198  getTableExport(attachmentsFetcher, attachmentsTemplate, Bundle.RecentFilesPanel_attachmentsTable_tabName(), dataSource))
199  .filter(sheet -> sheet != null)
200  .collect(Collectors.toList());
201  }
202 
203  @Override
204  public void close() {
205  ingestRunningLabel.unregister();
206  super.close();
207  }
208 
212  private void initalizeTables() {
213  initalizeOpenDocsTable();
214  initalizeDownloadTable();
215  initalizeAttchementsTable();
216  }
217 
218  @Messages({
219  "RecentFilePanel_no_open_documents=No recently open documents found."
220  })
224  @SuppressWarnings("unchecked")
225  private void initalizeOpenDocsTable() {
227 
229  pane.setModel(tableModel);
230  pane.setColumnModel(JTablePanel.getTableColumnModel(docsTemplate));
231  pane.setKeyFunction((recentFile) -> recentFile.getPath());
233  tablePanelList.add(pane);
234 
235  DataFetchWorker.DataFetchComponents<DataSource, List<RecentFileDetails>> worker
237  docsFetcher,
238  (result) -> pane.showDataFetchResult(result));
239 
240  dataFetchComponents.add(worker);
241  }
242 
246  @SuppressWarnings("unchecked")
247  private void initalizeDownloadTable() {
248  ListTableModel<RecentDownloadDetails> tableModel = JTablePanel.getTableModel(downloadsTemplate);
249 
251  pane.setModel(tableModel);
252  pane.setKeyFunction((download) -> download.getPath());
253  pane.setColumnModel(JTablePanel.getTableColumnModel(downloadsTemplate));
255  tablePanelList.add(pane);
256 
257  DataFetchWorker.DataFetchComponents<DataSource, List<RecentDownloadDetails>> worker
259  downloadsFetcher,
260  (result) -> pane.showDataFetchResult(result));
261 
262  dataFetchComponents.add(worker);
263  }
264 
268  @SuppressWarnings("unchecked")
269  private void initalizeAttchementsTable() {
270  ListTableModel<RecentAttachmentDetails> tableModel = JTablePanel.getTableModel(attachmentsTemplate);
271 
273  pane.setModel(tableModel);
274  pane.setKeyFunction((attachment) -> attachment.getPath());
275  pane.setColumnModel(JTablePanel.getTableColumnModel(attachmentsTemplate));
277  tablePanelList.add(pane);
278 
279  DataFetchWorker.DataFetchComponents<DataSource, List<RecentAttachmentDetails>> worker
281  attachmentsFetcher,
282  (result) -> pane.showDataFetchResult(result)
283  );
284 
285  dataFetchComponents.add(worker);
286  }
287 
293  @SuppressWarnings("unchecked")
294  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
295  private void initComponents() {
296  java.awt.GridBagConstraints gridBagConstraints;
297 
298  javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane();
299  javax.swing.JPanel tablePanel = new javax.swing.JPanel();
300  javax.swing.JPanel ingestRunningPanel = ingestRunningLabel;
301  openedDocPane = new JTablePanel<RecentFileDetails>();
302  downloadsPane = new JTablePanel<RecentDownloadDetails>();
303  attachmentsPane = new JTablePanel<RecentAttachmentDetails>();
304  javax.swing.JLabel openDocsLabel = new javax.swing.JLabel();
305  javax.swing.JLabel downloadLabel = new javax.swing.JLabel();
306  javax.swing.JLabel attachmentLabel = new javax.swing.JLabel();
307  javax.swing.JLabel rightClickForMoreOptions1 = new javax.swing.JLabel();
308  javax.swing.JLabel rightClickForMoreOptions2 = new javax.swing.JLabel();
309  javax.swing.JLabel rightClickForMoreOptions3 = new javax.swing.JLabel();
310 
311  setLayout(new java.awt.BorderLayout());
312 
313  tablePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
314  tablePanel.setMinimumSize(new java.awt.Dimension(400, 400));
315  tablePanel.setPreferredSize(new java.awt.Dimension(600, 400));
316  tablePanel.setLayout(new java.awt.GridBagLayout());
317 
318  ingestRunningPanel.setAlignmentX(0.0F);
319  ingestRunningPanel.setMaximumSize(new java.awt.Dimension(32767, 25));
320  ingestRunningPanel.setMinimumSize(new java.awt.Dimension(10, 25));
321  ingestRunningPanel.setPreferredSize(new java.awt.Dimension(10, 25));
322  gridBagConstraints = new java.awt.GridBagConstraints();
323  gridBagConstraints.gridx = 0;
324  gridBagConstraints.gridy = 0;
325  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
326  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
327  tablePanel.add(ingestRunningPanel, gridBagConstraints);
328  gridBagConstraints = new java.awt.GridBagConstraints();
329  gridBagConstraints.gridx = 0;
330  gridBagConstraints.gridy = 2;
331  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
332  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
333  gridBagConstraints.weightx = 1.0;
334  gridBagConstraints.weighty = 1.0;
335  gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
336  tablePanel.add(openedDocPane, gridBagConstraints);
337  gridBagConstraints = new java.awt.GridBagConstraints();
338  gridBagConstraints.gridx = 0;
339  gridBagConstraints.gridy = 5;
340  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
341  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
342  gridBagConstraints.weightx = 1.0;
343  gridBagConstraints.weighty = 1.0;
344  gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
345  tablePanel.add(downloadsPane, gridBagConstraints);
346  gridBagConstraints = new java.awt.GridBagConstraints();
347  gridBagConstraints.gridx = 0;
348  gridBagConstraints.gridy = 8;
349  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
350  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
351  gridBagConstraints.weightx = 1.0;
352  gridBagConstraints.weighty = 1.0;
353  gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
354  tablePanel.add(attachmentsPane, gridBagConstraints);
355 
356  org.openide.awt.Mnemonics.setLocalizedText(openDocsLabel, org.openide.util.NbBundle.getMessage(RecentFilesPanel.class, "RecentFilesPanel.openDocsLabel.text")); // NOI18N
357  gridBagConstraints = new java.awt.GridBagConstraints();
358  gridBagConstraints.gridx = 0;
359  gridBagConstraints.gridy = 1;
360  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
361  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
362  tablePanel.add(openDocsLabel, gridBagConstraints);
363 
364  org.openide.awt.Mnemonics.setLocalizedText(downloadLabel, org.openide.util.NbBundle.getMessage(RecentFilesPanel.class, "RecentFilesPanel.downloadLabel.text")); // NOI18N
365  gridBagConstraints = new java.awt.GridBagConstraints();
366  gridBagConstraints.gridx = 0;
367  gridBagConstraints.gridy = 4;
368  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
369  gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
370  tablePanel.add(downloadLabel, gridBagConstraints);
371 
372  org.openide.awt.Mnemonics.setLocalizedText(attachmentLabel, org.openide.util.NbBundle.getMessage(RecentFilesPanel.class, "RecentFilesPanel.attachmentLabel.text")); // NOI18N
373  gridBagConstraints = new java.awt.GridBagConstraints();
374  gridBagConstraints.gridx = 0;
375  gridBagConstraints.gridy = 7;
376  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
377  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
378  gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
379  tablePanel.add(attachmentLabel, gridBagConstraints);
380 
381  org.openide.awt.Mnemonics.setLocalizedText(rightClickForMoreOptions1, org.openide.util.NbBundle.getMessage(RecentFilesPanel.class, "RecentFilesPanel.rightClickForMoreOptions1.text")); // NOI18N
382  gridBagConstraints = new java.awt.GridBagConstraints();
383  gridBagConstraints.gridx = 0;
384  gridBagConstraints.gridy = 3;
385  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
386  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
387  tablePanel.add(rightClickForMoreOptions1, gridBagConstraints);
388 
389  org.openide.awt.Mnemonics.setLocalizedText(rightClickForMoreOptions2, org.openide.util.NbBundle.getMessage(RecentFilesPanel.class, "RecentFilesPanel.rightClickForMoreOptions2.text")); // NOI18N
390  gridBagConstraints = new java.awt.GridBagConstraints();
391  gridBagConstraints.gridx = 0;
392  gridBagConstraints.gridy = 6;
393  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
394  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
395  tablePanel.add(rightClickForMoreOptions2, gridBagConstraints);
396 
397  org.openide.awt.Mnemonics.setLocalizedText(rightClickForMoreOptions3, org.openide.util.NbBundle.getMessage(RecentFilesPanel.class, "RecentFilesPanel.rightClickForMoreOptions3.text")); // NOI18N
398  gridBagConstraints = new java.awt.GridBagConstraints();
399  gridBagConstraints.gridx = 0;
400  gridBagConstraints.gridy = 9;
401  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
402  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
403  tablePanel.add(rightClickForMoreOptions3, gridBagConstraints);
404 
405  scrollPane.setViewportView(tablePanel);
406 
407  add(scrollPane, java.awt.BorderLayout.CENTER);
408  }// </editor-fold>//GEN-END:initComponents
409 
410 
411  // Variables declaration - do not modify//GEN-BEGIN:variables
412  private javax.swing.JPanel attachmentsPane;
413  private javax.swing.JPanel downloadsPane;
414  private javax.swing.JPanel openedDocPane;
415  // End of variables declaration//GEN-END:variables
416 }
JTablePanel< T > setColumnModel(TableColumnModel columnModel)
static< T, CextendsGuiCellModel > TableColumnModel getTableColumnModel(List< ColumnModel< T, C >> columns)
final DataFetcher< DataSource, List< RecentAttachmentDetails > > attachmentsFetcher
List< RecentFileDetails > getRecentlyOpenedDocuments(DataSource dataSource, int maxCount)
DefaultCellModel< T > setPopupMenuRetriever(Supplier< List< MenuItem >> menuItemSupplier)
Supplier< List< MenuItem > > getPopupFunct(RecentFileDetails record)
void showDataFetchResult(DataFetchResult< T > result, String errorMessage, String noResultsMessage)
static< T, CextendsGuiCellModel > ListTableModel< T > getTableModel(List< ColumnModel< T, C >> columns)
List< RecentDownloadDetails > getRecentDownloads(DataSource dataSource, int maxCount)
final DataFetcher< DataSource, List< RecentFileDetails > > docsFetcher
JTablePanel< T > setCellListener(CellMouseListener cellListener)
final DataFetcher< DataSource, List< RecentDownloadDetails > > downloadsFetcher
List< RecentAttachmentDetails > getRecentAttachments(DataSource dataSource, int maxCount)
final JTablePanel< T > setModel(ListTableModel< T > tableModel)
JTablePanel< T > setKeyFunction(Function< T,?extends Object > keyFunction)

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.