Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportWizardAction.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2013-2018 Basis Technology Corp.
6  *
7  * Copyright 2012 42six Solutions.
8  * Contact: aebadirad <at> 42six <dot> com
9  * Project Contact/Architect: carrier <at> sleuthkit <dot> org
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.sleuthkit.autopsy.report;
24 
25 import java.awt.Component;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.beans.PropertyChangeEvent;
29 import java.io.IOException;
30 import java.text.MessageFormat;
31 import java.util.EnumSet;
32 import java.util.Map;
33 import javax.swing.ImageIcon;
34 import javax.swing.JButton;
35 import org.openide.DialogDisplayer;
36 import org.openide.NotifyDescriptor;
37 import org.openide.WizardDescriptor;
38 import org.openide.awt.ActionID;
39 import org.openide.awt.ActionReference;
40 import org.openide.awt.ActionReferences;
41 import org.openide.awt.ActionRegistration;
42 import org.openide.util.HelpCtx;
43 import org.openide.util.NbBundle;
44 import org.openide.util.actions.CallableSystemAction;
45 import org.openide.util.actions.Presenter;
48 import org.sleuthkit.datamodel.BlackboardArtifact;
49 
50 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.report.ReportWizardAction")
51 @ActionRegistration(displayName = "#CTL_ReportWizardAction", lazy = false)
52 @ActionReferences(value = {
53  @ActionReference(path = "Menu/Tools", position = 301, separatorAfter = 399),
54  @ActionReference(path = "Toolbars/Case", position = 105)})
55 public final class ReportWizardAction extends CallableSystemAction implements Presenter.Toolbar, ActionListener {
56 
57  private final JButton toolbarButton = new JButton();
58  private static final String ACTION_NAME = NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.actionName.text");
59 
65  @SuppressWarnings("unchecked")
66  public static void doReportWizard() {
67  WizardDescriptor wiz = new WizardDescriptor(new ReportWizardIterator());
68  wiz.setTitleFormat(new MessageFormat("{0} {1}"));
69  wiz.setTitle(NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.reportWiz.title"));
70  if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
71  ReportGenerator generator = new ReportGenerator(); //NON-NLS
72  TableReportModule tableReport = (TableReportModule) wiz.getProperty("tableModule");
73  GeneralReportModule generalReport = (GeneralReportModule) wiz.getProperty("generalModule");
74  FileReportModule fileReport = (FileReportModule) wiz.getProperty("fileModule");
75  PortableCaseReportModule portableCaseReport = (PortableCaseReportModule) wiz.getProperty("portableCaseModule"); // NON-NLS
76  try {
77  if (tableReport != null) {
78  generator.generateTableReport(tableReport, (Map<BlackboardArtifact.Type, Boolean>) wiz.getProperty("artifactStates"), (Map<String, Boolean>) wiz.getProperty("tagStates")); //NON-NLS
79  } else if (generalReport != null) {
80  generator.generateGeneralReport(generalReport);
81  } else if (fileReport != null) {
82  generator.generateFileListReport(fileReport, (Map<FileReportDataTypes, Boolean>) wiz.getProperty("fileReportOptions")); //NON-NLS
83  } else if (portableCaseReport != null) {
84  generator.generatePortableCaseReport(portableCaseReport, (PortableCaseReportModule.PortableCaseOptions) wiz.getProperty("portableCaseReportOptions"));
85  }
86  } catch (IOException e) {
87  NotifyDescriptor descriptor = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
88  DialogDisplayer.getDefault().notify(descriptor);
89  }
90  }
91  }
92 
93  public ReportWizardAction() {
94  setEnabled(false);
95  Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
96  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
97  Case newCase = (Case) evt.getNewValue();
98  setEnabled(newCase != null && RuntimeProperties.runningWithGUI());
99  }
100  });
101 
102  // Initialize the Generate Report button
103  toolbarButton.addActionListener(ReportWizardAction.this::actionPerformed);
104  }
105 
106  @Override
107  @SuppressWarnings("unchecked")
108  public void actionPerformed(ActionEvent e) {
109  doReportWizard();
110  }
111 
112  @Override
113  public void performAction() {
114  }
115 
116  @Override
117  public String getName() {
118  return ACTION_NAME;
119  }
120 
121  @Override
122  public HelpCtx getHelpCtx() {
123  return HelpCtx.DEFAULT_HELP;
124  }
125 
131  @Override
132  public Component getToolbarPresenter() {
133  ImageIcon icon = new ImageIcon(getClass().getResource("images/btn_icon_generate_report.png")); //NON-NLS
134  toolbarButton.setIcon(icon);
135  toolbarButton.setText(NbBundle.getMessage(this.getClass(), "ReportWizardAction.toolBarButton.text"));
136  return toolbarButton;
137  }
138 
144  @Override
145  public void setEnabled(boolean value) {
146  super.setEnabled(value);
147  toolbarButton.setEnabled(value);
148  }
149 }
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:477

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