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;
37 import java.util.concurrent.ExecutionException;
38 import java.util.logging.Level;
39 import javax.swing.ImageIcon;
40 import javax.swing.JButton;
41 import javax.swing.SwingWorker;
42 import org.openide.DialogDisplayer;
43 import org.openide.NotifyDescriptor;
44 import org.openide.WizardDescriptor;
45 import org.openide.awt.ActionID;
46 import org.openide.awt.ActionReference;
47 import org.openide.awt.ActionReferences;
48 import org.openide.awt.ActionRegistration;
49 import org.openide.util.HelpCtx;
50 import org.openide.util.NbBundle;
51 import org.openide.util.actions.CallableSystemAction;
52 import org.openide.util.actions.Presenter;
53 import org.openide.windows.WindowManager;
60 @ActionID(category =
"Tools",
id =
"org.sleuthkit.autopsy.report.infrastructure.ReportWizardAction")
61 @ActionRegistration(displayName =
"#CTL_ReportWizardAction", lazy =
false)
62 @ActionReferences(value = {
63 @ActionReference(path =
"Menu/Tools", position = 301, separatorAfter = 399)
65 @ActionReference(path =
"Toolbars/Case", position = 106)})
66 public final class ReportWizardAction extends CallableSystemAction implements Presenter.Toolbar, ActionListener {
69 private static final String REPORTING_CONFIGURATION_NAME =
"ReportAction";
70 private static final boolean DISPLAY_CASE_SPECIFIC_DATA =
true;
71 private static final boolean RUN_REPORTS =
true;
72 private final JButton toolbarButton =
new JButton();
73 private static final String ACTION_NAME = NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.actionName.text");
74 private static ReportGenerationPanel
panel;
87 @SuppressWarnings(
"unchecked")
88 public static
void doReportWizard(String configName,
boolean displayCaseSpecificData,
boolean runReports) {
89 WizardDescriptor wiz =
new WizardDescriptor(
new ReportWizardIterator(configName, displayCaseSpecificData));
90 wiz.setTitleFormat(
new MessageFormat(
"{0} {1}"));
91 wiz.setTitle(NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.reportWiz.title"));
92 if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
96 saveReportingConfiguration(configName, wiz);
97 }
catch (ReportConfigException ex) {
98 logger.log(Level.SEVERE,
"Failed to save reporting configuration " + configName, ex);
99 NotifyDescriptor descriptor =
new NotifyDescriptor.Message(
100 NbBundle.getMessage(
ReportWizardAction.class,
"ReportWizardAction.unableToSaveConfig.errorLabel.text"),
101 NotifyDescriptor.ERROR_MESSAGE);
102 DialogDisplayer.getDefault().notify(descriptor);
107 panel =
new ReportGenerationPanel();
108 Map<String, ReportModule> modules = (Map<String, ReportModule>) wiz.getProperty(
"modules");
114 generator.displayProgressPanel();
119 @SuppressWarnings(value =
"unchecked")
120 private static
void saveReportingConfiguration(String configName, WizardDescriptor wiz) throws ReportConfigException {
122 ReportingConfig reportingConfig =
new ReportingConfig(configName);
123 List<Long> selectedDataSourceIds = (List<Long>) wiz.getProperty(
"dataSourceSelections");
126 FileReportSettings fileSettings = (FileReportSettings) wiz.getProperty(
"fileReportSettings");
127 TableReportSettings tableSettings = (TableReportSettings) wiz.getProperty(
"tableReportSettings");
129 if(selectedDataSourceIds != null) {
131 if(fileSettings != null) {
132 fileSettings.setSelectedDataSources(selectedDataSourceIds);
134 if(tableSettings != null) {
135 tableSettings.setSelectedDataSources(selectedDataSourceIds);
139 reportingConfig.setFileReportSettings(fileSettings);
140 reportingConfig.setTableReportSettings(tableSettings);
141 reportingConfig.setGeneralReportSettings(generalSettings);
143 Map<String, ReportModuleConfig> moduleConfigs = (Map<String, ReportModuleConfig>) wiz.getProperty(
"moduleConfigs");
148 if (portableCaseReportSettings != null) {
149 config.setModuleSettings(portableCaseReportSettings);
154 reportingConfig.setModuleConfigs(moduleConfigs);
157 ReportingConfigLoader.saveConfig(reportingConfig);
164 Case newCase = (
Case) evt.getNewValue();
174 @SuppressWarnings(
"unchecked")
175 public
void actionPerformed(ActionEvent e) {
176 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
177 doReportWizard(REPORTING_CONFIGURATION_NAME, DISPLAY_CASE_SPECIFIC_DATA, RUN_REPORTS);
178 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
192 return HelpCtx.DEFAULT_HELP;
202 ImageIcon icon =
new ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/report/images/btn_icon_generate_report.png"));
203 toolbarButton.setIcon(icon);
204 toolbarButton.setText(NbBundle.getMessage(
this.getClass(),
"ReportWizardAction.toolBarButton.text"));
205 return toolbarButton;
216 Set<String> nameList = ReportingConfigLoader.getListOfReportConfigs();
218 nameList.remove(REPORTING_CONFIGURATION_NAME);
230 super.setEnabled(value);
231 toolbarButton.setEnabled(value);
239 this.doInBackground = doInBackground;
244 doInBackground.run();
252 }
catch (InterruptedException | ExecutionException ex) {
253 panel.getProgressPanel().updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
254 logger.log(Level.SEVERE,
"failed to generate reports", ex);
256 catch (java.util.concurrent.CancellationException ex) {
Component getToolbarPresenter()
static boolean runningWithGUI
static ReportGenerationPanel panel
ReportWorker(Runnable doInBackground)
static Set< String > getReportConfigNames()
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)