Autopsy  4.19.1
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 && filesTableModel.getRowCount() > 0) {
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, 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  correlationAttributes.addAll(data.getCorrelationAttributesToAdd());
335  for (CorrelationCase corCase : data.getCaseNames().values()) {
336  casesTableModel.addCorrelationCase(new CorrelationCaseWrapper(corCase));
337  }
338  int caseCount = casesTableModel.getRowCount();
339  if (correlationAttributes.isEmpty()) {
340  casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
341  } else if (caseCount == 0) {
342  casesTableModel.addCorrelationCase(NO_RESULTS_CASE);
343  } else {
344  String earliestDate = data.getEarliestCaseDate();
345  earliestCaseDate.setText(earliestDate.isEmpty() ? Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable() : earliestDate);
346  foundInLabel.setText(String.format(Bundle.OtherOccurrencesPanel_foundIn_text(), data.getTotalCount(), caseCount, data.getDataSourceCount()));
347  if (caseCount > 0) {
348  casesTable.setRowSelectionInterval(0, 0);
349  }
350  }
351 
352  } catch (InterruptedException | ExecutionException ex) {
353  logger.log(Level.SEVERE, "Failed to update OtherOccurrence panel", ex);
354  }
355  }
356  };
357 
358  worker.execute();
359  }
360 
364  void showPanelLoadingMessage() {
365  casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
366  }
367 
374  @NbBundle.Messages({
375  "OtherOccurrencesPanel.foundIn.text=Found %d instances in %d cases and %d data sources."
376  })
377  void populateTable(OtherOccurrencesData data) {
378  this.file = data.getFile();
379  this.dataSourceName = data.getDataSourceName();
380  this.deviceId = data.getDeviceId();
381 
382  casesTableModel.clearTable();
383 
384  correlationAttributes.addAll(data.getCorrelationAttributes());
385 
386  for (CorrelationCase corCase : data.getCaseMap().values()) {
387  casesTableModel.addCorrelationCase(new CorrelationCaseWrapper(corCase));
388  }
389  int caseCount = casesTableModel.getRowCount();
390  if (correlationAttributes.isEmpty()) {
391  casesTableModel.addCorrelationCase(NO_ARTIFACTS_CASE);
392  } else if (caseCount == 0) {
393  casesTableModel.addCorrelationCase(NO_RESULTS_CASE);
394  } else {
395  String earliestDate = data.getEarliestCaseDate();
396  earliestCaseDate.setText(earliestDate.isEmpty() ? Bundle.OtherOccurrencesPanel_earliestCaseNotAvailable() : earliestDate);
397  foundInLabel.setText(String.format(Bundle.OtherOccurrencesPanel_foundIn_text(), data.getInstanceDataCount(), caseCount, data.getDataSourceCount()));
398  if (caseCount > 0) {
399  casesTable.setRowSelectionInterval(0, 0);
400  }
401  }
402  }
403 
408  private void updateOnCaseSelection() {
409  if (worker != null) {
410  worker.cancel(true);
411  worker = null;
412  }
413 
414  final int[] selectedCaseIndexes = casesTable.getSelectedRows();
415  dataSourcesTableModel.clearTable();
416  filesTableModel.clearTable();
417 
418  if (selectedCaseIndexes.length == 0) {
419  //special case when no cases are selected
420  occurrencePanel = new OccurrencePanel();
421  occurrencePanel.getPreferredSize();
422  detailsPanelScrollPane.setViewportView(occurrencePanel);
423 
424  return;
425  }
426 
427  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
428 
429  worker = new SelectionWorker(correlationAttributes, deviceId, dataSourceName) {
430  @Override
431  public void done() {
432  if (isCancelled()) {
433  return;
434  }
435 
436  try {
437  Map<UniquePathKey, NodeData> correlatedNodeDataMap = get();
438 
439  String currentCaseName;
440  try {
441  currentCaseName = Case.getCurrentCaseThrows().getName();
442  } catch (NoCurrentCaseException ex) {
443  currentCaseName = null;
444  logger.log(Level.WARNING, "Unable to get current case for other occurrences content viewer", ex);
445  }
446  if (casesTableModel.getRowCount() > 0) {
447  for (NodeData nodeData : correlatedNodeDataMap.values()) {
448  for (int selectedRow : selectedCaseIndexes) {
449  try {
450  if (casesTableModel.getCorrelationCase(casesTable.convertRowIndexToModel(selectedRow)) != null
451  && casesTableModel.getCorrelationCase(casesTable.convertRowIndexToModel(selectedRow)).getCaseUUID().equals(nodeData.getCorrelationAttributeInstance().getCorrelationCase().getCaseUUID())) {
452  dataSourcesTableModel.addNodeData(nodeData);
453  }
454  } catch (CentralRepoException ex) {
455  logger.log(Level.WARNING, "Unable to get correlation attribute instance from OtherOccurrenceNodeInstanceData for case " + nodeData.getCaseName(), ex);
456  }
457  }
458  }
459  }
460  if (dataSourcesTableModel.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, deviceId, dataSourceName) {
491  @Override
492  public void done() {
493  if (isCancelled()) {
494  return;
495  }
496 
497  try {
498  Map<UniquePathKey, NodeData> correlatedNodeDataMap = get();
499  if (dataSourcesTableModel.getRowCount() > 0) {
500  for (NodeData nodeData : correlatedNodeDataMap.values()) {
501  for (int selectedDataSourceRow : selectedDataSources) {
502  int rowModelIndex = dataSourcesTable.convertRowIndexToModel(selectedDataSourceRow);
503  try {
504  if (dataSourcesTableModel.getCaseUUIDForRow(rowModelIndex).equals(nodeData.getCorrelationAttributeInstance().getCorrelationCase().getCaseUUID())
505  && dataSourcesTableModel.getDeviceIdForRow(rowModelIndex).equals(nodeData.getDeviceID())) {
506  filesTableModel.addNodeData(nodeData);
507  }
508  } catch (CentralRepoException ex) {
509  logger.log(Level.WARNING, "Unable to get correlation attribute instance from OtherOccurrenceNodeInstanceData for case " + nodeData.getCaseName(), ex);
510  }
511  }
512  }
513  }
514 
515  if (filesTableModel.getRowCount() > 0) {
516  filesTable.setRowSelectionInterval(0, 0);
517  }
518  } catch (InterruptedException | ExecutionException ex) {
519  logger.log(Level.SEVERE, "Failed to update OtherOccurrencesPanel on case selection", ex);
520  } finally {
521  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
522  }
523  }
524  };
525 
526  worker.execute();
527  }
528 
533  private void updateOnFileSelection() {
534  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
535  try {
536  if (filesTableModel.getRowCount() > 0 && filesTable.getSelectedRowCount() == 1) {
537  //if there is one file selected update the deatils to show the data for that file
538  occurrencePanel = new OccurrencePanel(filesTableModel.getListOfNodesForFile(filesTable.convertRowIndexToModel(filesTable.getSelectedRow())));
539  } else if (dataSourcesTableModel.getRowCount() > 0 && dataSourcesTable.getSelectedRowCount() == 1) {
540  //if no files were selected and only one data source is selected update the information to reflect the data source
541  String caseName = dataSourcesTableModel.getCaseNameForRow(dataSourcesTable.convertRowIndexToModel(dataSourcesTable.getSelectedRow()));
542  String dsName = dataSourcesTableModel.getValueAt(dataSourcesTable.convertRowIndexToModel(dataSourcesTable.getSelectedRow()), 0).toString();
543  String caseCreatedDate = "";
544  if (casesTableModel.getRowCount() > 0) {
545  for (int row : casesTable.getSelectedRows()) {
546  if (casesTableModel.getValueAt(casesTable.convertRowIndexToModel(row), 0).toString().equals(caseName)) {
547  caseCreatedDate = getCaseCreatedDate(row);
548  break;
549  }
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 (casesTableModel.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 {
589  if (CentralRepository.isEnabled() && casesTableModel.getRowCount() > 0) {
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 String deviceIdStr;
612  private final String dataSourceNameStr;
613 
622  SelectionWorker(Collection<CorrelationAttributeInstance> coAtInstances, String deviceIdStr, String dataSourceNameStr) {
623  this.coAtInstances = coAtInstances;
624  this.dataSourceNameStr = dataSourceNameStr;
625  this.deviceIdStr = deviceIdStr;
626  }
627 
628  @Override
629  protected Map<UniquePathKey, NodeData> doInBackground() throws Exception {
630  Map<UniquePathKey, NodeData> correlatedNodeDataMap = new HashMap<>();
631  for (CorrelationAttributeInstance corAttr : coAtInstances) {
632  correlatedNodeDataMap.putAll(OtherOccurrences.getCorrelatedInstances(deviceIdStr, dataSourceNameStr, corAttr));
633 
634  if (isCancelled()) {
635  return new HashMap<>();
636  }
637  }
638 
639  return correlatedNodeDataMap;
640  }
641  }
642 
646  private class CSVWorker extends SwingWorker<Void, Void> {
647 
648  private final Collection<CorrelationAttributeInstance> correlationAttList;
649  private final String dataSourceName;
650  private final String deviceId;
651  private final File destFile;
652 
662  CSVWorker(File destFile, String dataSourceName, String deviceId, Collection<CorrelationAttributeInstance> correlationAttList) {
663  this.destFile = destFile;
664  this.dataSourceName = dataSourceName;
665  this.deviceId = deviceId;
666  this.correlationAttList = correlationAttList;
667  }
668 
669  @Override
670  protected Void doInBackground() throws Exception {
671  OtherOccurrences.writeOtherOccurrencesToFileAsCSV(this.destFile, this.correlationAttList, this.dataSourceName, this.deviceId);
672  return null;
673  }
674 
675  @Override
676  public void done() {
677  try {
678  get();
679  } catch (InterruptedException | ExecutionException ex) {
680  JOptionPane.showMessageDialog(OtherOccurrencesPanel.this,
681  "Failed to create csv file for Other Occurrences at\n" + destFile.getAbsolutePath(),
682  "Error Creating CSV",
683  JOptionPane.ERROR_MESSAGE);
684 
685  logger.log(Level.SEVERE, "Error writing selected rows to from OtherOccurrencePanel to " + destFile.getAbsolutePath(), ex);
686  }
687  }
688  }
689 
695  @SuppressWarnings("unchecked")
696  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
697  private void initComponents() {
698  java.awt.GridBagConstraints gridBagConstraints;
699 
700  rightClickPopupMenu = new javax.swing.JPopupMenu();
701  exportToCSVMenuItem = new javax.swing.JMenuItem();
702  showCaseDetailsMenuItem = new javax.swing.JMenuItem();
703  showCommonalityMenuItem = new javax.swing.JMenuItem();
704  tableContainerPanel = new javax.swing.JPanel();
705  tablesViewerSplitPane = new javax.swing.JSplitPane();
706  caseDatasourceFileSplitPane = new javax.swing.JSplitPane();
707  caseDatasourceSplitPane = new javax.swing.JSplitPane();
708  caseScrollPane = new javax.swing.JScrollPane();
709  casesTable = new javax.swing.JTable();
710  dataSourceScrollPane = new javax.swing.JScrollPane();
711  dataSourcesTable = new javax.swing.JTable();
712  filesTableScrollPane = new javax.swing.JScrollPane();
713  filesTable = new javax.swing.JTable();
714  detailsPanelScrollPane = new javax.swing.JScrollPane();
715  jPanel1 = new javax.swing.JPanel();
716  foundInLabel = new javax.swing.JLabel();
717  earliestCaseDate = new javax.swing.JLabel();
718  earliestCaseLabel = new javax.swing.JLabel();
719  filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
720 
721  rightClickPopupMenu.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
722  public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
723  }
724  public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
725  }
726  public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
727  rightClickPopupMenuPopupMenuWillBecomeVisible(evt);
728  }
729  });
730 
731  org.openide.awt.Mnemonics.setLocalizedText(exportToCSVMenuItem, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.exportToCSVMenuItem.text")); // NOI18N
732  rightClickPopupMenu.add(exportToCSVMenuItem);
733 
734  org.openide.awt.Mnemonics.setLocalizedText(showCaseDetailsMenuItem, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.showCaseDetailsMenuItem.text")); // NOI18N
735  rightClickPopupMenu.add(showCaseDetailsMenuItem);
736 
737  org.openide.awt.Mnemonics.setLocalizedText(showCommonalityMenuItem, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.showCommonalityMenuItem.text")); // NOI18N
738  rightClickPopupMenu.add(showCommonalityMenuItem);
739 
740  tableContainerPanel.setPreferredSize(new java.awt.Dimension(600, 63));
741  tableContainerPanel.setRequestFocusEnabled(false);
742 
743  tablesViewerSplitPane.setDividerLocation(450);
744  tablesViewerSplitPane.setResizeWeight(0.75);
745 
746  caseDatasourceFileSplitPane.setDividerLocation(300);
747  caseDatasourceFileSplitPane.setResizeWeight(0.66);
748  caseDatasourceFileSplitPane.setToolTipText(org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.caseDatasourceFileSplitPane.toolTipText")); // NOI18N
749 
750  caseDatasourceSplitPane.setDividerLocation(150);
751  caseDatasourceSplitPane.setResizeWeight(0.5);
752 
753  caseScrollPane.setPreferredSize(new java.awt.Dimension(150, 30));
754 
755  casesTable.setAutoCreateRowSorter(true);
756  casesTable.setModel(casesTableModel);
757  caseScrollPane.setViewportView(casesTable);
758 
759  caseDatasourceSplitPane.setLeftComponent(caseScrollPane);
760 
761  dataSourceScrollPane.setPreferredSize(new java.awt.Dimension(150, 30));
762 
763  dataSourcesTable.setAutoCreateRowSorter(true);
764  dataSourcesTable.setModel(dataSourcesTableModel);
765  dataSourceScrollPane.setViewportView(dataSourcesTable);
766 
767  caseDatasourceSplitPane.setRightComponent(dataSourceScrollPane);
768 
769  caseDatasourceFileSplitPane.setLeftComponent(caseDatasourceSplitPane);
770 
771  filesTableScrollPane.setPreferredSize(new java.awt.Dimension(150, 30));
772 
773  filesTable.setAutoCreateRowSorter(true);
774  filesTable.setModel(filesTableModel);
775  filesTable.setToolTipText(org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.filesTable.toolTipText")); // NOI18N
776  filesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
777  filesTableScrollPane.setViewportView(filesTable);
778 
779  caseDatasourceFileSplitPane.setRightComponent(filesTableScrollPane);
780 
781  tablesViewerSplitPane.setLeftComponent(caseDatasourceFileSplitPane);
782 
783  detailsPanelScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
784  detailsPanelScrollPane.setPreferredSize(new java.awt.Dimension(300, 100));
785  tablesViewerSplitPane.setRightComponent(detailsPanelScrollPane);
786 
787  jPanel1.setPreferredSize(new java.awt.Dimension(576, 22));
788  jPanel1.setLayout(new java.awt.GridBagLayout());
789 
790  foundInLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
791  org.openide.awt.Mnemonics.setLocalizedText(foundInLabel, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.foundInLabel.text")); // NOI18N
792  foundInLabel.setPreferredSize(new java.awt.Dimension(400, 16));
793  gridBagConstraints = new java.awt.GridBagConstraints();
794  gridBagConstraints.gridx = 3;
795  gridBagConstraints.gridy = 0;
796  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
797  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
798  gridBagConstraints.insets = new java.awt.Insets(2, 2, 0, 0);
799  jPanel1.add(foundInLabel, gridBagConstraints);
800 
801  org.openide.awt.Mnemonics.setLocalizedText(earliestCaseDate, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.earliestCaseDate.text")); // NOI18N
802  earliestCaseDate.setMaximumSize(new java.awt.Dimension(200, 16));
803  gridBagConstraints = new java.awt.GridBagConstraints();
804  gridBagConstraints.gridx = 1;
805  gridBagConstraints.gridy = 0;
806  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
807  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
808  gridBagConstraints.insets = new java.awt.Insets(0, 7, 0, 0);
809  jPanel1.add(earliestCaseDate, gridBagConstraints);
810 
811  org.openide.awt.Mnemonics.setLocalizedText(earliestCaseLabel, org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.earliestCaseLabel.text")); // NOI18N
812  earliestCaseLabel.setToolTipText(org.openide.util.NbBundle.getMessage(OtherOccurrencesPanel.class, "OtherOccurrencesPanel.earliestCaseLabel.toolTipText")); // NOI18N
813  earliestCaseLabel.setMaximumSize(new java.awt.Dimension(260, 16));
814  gridBagConstraints = new java.awt.GridBagConstraints();
815  gridBagConstraints.gridx = 0;
816  gridBagConstraints.gridy = 0;
817  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
818  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
819  jPanel1.add(earliestCaseLabel, gridBagConstraints);
820  gridBagConstraints = new java.awt.GridBagConstraints();
821  gridBagConstraints.gridx = 2;
822  gridBagConstraints.gridy = 0;
823  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
824  gridBagConstraints.weightx = 0.1;
825  jPanel1.add(filler1, gridBagConstraints);
826 
827  javax.swing.GroupLayout tableContainerPanelLayout = new javax.swing.GroupLayout(tableContainerPanel);
828  tableContainerPanel.setLayout(tableContainerPanelLayout);
829  tableContainerPanelLayout.setHorizontalGroup(
830  tableContainerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
831  .addGroup(tableContainerPanelLayout.createSequentialGroup()
832  .addGroup(tableContainerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
833  .addComponent(tablesViewerSplitPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
834  .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE))
835  .addContainerGap())
836  );
837  tableContainerPanelLayout.setVerticalGroup(
838  tableContainerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
839  .addGroup(tableContainerPanelLayout.createSequentialGroup()
840  .addGap(0, 0, 0)
841  .addComponent(tablesViewerSplitPane)
842  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
843  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
844  .addGap(12, 12, 12))
845  );
846 
847  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
848  this.setLayout(layout);
849  layout.setHorizontalGroup(
850  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
851  .addComponent(tableContainerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE)
852  );
853  layout.setVerticalGroup(
854  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
855  .addComponent(tableContainerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
856  );
857  }// </editor-fold>//GEN-END:initComponents
858 
859  private void rightClickPopupMenuPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_rightClickPopupMenuPopupMenuWillBecomeVisible
860  boolean enableCentralRepoActions = false;
861  if (CentralRepository.isEnabled() && filesTable.getSelectedRowCount() == 1) {
862  int rowIndex = filesTable.getSelectedRow();
863  List<NodeData> selectedFile = filesTableModel.getListOfNodesForFile(rowIndex);
864  if (!selectedFile.isEmpty() && selectedFile.get(0) instanceof NodeData) {
865  enableCentralRepoActions = true;
866  }
867  }
868  showCaseDetailsMenuItem.setVisible(enableCentralRepoActions);
869  showCommonalityMenuItem.setVisible(enableCentralRepoActions);
870  }//GEN-LAST:event_rightClickPopupMenuPopupMenuWillBecomeVisible
871 
872 
873  // Variables declaration - do not modify//GEN-BEGIN:variables
874  private javax.swing.JSplitPane caseDatasourceFileSplitPane;
875  private javax.swing.JSplitPane caseDatasourceSplitPane;
876  private javax.swing.JScrollPane caseScrollPane;
877  private javax.swing.JTable casesTable;
878  private javax.swing.JScrollPane dataSourceScrollPane;
879  private javax.swing.JTable dataSourcesTable;
880  private javax.swing.JScrollPane detailsPanelScrollPane;
881  private javax.swing.JLabel earliestCaseDate;
882  private javax.swing.JLabel earliestCaseLabel;
883  private javax.swing.JMenuItem exportToCSVMenuItem;
884  private javax.swing.JTable filesTable;
885  private javax.swing.JScrollPane filesTableScrollPane;
886  private javax.swing.Box.Filler filler1;
887  private javax.swing.JLabel foundInLabel;
888  private javax.swing.JPanel jPanel1;
889  private javax.swing.JPopupMenu rightClickPopupMenu;
890  private javax.swing.JMenuItem showCaseDetailsMenuItem;
891  private javax.swing.JMenuItem showCommonalityMenuItem;
892  private javax.swing.JPanel tableContainerPanel;
893  private javax.swing.JSplitPane tablesViewerSplitPane;
894  // End of variables declaration//GEN-END:variables
895 }
static void writeOtherOccurrencesToFileAsCSV(File destFile, Collection< CorrelationAttributeInstance > correlationAttList, String dataSourceName, String deviceId)
static Map< UniquePathKey, NodeData > getCorrelatedInstances(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 Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.