Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceSummaryTabbedPane.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.awt.CardLayout;
22 import java.awt.Component;
23 import java.beans.PropertyChangeListener;
24 import java.util.Arrays;
25 import java.util.EnumSet;
26 import java.util.List;
27 import java.util.function.Consumer;
28 import java.util.function.Function;
29 import org.openide.util.NbBundle.Messages;
34 import org.sleuthkit.datamodel.DataSource;
35 
40 @Messages({
41  "DataSourceSummaryTabbedPane_typesTab_title=Types",
42  "DataSourceSummaryTabbedPane_detailsTab_title=Container",
43  "DataSourceSummaryTabbedPane_userActivityTab_title=User Activity",
44  "DataSourceSummaryTabbedPane_ingestHistoryTab_title=Ingest History",
45  "DataSourceSummaryTabbedPane_recentFileTab_title=Recent Files",
46  "DataSourceSummaryTabbedPane_pastCasesTab_title=Past Cases",
47  "DataSourceSummaryTabbedPane_analysisTab_title=Analysis",
48  "DataSourceSummaryTabbedPane_geolocationTab_title=Geolocation",
49  "DataSourceSummaryTabbedPane_timelineTab_title=Timeline",
50  "DataSourceSummaryTabbedPane_exportTab_title=Export"
51 })
52 public class DataSourceSummaryTabbedPane extends javax.swing.JPanel {
53 
58  private class DataSourceTab implements ExportableTab {
59 
60  private final String tabTitle;
61  private final Component component;
62  private final Consumer<DataSource> onDataSource;
63  private final Function<DataSource, List<ExcelSheetExport>> excelExporter;
64  private final Runnable onClose;
65  private final Runnable onInit;
66 
73  DataSourceTab(String tabTitle, BaseDataSourceSummaryPanel panel) {
74  this(tabTitle, panel, panel::setDataSource, panel::getExports, panel::close, panel::init);
75  panel.setParentCloseListener(() -> notifyParentClose());
76  }
77 
92  DataSourceTab(String tabTitle, Component component, Consumer<DataSource> onDataSource,
93  Function<DataSource, List<ExcelSheetExport>> excelExporter, Runnable onClose,
94  Runnable onInit) {
95  this.tabTitle = tabTitle;
96  this.component = component;
97  this.onDataSource = onDataSource;
98  this.excelExporter = excelExporter;
99  this.onClose = onClose;
100  this.onInit = onInit;
101  }
102 
106  @Override
107  public String getTabTitle() {
108  return tabTitle;
109  }
110 
114  Component getComponent() {
115  return component;
116  }
117 
121  Consumer<DataSource> getOnDataSource() {
122  return onDataSource;
123  }
124 
125  @Override
126  public List<ExcelSheetExport> getExcelExports(DataSource dataSource) {
127  return excelExporter == null ? null : excelExporter.apply(dataSource);
128  }
129 
133  public Runnable getOnClose() {
134  return onClose;
135  }
136 
141  public Runnable getOnInit() {
142  return onInit;
143  }
144  }
145 
146  private static final long serialVersionUID = 1L;
147 
148  // needs to match value provided for card layout in designed
149  private static final String TABBED_PANE = "tabbedPane";
150  private static final String NO_DATASOURCE_PANE = "noDataSourcePane";
151 
152  private Runnable notifyParentClose = null;
153  private final IngestJobInfoPanel ingestHistoryPanel = new IngestJobInfoPanel();
154 
155  // create an export panel whose button triggers the export to XLSX action
156  private final ExportPanel exportPanel = new ExportPanel();
157 
158  private final List<DataSourceTab> tabs = Arrays.asList(
159  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_typesTab_title(), new TypesPanel()),
160  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_userActivityTab_title(), new UserActivityPanel()),
161  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_analysisTab_title(), new AnalysisPanel()),
162  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_recentFileTab_title(), new RecentFilesPanel()),
163  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_pastCasesTab_title(), new PastCasesPanel()),
164  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_geolocationTab_title(), new GeolocationPanel()),
165  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_timelineTab_title(), new TimelinePanel()),
166  // do nothing on closing
167  new DataSourceTab(
168  Bundle.DataSourceSummaryTabbedPane_ingestHistoryTab_title(),
169  ingestHistoryPanel,
170  ingestHistoryPanel::setDataSource,
171  IngestJobExcelExport::getExports,
172  null,
173  null),
174  new DataSourceTab(Bundle.DataSourceSummaryTabbedPane_detailsTab_title(), new ContainerPanel()),
175  new DataSourceTab(
176  Bundle.DataSourceSummaryTabbedPane_exportTab_title(),
177  exportPanel,
178  null,
179  null,
180  null,
181  null)
182  );
183 
184  // the action that does the export
185  private final ExcelExportAction exportAction = new ExcelExportAction(tabs);
186 
187  private DataSource dataSource = null;
188  private CardLayout cardLayout;
189 
193  private final PropertyChangeListener caseEventsListener = (evt) -> {
194  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString()) && evt.getNewValue() == null) {
195  setDataSource(null);
196  }
197  };
198 
203  initComponents();
204  postInit();
205  Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), caseEventsListener);
206  }
207 
211  private void notifyParentClose() {
212  if (notifyParentClose != null) {
213  notifyParentClose.run();
214  }
215  }
216 
222  void setParentCloseListener(Runnable parentCloseAction) {
223  notifyParentClose = parentCloseAction;
224  }
225 
229  private void postInit() {
230  // get the card layout
231  cardLayout = (CardLayout) this.getLayout();
232 
233  // set up the tabs
234  for (DataSourceTab tab : tabs) {
235  tabbedPane.addTab(tab.getTabTitle(), tab.getComponent());
236 
237  // initialize the tab pane if it has an initialization method
238  Runnable onInitMethod = tab.getOnInit();
239  if (onInitMethod != null) {
240  onInitMethod.run();
241  }
242  }
243 
244  // set this to no datasource initially
245  cardLayout.show(this, NO_DATASOURCE_PANE);
246 
247  // set action for when user requests xlsx export
248  exportPanel.setXlsxExportAction(() -> exportAction.accept(getDataSource()));
249  }
250 
256  public DataSource getDataSource() {
257  return dataSource;
258  }
259 
265  public void setDataSource(DataSource dataSource) {
266  this.dataSource = dataSource;
267 
268  for (DataSourceTab tab : tabs) {
269  if (tab.getOnDataSource() != null) {
270  tab.getOnDataSource().accept(dataSource);
271  }
272  }
273 
274  if (this.dataSource == null) {
275  cardLayout.show(this, NO_DATASOURCE_PANE);
276  } else {
277  cardLayout.show(this, TABBED_PANE);
278  }
279  }
280 
284  public void close() {
285  for (DataSourceTab tab : tabs) {
286  if (tab.getOnClose() != null) {
287  tab.getOnClose().run();
288  }
289  }
290 
291  Case.removeEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), caseEventsListener);
292  }
293 
299  @SuppressWarnings("unchecked")
300  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
301  private void initComponents() {
302 
303  javax.swing.JPanel noDataSourcePane = new javax.swing.JPanel();
304  javax.swing.JLabel noDataSourceLabel = new javax.swing.JLabel();
305  javax.swing.JPanel tabContentPane = new javax.swing.JPanel();
306  tabbedPane = new javax.swing.JTabbedPane();
307 
308  setLayout(new java.awt.CardLayout());
309 
310  noDataSourcePane.setLayout(new java.awt.BorderLayout());
311 
312  noDataSourceLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
313  org.openide.awt.Mnemonics.setLocalizedText(noDataSourceLabel, org.openide.util.NbBundle.getMessage(DataSourceSummaryTabbedPane.class, "DataSourceSummaryTabbedPane.noDataSourceLabel.text")); // NOI18N
314  noDataSourcePane.add(noDataSourceLabel, java.awt.BorderLayout.CENTER);
315 
316  add(noDataSourcePane, "noDataSourcePane");
317 
318  tabContentPane.setLayout(new java.awt.BorderLayout());
319  tabContentPane.add(tabbedPane, java.awt.BorderLayout.CENTER);
320 
321  add(tabContentPane, "tabbedPane");
322  }// </editor-fold>//GEN-END:initComponents
323 
324 
325  // Variables declaration - do not modify//GEN-BEGIN:variables
326  private javax.swing.JTabbedPane tabbedPane;
327  // End of variables declaration//GEN-END:variables
328 }
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:711
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:756

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.