Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
MultiUserCasesPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.casemodule;
20 
21 import java.awt.Cursor;
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.logging.Level;
25 import javax.swing.JDialog;
26 import javax.swing.JPanel;
27 import javax.swing.SortOrder;
28 import javax.swing.SwingUtilities;
29 import javax.swing.event.ListSelectionEvent;
30 import javax.swing.table.DefaultTableModel;
31 import javax.swing.table.TableRowSorter;
32 import org.openide.util.Lookup;
35 
39 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
40 final class MultiUserCasesPanel extends JPanel{
41 
42  private static final Logger logger = Logger.getLogger(MultiUserCasesPanel.class.getName());
43  private static final long serialVersionUID = 1L;
44  private final JDialog parentDialog;
45  private final CaseBrowser caseBrowserPanel;
46 
51  MultiUserCasesPanel(JDialog parentDialog) {
52  this.parentDialog = parentDialog;
53  initComponents();
54 
55  caseBrowserPanel = new CaseBrowser();
56  caseExplorerScrollPane.add(caseBrowserPanel);
57  caseExplorerScrollPane.setViewportView(caseBrowserPanel);
58  /*
59  * Listen for row selection changes and set button state for the current
60  * selection.
61  */
62  caseBrowserPanel.addListSelectionListener((ListSelectionEvent e) -> {
63  setButtons();
64  });
65 
66  }
67 
72  void refresh() {
73  caseBrowserPanel.refresh();
74  }
75 
80  void setButtons() {
81  bnOpen.setEnabled(caseBrowserPanel.isRowSelected());
82  }
83 
89  private void openCase(String caseMetadataFilePath) {
90  if (caseMetadataFilePath != null) {
91  setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
92 
93  StartupWindowProvider.getInstance().close();
94  if (parentDialog != null) {
95  parentDialog.setVisible(false);
96  }
97  new Thread(() -> {
98  try {
99  Case.openAsCurrentCase(caseMetadataFilePath);
100  } catch (CaseActionException ex) {
101  if (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException)) {
102  logger.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", caseMetadataFilePath), ex); //NON-NLS
103  MessageNotifyUtil.Message.error(ex.getCause().getLocalizedMessage());
104  }
105  SwingUtilities.invokeLater(() -> {
106  //GUI changes done back on the EDT
107  StartupWindowProvider.getInstance().open();
108  });
109  } finally {
110  SwingUtilities.invokeLater(() -> {
111  //GUI changes done back on the EDT
112  setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
113  });
114  }
115  }).start();
116  }
117  }
118 
123  private static class RowSorter<M extends DefaultTableModel> extends TableRowSorter<M> {
124 
125  RowSorter(M tModel) {
126  super(tModel);
127  }
128 
129  @Override
130  public void toggleSortOrder(int column) {
131  if (!this.getModel().getColumnClass(column).equals(Date.class)) {
132  super.toggleSortOrder(column); //if it isn't a date column perform the regular sorting
133  } else {
134  ArrayList<RowSorter.SortKey> sortKeys = new ArrayList<>(getSortKeys());
135  if (sortKeys.isEmpty() || sortKeys.get(0).getColumn() != column) { //sort descending
136  sortKeys.add(0, new RowSorter.SortKey(column, SortOrder.DESCENDING));
137  } else if (sortKeys.get(0).getSortOrder() == SortOrder.ASCENDING) {
138  sortKeys.removeIf(key -> key.getColumn() == column);
139  sortKeys.add(0, new RowSorter.SortKey(column, SortOrder.DESCENDING));
140  } else {
141  sortKeys.removeIf(key -> key.getColumn() == column);
142  sortKeys.add(0, new RowSorter.SortKey(column, SortOrder.ASCENDING));
143  }
144  setSortKeys(sortKeys);
145  }
146  }
147  }
148 
154  @SuppressWarnings("unchecked")
155  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
156  private void initComponents() {
157 
158  bnOpen = new javax.swing.JButton();
159  bnOpenSingleUserCase = new javax.swing.JButton();
160  cancelButton = new javax.swing.JButton();
161  searchLabel = new javax.swing.JLabel();
162  caseExplorerScrollPane = new javax.swing.JScrollPane();
163 
164  setName("Completed Cases"); // NOI18N
165  setPreferredSize(new java.awt.Dimension(960, 485));
166 
167  org.openide.awt.Mnemonics.setLocalizedText(bnOpen, org.openide.util.NbBundle.getMessage(MultiUserCasesPanel.class, "MultiUserCasesPanel.bnOpen.text")); // NOI18N
168  bnOpen.setEnabled(false);
169  bnOpen.setMaximumSize(new java.awt.Dimension(80, 23));
170  bnOpen.setMinimumSize(new java.awt.Dimension(80, 23));
171  bnOpen.setPreferredSize(new java.awt.Dimension(80, 23));
172  bnOpen.addActionListener(new java.awt.event.ActionListener() {
173  public void actionPerformed(java.awt.event.ActionEvent evt) {
174  bnOpenActionPerformed(evt);
175  }
176  });
177 
178  org.openide.awt.Mnemonics.setLocalizedText(bnOpenSingleUserCase, org.openide.util.NbBundle.getMessage(MultiUserCasesPanel.class, "MultiUserCasesPanel.bnOpenSingleUserCase.text")); // NOI18N
179  bnOpenSingleUserCase.setMinimumSize(new java.awt.Dimension(156, 23));
180  bnOpenSingleUserCase.setPreferredSize(new java.awt.Dimension(156, 23));
181  bnOpenSingleUserCase.addActionListener(new java.awt.event.ActionListener() {
182  public void actionPerformed(java.awt.event.ActionEvent evt) {
183  bnOpenSingleUserCaseActionPerformed(evt);
184  }
185  });
186 
187  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(MultiUserCasesPanel.class, "MultiUserCasesPanel.cancelButton.text")); // NOI18N
188  cancelButton.setMaximumSize(new java.awt.Dimension(80, 23));
189  cancelButton.setMinimumSize(new java.awt.Dimension(80, 23));
190  cancelButton.setPreferredSize(new java.awt.Dimension(80, 23));
191  cancelButton.addActionListener(new java.awt.event.ActionListener() {
192  public void actionPerformed(java.awt.event.ActionEvent evt) {
193  cancelButtonActionPerformed(evt);
194  }
195  });
196 
197  org.openide.awt.Mnemonics.setLocalizedText(searchLabel, org.openide.util.NbBundle.getMessage(MultiUserCasesPanel.class, "MultiUserCasesPanel.searchLabel.text")); // NOI18N
198 
199  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
200  this.setLayout(layout);
201  layout.setHorizontalGroup(
202  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
203  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
204  .addContainerGap()
205  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
206  .addComponent(caseExplorerScrollPane)
207  .addGroup(layout.createSequentialGroup()
208  .addComponent(searchLabel)
209  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
210  .addComponent(bnOpenSingleUserCase, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
211  .addGap(190, 190, 190)
212  .addComponent(bnOpen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
213  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
214  .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
215  .addContainerGap())
216  );
217 
218  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {bnOpen, cancelButton});
219 
220  layout.setVerticalGroup(
221  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
222  .addGroup(layout.createSequentialGroup()
223  .addGap(6, 6, 6)
224  .addComponent(caseExplorerScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
225  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
226  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
227  .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
228  .addComponent(bnOpen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
229  .addComponent(bnOpenSingleUserCase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
230  .addComponent(searchLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
231  .addContainerGap())
232  );
233  }// </editor-fold>//GEN-END:initComponents
234 
240  private void bnOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOpenActionPerformed
241  openCase(caseBrowserPanel.getCasePath());
242  }//GEN-LAST:event_bnOpenActionPerformed
243 
244  private void bnOpenSingleUserCaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOpenSingleUserCaseActionPerformed
245  Lookup.getDefault().lookup(CaseOpenAction.class).openCaseSelectionWindow();
246  }//GEN-LAST:event_bnOpenSingleUserCaseActionPerformed
247 
248  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
249  if (parentDialog != null) {
250  parentDialog.setVisible(false);
251  }
252  }//GEN-LAST:event_cancelButtonActionPerformed
253 
254  // Variables declaration - do not modify//GEN-BEGIN:variables
255  private javax.swing.JButton bnOpen;
256  private javax.swing.JButton bnOpenSingleUserCase;
257  private javax.swing.JButton cancelButton;
258  private javax.swing.JScrollPane caseExplorerScrollPane;
259  private javax.swing.JLabel searchLabel;
260  // End of variables declaration//GEN-END:variables
261 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.