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

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