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");
119 generator.displayProgressPanel();
124 @SuppressWarnings(value =
"unchecked")
125 private static
void saveReportingConfiguration(String configName, WizardDescriptor wiz) throws ReportConfigException {
127 ReportingConfig reportingConfig =
new ReportingConfig(configName);
128 List<Long> selectedDataSourceIds = (List<Long>) wiz.getProperty(
"dataSourceSelections");
131 FileReportSettings fileSettings = (FileReportSettings) wiz.getProperty(
"fileReportSettings");
132 TableReportSettings tableSettings = (TableReportSettings) wiz.getProperty(
"tableReportSettings");
134 if(selectedDataSourceIds != null) {
136 if(fileSettings != null) {
137 fileSettings.setSelectedDataSources(selectedDataSourceIds);
139 if(tableSettings != null) {
140 tableSettings.setSelectedDataSources(selectedDataSourceIds);
144 reportingConfig.setFileReportSettings(fileSettings);
145 reportingConfig.setTableReportSettings(tableSettings);
146 reportingConfig.setGeneralReportSettings(generalSettings);
148 Map<String, ReportModuleConfig> moduleConfigs = (Map<String, ReportModuleConfig>) wiz.getProperty(
"moduleConfigs");
153 if (portableCaseReportSettings != null) {
154 config.setModuleSettings(portableCaseReportSettings);
159 reportingConfig.setModuleConfigs(moduleConfigs);
162 ReportingConfigLoader.saveConfig(reportingConfig);
169 Case newCase = (
Case) evt.getNewValue();
179 @SuppressWarnings(
"unchecked")
180 public
void actionPerformed(ActionEvent e) {
181 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
182 doReportWizard(REPORTING_CONFIGURATION_NAME, DISPLAY_CASE_SPECIFIC_DATA, RUN_REPORTS);
183 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
197 return HelpCtx.DEFAULT_HELP;
207 ImageIcon icon =
new ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/report/images/btn_icon_generate_report.png"));
208 toolbarButton.setIcon(icon);
209 toolbarButton.setText(NbBundle.getMessage(
this.getClass(),
"ReportWizardAction.toolBarButton.text"));
210 return toolbarButton;
221 Set<String> nameList = ReportingConfigLoader.getListOfReportConfigs();
223 nameList.remove(REPORTING_CONFIGURATION_NAME);
235 super.setEnabled(value);
236 toolbarButton.setEnabled(value);
244 this.doInBackground = doInBackground;
249 doInBackground.run();
257 }
catch (InterruptedException | ExecutionException ex) {
258 panel.getProgressPanel().updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
259 logger.log(Level.SEVERE,
"failed to generate reports", ex);
261 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)