Autopsy  4.6.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 = 103),
54  @ActionReference(path = "Toolbars/Case", position = 103)})
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  try {
76  if (tableReport != null) {
77  generator.generateTableReport(tableReport, (Map<BlackboardArtifact.Type, Boolean>) wiz.getProperty("artifactStates"), (Map<String, Boolean>) wiz.getProperty("tagStates")); //NON-NLS
78  } else if (generalReport != null) {
79  generator.generateGeneralReport(generalReport);
80  } else if (fileReport != null) {
81  generator.generateFileListReport(fileReport, (Map<FileReportDataTypes, Boolean>) wiz.getProperty("fileReportOptions")); //NON-NLS
82  }
83  } catch (IOException e) {
84  NotifyDescriptor descriptor = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
85  DialogDisplayer.getDefault().notify(descriptor);
86  }
87  }
88  }
89 
90  public ReportWizardAction() {
91  setEnabled(false);
92  Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
93  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
94  Case newCase = (Case) evt.getNewValue();
95  setEnabled(newCase != null && RuntimeProperties.runningWithGUI());
96  }
97  });
98 
99  // Initialize the Generate Report button
100  toolbarButton.addActionListener(ReportWizardAction.this::actionPerformed);
101  }
102 
103  @Override
104  @SuppressWarnings("unchecked")
105  public void actionPerformed(ActionEvent e) {
106  doReportWizard();
107  }
108 
109  @Override
110  public void performAction() {
111  }
112 
113  @Override
114  public String getName() {
115  return ACTION_NAME;
116  }
117 
118  @Override
119  public HelpCtx getHelpCtx() {
120  return HelpCtx.DEFAULT_HELP;
121  }
122 
128  @Override
129  public Component getToolbarPresenter() {
130  ImageIcon icon = new ImageIcon(getClass().getResource("images/btn_icon_generate_report.png")); //NON-NLS
131  toolbarButton.setIcon(icon);
132  toolbarButton.setText(NbBundle.getMessage(this.getClass(), "ReportWizardAction.toolBarButton.text"));
133  return toolbarButton;
134  }
135 
141  @Override
142  public void setEnabled(boolean value) {
143  super.setEnabled(value);
144  toolbarButton.setEnabled(value);
145  }
146 }
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:420

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.