Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OtherOccurrencesPanel.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2017-2021 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.centralrepository.contentviewer;
20 
24 import java.awt.Cursor;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.ComponentAdapter;
28 import java.awt.event.ComponentEvent;
29 import java.io.File;
30 import java.util.ArrayList;
31 import java.util.Calendar;
32 import java.util.Collection;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.concurrent.ExecutionException;
38 import java.util.concurrent.ExecutorService;
39 import java.util.concurrent.Executors;
40 import java.util.concurrent.FutureTask;
41 import java.util.logging.Level;
42 import javax.swing.JFileChooser;
43 import javax.swing.JMenuItem;
44 import javax.swing.JOptionPane;
45 import static javax.swing.JOptionPane.DEFAULT_OPTION;
46 import static javax.swing.JOptionPane.ERROR_MESSAGE;
47 import static javax.swing.JOptionPane.PLAIN_MESSAGE;
48 import javax.swing.SwingWorker;
49 import javax.swing.filechooser.FileNameExtensionFilter;
50 import javax.swing.table.TableModel;
51 import javax.swing.table.TableRowSorter;
52 import org.openide.util.NbBundle;
62 import org.sleuthkit.datamodel.AbstractFile;
63 
67 @NbBundle.Messages({
68  "OtherOccurrencesPanel.table.noArtifacts=Item has no attributes with which to search.",
69  "OtherOccurrencesPanel.table.noResultsFound=No results found.",
70  "OtherOccurrencesPanel_table_loadingResults=Loading results"
71 })
72 public final class OtherOccurrencesPanel extends javax.swing.JPanel {
73 
74  private static final CorrelationCaseWrapper NO_ARTIFACTS_CASE = new CorrelationCaseWrapper(Bundle.OtherOccurrencesPanel_table_noArtifacts());
75  private static final CorrelationCaseWrapper NO_RESULTS_CASE = new CorrelationCaseWrapper(Bundle.OtherOccurrencesPanel_table_noResultsFound());
76  private static final Logger logger = Logger.getLogger(OtherOccurrencesPanel.class.getName());
77  private static final long serialVersionUID = 1L;
80  private final OtherOccurrencesDataSourcesTableModel dataSourcesTableModel;
81  private OccurrencePanel occurrencePanel;
82  private final Collection<CorrelationAttributeInstance> correlationAttributes;
83  private String dataSourceName = ""; //the data source of the file which the content viewer is being populated for
84  private String deviceId = ""; //the device id of the data source for the file which the content viewer is being populated for
85  private AbstractFile file = null;
86 
87  private SwingWorker<?, ?> worker;
88 
89  // Initializing the JFileChooser in a thread to prevent a block on the EDT
90  // see https://stackoverflow.com/questions/49792375/jfilechooser-is-very-slow-when-using-windows-look-and-feel
91  private final FutureTask<JFileChooser> futureFileChooser = new FutureTask<>(JFileChooser::new);
92  private JFileChooser CSVFileChooser;
93 
98  this.filesTableModel = new OtherOccurrencesFilesTableModel();
99  this.casesTableModel = new OtherOccurrencesCasesTableModel();
100  this.dataSourcesTableModel = new OtherOccurrencesDataSourcesTableModel();
101  this.correlationAttributes = new ArrayList<>();
102  initComponents();
103  customizeComponents();
104 
105  ExecutorService executor = Executors.newSingleThreadExecutor();
106  executor.execute(futureFileChooser);
107  }
108 
109  private void customizeComponents() {
110  ActionListener actList = (ActionEvent e) -> {
111  JMenuItem jmi = (JMenuItem) e.getSource();
112  if (jmi.equals(showCaseDetailsMenuItem)) {
113  showCaseDetails(filesTable.getSelectedRow());
114  } else if (jmi.equals(exportToCSVMenuItem)) {
115  try {
116  saveToCSV();
117  } catch (NoCurrentCaseException ex) {
118  logger.log(Level.SEVERE, "Exception while getting open case.", ex); // NON-NLS
119  }
120  } else if (jmi.equals(showCommonalityMenuItem)) {
121  showCommonalityDetails();
122  }
123  };
124 
125  exportToCSVMenuItem.addActionListener(actList);
126  showCaseDetailsMenuItem.addActionListener(actList);
127  showCommonalityMenuItem.addActionListener(actList);
128  filesTable.setComponentPopupMenu(rightClickPopupMenu);
129  // Configure column sorting.
130  TableRowSorter<TableModel> sorter = new TableRowSorter<>(filesTable.getModel());
131  filesTable.setRowSorter(sorter);
132 
133  //sort tables alphabetically initially
134  casesTable.getRowSorter().toggleSortOrder(0);
135  dataSourcesTable.getRowSorter().toggleSortOrder(0);
136  filesTable.getRowSorter().toggleSortOrder(0);
137  reset();
138  casesTable.getSelectionModel().addListSelectionListener((e) -> {
139  if (Case.isCaseOpen()) {
140  updateOnCaseSelection();
141  }
142  });
143  dataSourcesTable.getSelectionModel().addListSelectionListener((e) -> {
144  if (Case.isCaseOpen()) {
145  updateOnDataSourceSelection();
146  }
147  });
148 
149  //alows resizing of the 4th section
150  filesTable.getSelectionModel().addListSelectionListener((e) -> {
151  if (Case.isCaseOpen()) {
152  occurrencePanel = new OccurrencePanel();
153  updateOnFileSelection();
154  }
155  });
156  detailsPanelScrollPane.addComponentListener(new ComponentAdapter() {
157  @Override
158  public void componentResized(ComponentEvent componentEvent) {
159  //when its resized make sure the width of the panel resizes to match the scroll pane width to avoid a horizontal scroll bar
160  occurrencePanel.setPreferredSize(new java.awt.Dimension(detailsPanelScrollPane.getPreferredSize().width, occurrencePanel.getPreferredSize().height));
161  detailsPanelScrollPane.setViewportView(occurrencePanel);
162  }
163  });
164 
165  }
166 
167  @NbBundle.Messages({"OtherOccurrencesPanel.correlatedArtifacts.isEmpty=There are no files or artifacts to correlate.",
168  "# {0} - commonality percentage",
169  "# {1} - correlation type",
170  "# {2} - correlation value",
171  "OtherOccurrencesPanel.correlatedArtifacts.byType={0}% of data sources have {2} (type: {1})\n",
172  "OtherOccurrencesPanel.correlatedArtifacts.title=Attribute Frequency",
173  "OtherOccurrencesPanel.correlatedArtifacts.failed=Failed to get frequency details."})
178  private void showCommonalityDetails() {
179  if (correlationAttributes.isEmpty()) {
180  JOptionPane.showConfirmDialog(OtherOccurrencesPanel.this,
181  Bundle.OtherOccurrencesPanel_correlatedArtifacts_isEmpty(),
182  Bundle.OtherOccurrencesPanel_correlatedArtifacts_title(),
183  DEFAULT_OPTION, PLAIN_MESSAGE);
184  } else {
185  StringBuilder msg = new StringBuilder(correlationAttributes.size());
186  int percentage;
187  this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
188  try {
189  // Leaving these calls on the EDT but adding wait cursor
191  for (CorrelationAttributeInstance eamArtifact : correlationAttributes) {
192  try {
193  percentage = dbManager.getFrequencyPercentage(eamArtifact);
194  msg.append(Bundle.OtherOccurrencesPanel_correlatedArtifacts_byType(percentage,
195  eamArtifact.getCorrelationType().getDisplayName(),
196  eamArtifact.getCorrelationValue()));
198  logger.log(Level.WARNING, String.format("Error getting commonality details for artifact with ID: %s.", eamArtifact.getID()), ex);
199  }
200  }
201  this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
202  JOptionPane.showConfirmDialog(OtherOccurrencesPanel.this,
203  msg.toString(),
204  Bundle.OtherOccurrencesPanel_correlatedArtifacts_title(),
205  DEFAULT_OPTION, PLAIN_MESSAGE);
206  } catch (CentralRepoException ex) {
207  this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
208  logger.log(Level.SEVERE, "Error getting commonality details.", ex);
209  JOptionPane.showConfirmDialog(OtherOccurrencesPanel.this,
210  Bundle.OtherOccurrencesPanel_correlatedArtifacts_failed(),
211  Bundle.OtherOccurrencesPanel_correlatedArtifacts_title(),
212  DEFAULT_OPTION, ERROR_MESSAGE);
213  }
214  }
215  }
216 
217  @NbBundle.Messages({"OtherOccurrencesPanel.caseDetailsDialog.notSelected=No Row Selected",
218  "OtherOccurrencesPanel.caseDetailsDialog.noDetails=No details for this case.",
219  "OtherOccurrencesPanel.caseDetailsDialog.noDetailsReference=No case details for Global reference properties.",
220  "OtherOccurrencesPanel.caseDetailsDialog.noCaseNameError=Error",
221  "OtherOccurrencesPanel.noOpenCase.errMsg=No open case available."})
222  private void showCaseDetails(int selectedRowViewIdx) {
223  String caseDisplayName = Bundle.OtherOccurrencesPanel_caseDetailsDialog_noCaseNameError();
224  String details = Bundle.OtherOccurrencesPanel_caseDetailsDialog_noDetails();
225  try {
226  if (-1 != selectedRowViewIdx) {
228  int selectedRowModelIdx = filesTable.convertRowIndexToModel(selectedRowViewIdx);
229  List<NodeData> rowList = filesTableModel.getListOfNodesForFile(selectedRowModelIdx);
230  if (!rowList.isEmpty()) {
231  CorrelationCase eamCasePartial = rowList.get(0).getCorrelationAttributeInstance().getCorrelationCase();
232  caseDisplayName = eamCasePartial.getDisplayName();
233  // query case details
234  CorrelationCase eamCase = dbManager.getCaseByUUID(eamCasePartial.getCaseUUID());
235  if (eamCase != null) {
236  details = eamCase.getCaseDetailsOptionsPaneDialog();
237  } else {
238  details = Bundle.OtherOccurrencesPanel_caseDetailsDialog_noDetails();
239  }
240  } else {
241  details = Bundle.OtherOccurrencesPanel_caseDetailsDialog_noDetailsReference();
242  }
243  }
244  } catch (CentralRepoException ex) {
245  logger.log(Level.SEVERE, "Error loading case details", ex);
246  } finally {
247  JOptionPane.showConfirmDialog(OtherOccurrencesPanel.this,
248  details,
249  caseDisplayName,
250  DEFAULT_OPTION, PLAIN_MESSAGE);
251  }
252  }
253 
254  private void saveToCSV() throws NoCurrentCaseException {
255  if (casesTableModel.getRowCount() > 0) {
256 
257  if(CSVFileChooser == null) {
258  try{
259  CSVFileChooser = futureFileChooser.get();
260  } catch (InterruptedException | ExecutionException ex) {
261  // If something happened with the thread try and
262  // initalized the chooser now
263  logger.log(Level.WARNING, "A failure occurred in the JFileChooser background thread");
264  CSVFileChooser = new JFileChooser();
265  }
266  }
267 
268  Calendar now = Calendar.getInstance();
269  String fileName = String.format("%1$tY%1$tm%1$te%1$tI%1$tM%1$tS_other_data_sources.csv", now);
270  CSVFileChooser.setCurrentDirectory(new File(Case.getCurrentCaseThrows().getExportDirectory()));
271  CSVFileChooser.setSelectedFile(new File(fileName));
272  CSVFileChooser.setFileFilter(new FileNameExtensionFilter("csv file", "csv"));
273 
274  int returnVal = CSVFileChooser.showSaveDialog(filesTable);
275  if (returnVal == JFileChooser.APPROVE_OPTION) {
276 
277  File selectedFile = CSVFileChooser.getSelectedFile();
278  if (!selectedFile.getName().endsWith(".csv")) { // NON-NLS
279  selectedFile = new File(selectedFile.toString() + ".csv"); // NON-NLS
280  }
281  CSVWorker csvWorker = new CSVWorker(selectedFile, file, dataSourceName, deviceId, Collections.unmodifiableCollection(correlationAttributes));
282  csvWorker.execute();
283  }
284  }
285  }
286 
287  @NbBundle.Messages({"OtherOccurrencesPanel_earliestCaseNotAvailable=Not Available."})
291  public void reset() {
292  // start with empty table
293  casesTableModel.clearTable();
294  dataSourcesTableModel.clearTable();
295  filesTableModel.clearTable();
296  correlationAttributes.clear();
297  earliestCaseDate.setText(Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable());
298  foundInLabel.setText("");
299  //calling getPreferredSize has a side effect of ensuring it has a preferred size which reflects the contents which are visible
300  occurrencePanel = new OccurrencePanel();
301  occurrencePanel.getPreferredSize();
302  detailsPanelScrollPane.setViewportView(occurrencePanel);
303  }
304 
316  if (worker != null) {
317  worker.cancel(true);
318  worker = null;
319  }
320 
321  casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
322 
323  worker = new OtherOccurrenceOneTypeWorker(aType, value, file, deviceId, dataSourceName) {
324  @Override
325  public void done() {
326  try {
327  if (isCancelled()) {
328  return;
329  }
330 
331  casesTableModel.clearTable();
332 
333  OtherOccurrenceOneTypeWorker.OneTypeData data = get();
334  for (CorrelationCase corCase : data.getCaseNames().values()) {
335  casesTableModel.addCorrelationCase(new CorrelationCaseWrapper(corCase));
336  }
337  int caseCount = casesTableModel.getRowCount();
338  if (correlationAttributes.isEmpty()) {
339  casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
340  } else if (caseCount == 0) {
341  casesTableModel.addCorrelationCase(NO_RESULTS_CASE);
342  }
343  String earliestDate = data.getEarliestCaseDate();
344  earliestCaseDate.setText(earliestDate.isEmpty() ? Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable() : earliestDate);
345  foundInLabel.setText(String.format(Bundle.OtherOccurrencesPanel_foundIn_text(), data.getTotalCount(), caseCount, data.getDataSourceCount()));
346  if (caseCount > 0) {
347  casesTable.setRowSelectionInterval(0, 0);
348  }
349 
350  } catch (InterruptedException | ExecutionException ex) {
351  logger.log(Level.SEVERE, "Failed to update OtherOccurrence panel", ex);
352  }
353  }
354  };
355 
356  worker.execute();
357  }
358 
362  void showPanelLoadingMessage() {
363  casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
364  }
365 
372  @NbBundle.Messages({
373  "OtherOccurrencesPanel.foundIn.text=Found %d instances in %d cases and %d data sources."
374  })
375  void populateTable(OtherOccurrencesData data) {
376  this.file = data.getFile();
377  this.dataSourceName = data.getDataSourceName();
378  this.deviceId = data.getDeviceId();
379 
380  casesTableModel.clearTable();
381 
382  correlationAttributes.addAll(data.getCorrelationAttributes());
383 
384  for (CorrelationCase corCase : data.getCaseMap().values()) {
385  casesTableModel.addCorrelationCase(new CorrelationCaseWrapper(corCase));
386  }
387  int caseCount = casesTableModel.getRowCount();
388  if (correlationAttributes.isEmpty()) {
389  casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
390  } else if (caseCount == 0) {
391  casesTableModel.addCorrelationCase(NO_RESULTS_CASE);
392  }
393  String earliestDate = data.getEarliestCaseDate();
394  earliestCaseDate.setText(earliestDate.isEmpty() ? Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable() : earliestDate);
395  foundInLabel.setText(String.format(Bundle.OtherOccurrencesPanel_foundIn_text(), data.getInstanceDataCount(), caseCount, data.getDataSourceCount()));
396  if (caseCount > 0) {
397  casesTable.setRowSelectionInterval(0, 0);
398  }
399  }
400 
405  private void updateOnCaseSelection() {
406  if (worker != null) {
407  worker.cancel(true);
408  worker = null;
409  }
410 
411  final int[] selectedCaseIndexes = casesTable.getSelectedRows();
412  dataSourcesTableModel.clearTable();
413  filesTableModel.clearTable();
414 
415  if (selectedCaseIndexes.length == 0) {
416  //special case when no cases are selected
417  occurrencePanel = new OccurrencePanel();
418  occurrencePanel.getPreferredSize();
419  detailsPanelScrollPane.setViewportView(occurrencePanel);
420 
421  return;
422  }
423 
424  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
425 
426  worker = new SelectionWorker(correlationAttributes, file, deviceId, dataSourceName) {
427  @Override
428  public void done() {
429  if (isCancelled()) {
430  return;
431  }
432 
433  try {
434  Map<UniquePathKey, NodeData> correlatedNodeDataMap = get();
435 
436  String currentCaseName;
437  try {
438  currentCaseName = Case.getCurrentCaseThrows().getName();
439  } catch (NoCurrentCaseException ex) {
440  currentCaseName = null;
441  logger.log(Level.WARNING, "Unable to get current case for other occurrences content viewer", ex);
442  }
443 
444  for (NodeData nodeData : correlatedNodeDataMap.values()) {
445  for (int selectedRow : selectedCaseIndexes) {
446  try {
447  if (nodeData.isCentralRepoNode()) {
448  if (casesTableModel.getCorrelationCase(casesTable.convertRowIndexToModel(selectedRow)) != null
449  && casesTableModel.getCorrelationCase(casesTable.convertRowIndexToModel(selectedRow)).getCaseUUID().equals(nodeData.getCorrelationAttributeInstance().getCorrelationCase().getCaseUUID())) {
450  dataSourcesTableModel.addNodeData(nodeData);
451  }
452  } else if (currentCaseName != null && (casesTableModel.getCorrelationCase(casesTable.convertRowIndexToModel(selectedRow)).getCaseUUID().equals(currentCaseName))) {
453  dataSourcesTableModel.addNodeData(nodeData);
454  }
455  } catch (CentralRepoException ex) {
456  logger.log(Level.WARNING, "Unable to get correlation attribute instance from OtherOccurrenceNodeInstanceData for case " + nodeData.getCaseName(), ex);
457  }
458  }
459  }
460  if (dataSourcesTable.getRowCount() > 0) {
461  dataSourcesTable.setRowSelectionInterval(0, 0);
462  }
463 
464  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
465 
466  } catch (InterruptedException | ExecutionException ex) {
467  logger.log(Level.SEVERE, "Failed to update OtherOccurrencesPanel on data source selection", ex);
468  }
469  }
470  };
471 
472  worker.execute();
473  }
474 
480  if (worker != null) {
481  worker.cancel(true);
482  worker = null;
483  }
484 
485  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
486 
487  final int[] selectedDataSources = dataSourcesTable.getSelectedRows();
488  filesTableModel.clearTable();
489 
490  worker = new SelectionWorker(correlationAttributes, file, deviceId, dataSourceName) {
491  @Override
492  public void done() {
493  if (isCancelled()) {
494  return;
495  }
496 
497  try {
498  Map<UniquePathKey, NodeData> correlatedNodeDataMap = get();
499  for (NodeData nodeData : correlatedNodeDataMap.values()) {
500  for (int selectedDataSourceRow : selectedDataSources) {
501  try {
502  if (nodeData.isCentralRepoNode()) {
503  if (dataSourcesTableModel.getCaseUUIDForRow(dataSourcesTable.convertRowIndexToModel(selectedDataSourceRow)).equals(nodeData.getCorrelationAttributeInstance().getCorrelationCase().getCaseUUID())
504  && dataSourcesTableModel.getDeviceIdForRow(dataSourcesTable.convertRowIndexToModel(selectedDataSourceRow)).equals(nodeData.getDeviceID())) {
505  filesTableModel.addNodeData(nodeData);
506  }
507  } else {
508  if (dataSourcesTableModel.getDeviceIdForRow(dataSourcesTable.convertRowIndexToModel(selectedDataSourceRow)).equals(nodeData.getDeviceID())) {
509  filesTableModel.addNodeData(nodeData);
510  }
511  }
512  } catch (CentralRepoException ex) {
513  logger.log(Level.WARNING, "Unable to get correlation attribute instance from OtherOccurrenceNodeInstanceData for case " + nodeData.getCaseName(), ex);
514  }
515  }
516  }
517  if (filesTable.getRowCount() > 0) {
518  filesTable.setRowSelectionInterval(0, 0);
519  }
520  } catch (InterruptedException | ExecutionException ex) {
521  logger.log(Level.SEVERE, "Failed to update OtherOccurrencesPanel on case selection", ex);
522  } finally {
523  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
524  }
525  }
526  };
527 
528  worker.execute();
529  }
530 
535  private void updateOnFileSelection() {
536  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
537  try {
538  if (filesTable.getSelectedRowCount() == 1) {
539  //if there is one file selected update the deatils to show the data for that file
540  occurrencePanel = new OccurrencePanel(filesTableModel.getListOfNodesForFile(filesTable.convertRowIndexToModel(filesTable.getSelectedRow())));
541  } else if (dataSourcesTable.getSelectedRowCount() == 1) {
542  //if no files were selected and only one data source is selected update the information to reflect the data source
543  String caseName = dataSourcesTableModel.getCaseNameForRow(dataSourcesTable.convertRowIndexToModel(dataSourcesTable.getSelectedRow()));
544  String dsName = dataSourcesTableModel.getValueAt(dataSourcesTable.convertRowIndexToModel(dataSourcesTable.getSelectedRow()), 0).toString();
545  String caseCreatedDate = "";
546  for (int row : casesTable.getSelectedRows()) {
547  if (casesTableModel.getValueAt(casesTable.convertRowIndexToModel(row), 0).toString().equals(caseName)) {
548  caseCreatedDate = getCaseCreatedDate(row);
549  break;
550  }
551  }
552  occurrencePanel = new OccurrencePanel(caseName, caseCreatedDate, dsName);
553  } else if (casesTable.getSelectedRowCount() == 1) {
554  //if no files were selected and a number of data source other than 1 are selected
555  //update the information to reflect the case
556  String createdDate;
557  String caseName = "";
558  if (casesTable.getRowCount() > 0) {
559  caseName = casesTableModel.getValueAt(casesTable.convertRowIndexToModel(casesTable.getSelectedRow()), 0).toString();
560  }
561  if (caseName.isEmpty()) {
562  occurrencePanel = new OccurrencePanel();
563  } else {
564  createdDate = getCaseCreatedDate(casesTable.getSelectedRow());
565  occurrencePanel = new OccurrencePanel(caseName, createdDate);
566  }
567  } else {
568  //else display an empty details area
569  occurrencePanel = new OccurrencePanel();
570  }
571  //calling getPreferredSize has a side effect of ensuring it has a preferred size which reflects the contents which are visible
572  occurrencePanel.getPreferredSize();
573  detailsPanelScrollPane.setViewportView(occurrencePanel);
574  } finally {
575  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
576  }
577  }
578 
587  private String getCaseCreatedDate(int caseTableRowIdx) {
588  try {
590  CorrelationCase partialCase;
591  partialCase = casesTableModel.getCorrelationCase(casesTable.convertRowIndexToModel(caseTableRowIdx));
592  if (partialCase == null) {
593  return "";
594  }
595  return CentralRepository.getInstance().getCaseByUUID(partialCase.getCaseUUID()).getCreationDate();
596  } else {
598  }
599  } catch (CentralRepoException ex) {
600  logger.log(Level.WARNING, "Error getting case created date for row: " + caseTableRowIdx, ex);
601  }
602  return "";
603  }
604 
608  private class SelectionWorker extends SwingWorker<Map<UniquePathKey, NodeData>, Void> {
609 
610  private final Collection<CorrelationAttributeInstance> coAtInstances;
611  private final AbstractFile abstractFile;
612  private final String deviceIdStr;
613  private final String dataSourceNameStr;
614 
623  SelectionWorker(Collection<CorrelationAttributeInstance> coAtInstances, AbstractFile abstractFile, String deviceIdStr, String dataSourceNameStr) {
624  this.coAtInstances = coAtInstances;
625  this.abstractFile = abstractFile;
626  this.dataSourceNameStr = dataSourceNameStr;
627  this.deviceIdStr = deviceIdStr;
628  }
629 
630  @Override
631  protected Map<UniquePathKey, NodeData> doInBackground() throws Exception {
632  Map<UniquePathKey, NodeData> correlatedNodeDataMap = new HashMap<>();
633  for (CorrelationAttributeInstance corAttr : coAtInstances) {
634  correlatedNodeDataMap.putAll(OtherOccurrences.getCorrelatedInstances(abstractFile, deviceIdStr, dataSourceNameStr, corAttr));
635 
636  if(isCancelled()) {
637  return new HashMap<>();
638  }
639  }
640 
641  return correlatedNodeDataMap;
642  }
643  }
644 
648  private class CSVWorker extends SwingWorker<Void, Void> {
649 
650  private final Collection<CorrelationAttributeInstance> correlationAttList;
651  private final String dataSourceName;
652  private final String deviceId;
653  private final File destFile;
654  private final AbstractFile abstractFile;
655 
665  CSVWorker(File destFile, AbstractFile sourceFile, String dataSourceName, String deviceId, Collection<CorrelationAttributeInstance> correlationAttList) {
666  this.destFile = destFile;
667  this.abstractFile = sourceFile;
668  this.dataSourceName = dataSourceName;
669  this.deviceId = deviceId;
670  this.correlationAttList = correlationAttList;
671  }
672 
673  @Override
674  protected Void doInBackground() throws Exception {
675  OtherOccurrences.writeOtherOccurrencesToFileAsCSV(this.destFile, this.abstractFile, this.correlationAttList, this.dataSourceName, this.deviceId);
676  return null;
677  }
678 
679  @Override
680  public void done() {
681  try {
682  get();
683  } catch (InterruptedException | ExecutionException ex) {
684  JOptionPane.showMessageDialog(OtherOccurrencesPanel.this,
685  "Failed to create csv file for Other Occurrences at\n" + destFile.getAbsolutePath(),
686  "Error Creating CSV",
687  JOptionPane.ERROR_MESSAGE);
688 
689  logger.log(Level.SEVERE, "Error writing selected rows to from OtherOccurrencePanel to " + destFile.getAbsolutePath(), ex);
690  }
691  }
692  }
693 
699  @SuppressWarnings("unchecked")
700  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
701  private void initComponents() {
702  java.awt.GridBagConstraints gridBagConstraints;
703 
704  rightClickPopupMenu = new javax.swing.JPopupMenu();
705  exportToCSVMenuItem = new javax.swing.JMenuItem();
706  showCaseDetailsMenuItem = new javax.swing.JMenuItem();
707  showCommonalityMenuItem = new javax.swing.JMenuItem();
708  tableContainerPanel = new javax.swing.JPanel();
709  tablesViewerSplitPane = new javax.swing.JSplitPane();
710  caseDatasourceFileSplitPane = new javax.swing.JSplitPane();
711  caseDatasourceSplitPane = new javax.swing.JSplitPane();
712  caseScrollPane = new javax.swing.JScrollPane();
713  casesTable = new javax.swing.JTable();
714  dataSourceScrollPane = new javax.swing.JScrollPane();
715  dataSourcesTable = new javax.swing.JTable();
716  filesTableScrollPane = new javax.swing.JScrollPane();
717  filesTable = new javax.swing.JTable();
718  detailsPanelScrollPane = new javax.swing.JScrollPane();
719  jPanel1 = new javax.swing.JPanel();
720  foundInLabel = new javax.swing.JLabel();
721  earliestCaseDate = new javax.swing.JLabel();
722  earliestCaseLabel = new javax.swing.JLabel();
723  filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
724 
725  rightClickPopupMenu.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
726  public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
727  }
728  public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
729  }
730  public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
731  rightClickPopupMenuPopupMenuWillBecomeVisible(evt);
732  }
733  });
734 
735  org.openide.awt.Mnemonics.setLocalizedText(exportToCSVMenuItem, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.exportToCSVMenuItem.text")); // NOI18N
736  rightClickPopupMenu.add(exportToCSVMenuItem);
737 
738  org.openide.awt.Mnemonics.setLocalizedText(showCaseDetailsMenuItem, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.showCaseDetailsMenuItem.text")); // NOI18N
739  rightClickPopupMenu.add(showCaseDetailsMenuItem);
740 
741  org.openide.awt.Mnemonics.setLocalizedText(showCommonalityMenuItem, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.showCommonalityMenuItem.text")); // NOI18N
742  rightClickPopupMenu.add(showCommonalityMenuItem);
743 
744  tableContainerPanel.setPreferredSize(new java.awt.Dimension(600, 63));
745  tableContainerPanel.setRequestFocusEnabled(false);
746 
747  tablesViewerSplitPane.setDividerLocation(450);
748  tablesViewerSplitPane.setResizeWeight(0.75);
749 
750  caseDatasourceFileSplitPane.setDividerLocation(300);
751  caseDatasourceFileSplitPane.setResizeWeight(0.66);
752  caseDatasourceFileSplitPane.setToolTipText(org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.caseDatasourceFileSplitPane.toolTipText")); // NOI18N
753 
754  caseDatasourceSplitPane.setDividerLocation(150);
755  caseDatasourceSplitPane.setResizeWeight(0.5);
756 
757  caseScrollPane.setPreferredSize(new java.awt.Dimension(150, 30));
758 
759  casesTable.setAutoCreateRowSorter(true);
760  casesTable.setModel(casesTableModel);
761  caseScrollPane.setViewportView(casesTable);
762 
763  caseDatasourceSplitPane.setLeftComponent(caseScrollPane);
764 
765  dataSourceScrollPane.setPreferredSize(new java.awt.Dimension(150, 30));
766 
767  dataSourcesTable.setAutoCreateRowSorter(true);
768  dataSourcesTable.setModel(dataSourcesTableModel);
769  dataSourceScrollPane.setViewportView(dataSourcesTable);
770 
771  caseDatasourceSplitPane.setRightComponent(dataSourceScrollPane);
772 
773  caseDatasourceFileSplitPane.setLeftComponent(caseDatasourceSplitPane);
774 
775  filesTableScrollPane.setPreferredSize(new java.awt.Dimension(150, 30));
776 
777  filesTable.setAutoCreateRowSorter(true);
778  filesTable.setModel(filesTableModel);
779  filesTable.setToolTipText(org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.filesTable.toolTipText")); // NOI18N
780  filesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
781  filesTableScrollPane.setViewportView(filesTable);
782 
783  caseDatasourceFileSplitPane.setRightComponent(filesTableScrollPane);
784 
785  tablesViewerSplitPane.setLeftComponent(caseDatasourceFileSplitPane);
786 
787  detailsPanelScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
788  detailsPanelScrollPane.setPreferredSize(new java.awt.Dimension(300, 100));
789  tablesViewerSplitPane.setRightComponent(detailsPanelScrollPane);
790 
791  jPanel1.setPreferredSize(new java.awt.Dimension(576, 22));
792  jPanel1.setLayout(new java.awt.GridBagLayout());
793 
794  foundInLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
795  org.openide.awt.Mnemonics.setLocalizedText(foundInLabel, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.foundInLabel.text")); // NOI18N
796  foundInLabel.setPreferredSize(new java.awt.Dimension(400, 16));
797  gridBagConstraints = new java.awt.GridBagConstraints();
798  gridBagConstraints.gridx = 3;
799  gridBagConstraints.gridy = 0;
800  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
801  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
802  gridBagConstraints.insets = new java.awt.Insets(2, 2, 0, 0);
803  jPanel1.add(foundInLabel, gridBagConstraints);
804 
805  org.openide.awt.Mnemonics.setLocalizedText(earliestCaseDate, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.earliestCaseDate.text")); // NOI18N
806  earliestCaseDate.setMaximumSize(new java.awt.Dimension(200, 16));
807  gridBagConstraints = new java.awt.GridBagConstraints();
808  gridBagConstraints.gridx = 1;
809  gridBagConstraints.gridy = 0;
810  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
811  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
812  gridBagConstraints.insets = new java.awt.Insets(0, 7, 0, 0);
813  jPanel1.add(earliestCaseDate, gridBagConstraints);
814 
815  org.openide.awt.Mnemonics.setLocalizedText(earliestCaseLabel, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.earliestCaseLabel.text")); // NOI18N
816  earliestCaseLabel.setToolTipText(org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.earliestCaseLabel.toolTipText")); // NOI18N
817  earliestCaseLabel.setMaximumSize(new java.awt.Dimension(260, 16));
818  gridBagConstraints = new java.awt.GridBagConstraints();
819  gridBagConstraints.gridx = 0;
820  gridBagConstraints.gridy = 0;
821  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
822  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
823  jPanel1.add(earliestCaseLabel, gridBagConstraints);
824  gridBagConstraints = new java.awt.GridBagConstraints();
825  gridBagConstraints.gridx = 2;
826  gridBagConstraints.gridy = 0;
827  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
828  gridBagConstraints.weightx = 0.1;
829  jPanel1.add(filler1, gridBagConstraints);
830 
831  javax.swing.GroupLayout tableContainerPanelLayout = new javax.swing.GroupLayout(tableContainerPanel);
832  tableContainerPanel.setLayout(tableContainerPanelLayout);
833  tableContainerPanelLayout.setHorizontalGroup(
834  tableContainerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
835  .addGroup(tableContainerPanelLayout.createSequentialGroup()
836  .addGroup(tableContainerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
837  .addComponent(tablesViewerSplitPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
838  .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE))
839  .addContainerGap())
840  );
841  tableContainerPanelLayout.setVerticalGroup(
842  tableContainerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
843  .addGroup(tableContainerPanelLayout.createSequentialGroup()
844  .addGap(0, 0, 0)
845  .addComponent(tablesViewerSplitPane)
846  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
847  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
848  .addGap(12, 12, 12))
849  );
850 
851  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
852  this.setLayout(layout);
853  layout.setHorizontalGroup(
854  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
855  .addComponent(tableContainerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE)
856  );
857  layout.setVerticalGroup(
858  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
859  .addComponent(tableContainerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
860  );
861  }// </editor-fold>//GEN-END:initComponents
862 
863  private void rightClickPopupMenuPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_rightClickPopupMenuPopupMenuWillBecomeVisible
864  boolean enableCentralRepoActions = false;
865  if (CentralRepository.isEnabled() && filesTable.getSelectedRowCount() == 1) {
866  int rowIndex = filesTable.getSelectedRow();
867  List<NodeData> selectedFile = filesTableModel.getListOfNodesForFile(rowIndex);
868  if (!selectedFile.isEmpty() && selectedFile.get(0) instanceof NodeData) {
869  NodeData instanceData = selectedFile.get(0);
870  enableCentralRepoActions = instanceData.isCentralRepoNode();
871  }
872  }
873  showCaseDetailsMenuItem.setVisible(enableCentralRepoActions);
874  showCommonalityMenuItem.setVisible(enableCentralRepoActions);
875  }//GEN-LAST:event_rightClickPopupMenuPopupMenuWillBecomeVisible
876 
877 
878  // Variables declaration - do not modify//GEN-BEGIN:variables
879  private javax.swing.JSplitPane caseDatasourceFileSplitPane;
880  private javax.swing.JSplitPane caseDatasourceSplitPane;
881  private javax.swing.JScrollPane caseScrollPane;
882  private javax.swing.JTable casesTable;
883  private javax.swing.JScrollPane dataSourceScrollPane;
884  private javax.swing.JTable dataSourcesTable;
885  private javax.swing.JScrollPane detailsPanelScrollPane;
886  private javax.swing.JLabel earliestCaseDate;
887  private javax.swing.JLabel earliestCaseLabel;
888  private javax.swing.JMenuItem exportToCSVMenuItem;
889  private javax.swing.JTable filesTable;
890  private javax.swing.JScrollPane filesTableScrollPane;
891  private javax.swing.Box.Filler filler1;
892  private javax.swing.JLabel foundInLabel;
893  private javax.swing.JPanel jPanel1;
894  private javax.swing.JPopupMenu rightClickPopupMenu;
895  private javax.swing.JMenuItem showCaseDetailsMenuItem;
896  private javax.swing.JMenuItem showCommonalityMenuItem;
897  private javax.swing.JPanel tableContainerPanel;
898  private javax.swing.JSplitPane tablesViewerSplitPane;
899  // End of variables declaration//GEN-END:variables
900 }
static void writeOtherOccurrencesToFileAsCSV(File destFile, AbstractFile abstractFile, Collection< CorrelationAttributeInstance > correlationAttList, String dataSourceName, String deviceId)
static Map< UniquePathKey, NodeData > getCorrelatedInstances(AbstractFile file, String deviceId, String dataSourceName, CorrelationAttributeInstance corAttr)
void populateTableForOneType(CorrelationAttributeInstance.Type aType, String value)
int getFrequencyPercentage(CorrelationAttributeInstance corAttr)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.