23 package org.sleuthkit.autopsy.report.infrastructure;
27 import java.awt.Component;
28 import java.awt.Cursor;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.beans.PropertyChangeEvent;
32 import java.text.MessageFormat;
33 import java.util.EnumSet;
34 import java.util.List;
36 import java.util.concurrent.ExecutionException;
37 import java.util.logging.Level;
38 import javax.swing.ImageIcon;
39 import javax.swing.JButton;
40 import javax.swing.SwingWorker;
41 import org.openide.DialogDisplayer;
42 import org.openide.NotifyDescriptor;
43 import org.openide.WizardDescriptor;
44 import org.openide.awt.ActionID;
45 import org.openide.awt.ActionReference;
46 import org.openide.awt.ActionReferences;
47 import org.openide.awt.ActionRegistration;
48 import org.openide.util.HelpCtx;
49 import org.openide.util.NbBundle;
50 import org.openide.util.actions.CallableSystemAction;
51 import org.openide.util.actions.Presenter;
52 import org.openide.windows.WindowManager;
59 @ActionID(category =
"Tools",
id =
"org.sleuthkit.autopsy.report.infrastructure.ReportWizardAction")
60 @ActionRegistration(displayName =
"#CTL_ReportWizardAction", lazy =
false)
61 @ActionReferences(value = {
62 @ActionReference(path =
"Menu/Tools", position = 301, separatorAfter = 399)
64 @ActionReference(path =
"Toolbars/Case", position = 106)})
65 public final class ReportWizardAction extends CallableSystemAction implements Presenter.Toolbar, ActionListener {
68 private static final String REPORTING_CONFIGURATION_NAME =
"ReportAction";
69 private static final boolean DISPLAY_CASE_SPECIFIC_DATA =
true;
70 private static final boolean RUN_REPORTS =
true;
71 private final JButton toolbarButton =
new JButton();
72 private static final String ACTION_NAME = NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.actionName.text");
73 private static ReportGenerationPanel
panel;
86 @SuppressWarnings(
"unchecked")
87 public static
void doReportWizard(String configName,
boolean displayCaseSpecificData,
boolean runReports) {
88 WizardDescriptor wiz =
new WizardDescriptor(
new ReportWizardIterator(configName, displayCaseSpecificData));
89 wiz.setTitleFormat(
new MessageFormat(
"{0} {1}"));
90 wiz.setTitle(NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.reportWiz.title"));
91 if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
95 saveReportingConfiguration(configName, wiz);
96 }
catch (ReportConfigException ex) {
97 logger.log(Level.SEVERE,
"Failed to save reporting configuration " + configName, ex);
98 NotifyDescriptor descriptor =
new NotifyDescriptor.Message(
99 NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.unableToSaveConfig.errorLabel.text"),
100 NotifyDescriptor.ERROR_MESSAGE);
101 DialogDisplayer.getDefault().notify(descriptor);
106 panel =
new ReportGenerationPanel();
107 Map<String, ReportModule> modules = (Map<String, ReportModule>) wiz.getProperty(
"modules");
113 generator.displayProgressPanel();
118 @SuppressWarnings(value =
"unchecked")
119 private static
void saveReportingConfiguration(String configName, WizardDescriptor wiz) throws ReportConfigException {
121 ReportingConfig reportingConfig =
new ReportingConfig(configName);
122 List<Long> selectedDataSourceIds = (List<Long>) wiz.getProperty(
"dataSourceSelections");
125 FileReportSettings fileSettings = (FileReportSettings) wiz.getProperty(
"fileReportSettings");
126 TableReportSettings tableSettings = (TableReportSettings) wiz.getProperty(
"tableReportSettings");
128 if(selectedDataSourceIds != null) {
130 if(fileSettings != null) {
131 fileSettings.setSelectedDataSources(selectedDataSourceIds);
133 if(tableSettings != null) {
134 tableSettings.setSelectedDataSources(selectedDataSourceIds);
138 reportingConfig.setFileReportSettings(fileSettings);
139 reportingConfig.setTableReportSettings(tableSettings);
140 reportingConfig.setGeneralReportSettings(generalSettings);
142 Map<String, ReportModuleConfig> moduleConfigs = (Map<String, ReportModuleConfig>) wiz.getProperty(
"moduleConfigs");
147 if (portableCaseReportSettings != null) {
148 config.setModuleSettings(portableCaseReportSettings);
153 reportingConfig.setModuleConfigs(moduleConfigs);
156 ReportingConfigLoader.saveConfig(reportingConfig);
163 Case newCase = (
Case) evt.getNewValue();
173 @SuppressWarnings(
"unchecked")
174 public
void actionPerformed(ActionEvent e) {
175 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
176 doReportWizard(REPORTING_CONFIGURATION_NAME, DISPLAY_CASE_SPECIFIC_DATA, RUN_REPORTS);
177 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
191 return HelpCtx.DEFAULT_HELP;
201 ImageIcon icon =
new ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/report/images/btn_icon_generate_report.png"));
202 toolbarButton.setIcon(icon);
203 toolbarButton.setText(NbBundle.getMessage(
this.getClass(),
"ReportWizardAction.toolBarButton.text"));
204 return toolbarButton;
214 super.setEnabled(value);
215 toolbarButton.setEnabled(value);
223 this.doInBackground = doInBackground;
228 doInBackground.run();
236 }
catch (InterruptedException | ExecutionException ex) {
237 panel.getProgressPanel().updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
238 logger.log(Level.SEVERE,
"failed to generate reports", ex);
240 catch (java.util.concurrent.CancellationException ex) {
Component getToolbarPresenter()
static boolean runningWithGUI
static ReportGenerationPanel panel
ReportWorker(Runnable doInBackground)
void setEnabled(boolean value)
synchronized static Logger getLogger(String name)
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
final Runnable doInBackground
void setSelectedDataSources(List< Long > selectedDataSources)