Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PersonasTopComponent.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.persona;
20 
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.JOptionPane;
28 import javax.swing.JTable;
29 import javax.swing.ListSelectionModel;
30 import javax.swing.event.ListSelectionEvent;
31 import javax.swing.event.ListSelectionListener;
32 import javax.swing.table.DefaultTableModel;
33 import org.openide.DialogDisplayer;
34 import org.openide.NotifyDescriptor;
35 import org.openide.util.NbBundle.Messages;
36 import org.openide.windows.RetainLocation;
37 import org.openide.windows.TopComponent;
38 import org.openide.windows.WindowManager;
42 
47 @TopComponent.Description(preferredID = "PersonasTopComponent", persistenceType = TopComponent.PERSISTENCE_NEVER)
48 @TopComponent.Registration(mode = "personas", openAtStartup = false)
49 @RetainLocation("personas")
50 @SuppressWarnings("PMD.SingularField")
51 public final class PersonasTopComponent extends TopComponent {
52 
53  private static final long serialVersionUID = 1L;
54 
55  private static final Logger logger = Logger.getLogger(PersonasTopComponent.class.getName());
56 
57  private List<Persona> currentResults = null;
58  private Persona selectedPersona = null;
59 
60  @Messages({
61  "PersonasTopComponent_Name=Personas",
62  "PersonasTopComponent_delete_exception_Title=Delete failure",
63  "PersonasTopComponent_delete_exception_msg=Failed to delete persona.",
64  "PersonasTopComponent_delete_confirmation_Title=Are you sure?",
65  "PersonasTopComponent_delete_confirmation_msg=Are you sure you want to delete this persona?",
66  })
68  initComponents();
69  setName(Bundle.PersonasTopComponent_Name());
70  executeSearch();
71 
72  searchBtn.addActionListener(new ActionListener() {
73  @Override
74  public void actionPerformed(ActionEvent e) {
75  executeSearch();
76  }
77  });
78 
79  editBtn.addActionListener(new ActionListener() {
80  @Override
81  public void actionPerformed(ActionEvent e) {
83  PersonaDetailsMode.EDIT, selectedPersona, new CreateEditCallbackImpl());
84  }
85  });
86 
87  createBtn.addActionListener(new ActionListener() {
88  @Override
89  public void actionPerformed(ActionEvent e) {
91  PersonaDetailsMode.CREATE, selectedPersona, new CreateEditCallbackImpl());
92  }
93  });
94 
95  deleteBtn.addActionListener(new ActionListener() {
96  @Override
97  public void actionPerformed(ActionEvent e) {
98  NotifyDescriptor confirm = new NotifyDescriptor.Confirmation(
99  Bundle.PersonasTopComponent_delete_confirmation_msg(),
100  Bundle.PersonasTopComponent_delete_confirmation_Title(),
101  NotifyDescriptor.YES_NO_OPTION);
102  DialogDisplayer.getDefault().notify(confirm);
103  if (confirm.getValue().equals(NotifyDescriptor.YES_OPTION)) {
104  try {
105  if (selectedPersona != null) {
106  selectedPersona.delete();
107  }
108  } catch (CentralRepoException ex) {
109  logger.log(Level.SEVERE, "Failed to delete persona: " + selectedPersona.getName(), ex);
110  JOptionPane.showMessageDialog(PersonasTopComponent.this,
111  Bundle.PersonasTopComponent_delete_exception_msg(),
112  Bundle.PersonasTopComponent_delete_exception_Title(),
113  JOptionPane.ERROR_MESSAGE);
114  return;
115  }
116  executeSearch();
117  }
118  }
119  });
120 
121  // Results table
122  resultsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
123  resultsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
124  @Override
125  public void valueChanged(ListSelectionEvent e) {
126  handleSelectionChange(e);
127  }
128  });
129 
130  searchNameRadio.addActionListener((ActionEvent e) -> {
131  searchField.setText("");
132  });
133 
134  searchAccountRadio.addActionListener((ActionEvent e) -> {
135  searchField.setText("");
136  });
137 
138  createAccountBtn.addActionListener(new ActionListener() {
139  @Override
140  public void actionPerformed(ActionEvent e) {
141  new CreatePersonaAccountDialog(detailsPanel);
142  }
143  });
144  }
145 
149  class CreateEditCallbackImpl implements PersonaDetailsDialogCallback {
150 
151  @Override
152  public void callback(Persona persona) {
153  if (persona != null) {
154  searchField.setText("");
155  executeSearch();
156  int personaRow = currentResults.indexOf(persona);
157  resultsTable.getSelectionModel().setSelectionInterval(personaRow, personaRow);
158  handleSelectionChange();
159  }
160  createBtn.setEnabled(true);
161  }
162  }
163 
164  void setPersona(int index) {
165  Persona persona = currentResults.get(index);
166  selectedPersona = persona;
167  editBtn.setEnabled(true);
168  deleteBtn.setEnabled(true);
169  }
170 
174  final class PersonaFilterTableModel extends DefaultTableModel {
175 
176  private static final long serialVersionUID = 1L;
177 
178  PersonaFilterTableModel(Object[][] rows, String[] colNames) {
179  super(rows, colNames);
180  }
181 
182  @Override
183  public boolean isCellEditable(int row, int column) {
184  return false;
185  }
186  }
187 
188  private void handleSelectionChange(ListSelectionEvent e) {
189  if (e.getValueIsAdjusting()) {
190  return;
191  }
192  handleSelectionChange();
193  }
194 
195  private void handleSelectionChange() {
196  int selectedRow = resultsTable.getSelectedRow();
197  if (selectedRow != -1) {
198  setPersona(resultsTable.getSelectedRow());
199  detailsPanel.setMode(this, PersonaDetailsMode.VIEW, selectedPersona);
200  } else {
201  detailsPanel.clear();
202  }
203  }
204 
205  private void updateResultsTable(Collection<Persona> results) {
206  Object[][] rows = new Object[results.size()][2];
207  int i = 0;
208  for (Persona result : results) {
209  rows[i] = new Object[]{result.getId(), result.getName()};
210  i++;
211  }
212  PersonaFilterTableModel updatedTableModel = new PersonaFilterTableModel(
213  rows,
214  new String[]{"ID", "Name"}
215  );
216 
217  resultsTable.setModel(updatedTableModel);
218  currentResults = new ArrayList<>(results);
219 
220  // Formatting
221  resultsTable.getColumnModel().getColumn(0).setMaxWidth(100);
222  resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
223  }
224 
225  @Messages({
226  "PersonasTopComponent_search_exception_Title=Search failure",
227  "PersonasTopComponent_search_exception_msg=Failed to search personas.",})
228  private void executeSearch() {
229  Collection<Persona> results;
230  try {
231  if (searchNameRadio.isSelected()) {
232  results = Persona.getPersonaByName(searchField.getText());
233  } else {
234  results = Persona.getPersonaByAccountIdentifierLike(searchField.getText());
235  }
236  } catch (CentralRepoException ex) {
237  logger.log(Level.SEVERE, "Failed to search personas", ex);
238  JOptionPane.showMessageDialog(this,
239  Bundle.PersonasTopComponent_search_exception_Title(),
240  Bundle.PersonasTopComponent_search_exception_msg(),
241  JOptionPane.ERROR_MESSAGE);
242  return;
243  }
244 
245  resultsTable.clearSelection();
246  updateResultsTable(results);
247  editBtn.setEnabled(false);
248  deleteBtn.setEnabled(false);
249  }
250 
251  @Override
252  public void componentOpened() {
253  super.componentOpened();
254  WindowManager.getDefault().setTopComponentFloating(this, true);
255  }
256 
262  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
263  private void initComponents() {
264 
265  searchButtonGroup = new javax.swing.ButtonGroup();
266  mainSplitPane = new javax.swing.JSplitPane();
267  searchPanel = new javax.swing.JPanel();
268  searchField = new javax.swing.JTextField();
269  searchNameRadio = new javax.swing.JRadioButton();
270  searchAccountRadio = new javax.swing.JRadioButton();
271  searchBtn = new javax.swing.JButton();
272  resultsPane = new javax.swing.JScrollPane();
273  resultsTable = new javax.swing.JTable();
274  createAccountBtn = new javax.swing.JButton();
275  editBtn = new javax.swing.JButton();
276  deleteBtn = new javax.swing.JButton();
277  createButtonSeparator = new javax.swing.JSeparator();
278  createBtn = new javax.swing.JButton();
279  detailsScrollPane = new javax.swing.JScrollPane();
281 
282  setName(""); // NOI18N
283 
284  mainSplitPane.setDividerLocation(400);
285 
286  searchField.setText(org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.searchField.text")); // NOI18N
287 
288  searchButtonGroup.add(searchNameRadio);
289  searchNameRadio.setSelected(true);
290  org.openide.awt.Mnemonics.setLocalizedText(searchNameRadio, org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.searchNameRadio.text")); // NOI18N
291 
292  searchButtonGroup.add(searchAccountRadio);
293  org.openide.awt.Mnemonics.setLocalizedText(searchAccountRadio, org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.searchAccountRadio.text")); // NOI18N
294 
295  org.openide.awt.Mnemonics.setLocalizedText(searchBtn, org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.searchBtn.text")); // NOI18N
296 
297  resultsTable.setToolTipText(org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.resultsTable.toolTipText")); // NOI18N
298  resultsTable.getTableHeader().setReorderingAllowed(false);
299  resultsPane.setViewportView(resultsTable);
300  if (resultsTable.getColumnModel().getColumnCount() > 0) {
301  resultsTable.getColumnModel().getColumn(0).setMaxWidth(25);
302  resultsTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.resultsTable.columnModel.title0")); // NOI18N
303  resultsTable.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.resultsTable.columnModel.title1")); // NOI18N
304  }
305 
306  org.openide.awt.Mnemonics.setLocalizedText(createAccountBtn, org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.createAccountBtn.text")); // NOI18N
307 
308  org.openide.awt.Mnemonics.setLocalizedText(editBtn, org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.editBtn.text")); // NOI18N
309  editBtn.setEnabled(false);
310 
311  org.openide.awt.Mnemonics.setLocalizedText(deleteBtn, org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.deleteBtn.text")); // NOI18N
312  deleteBtn.setEnabled(false);
313 
314  org.openide.awt.Mnemonics.setLocalizedText(createBtn, org.openide.util.NbBundle.getMessage(PersonasTopComponent.class, "PersonasTopComponent.createBtn.text")); // NOI18N
315 
316  javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
317  searchPanel.setLayout(searchPanelLayout);
318  searchPanelLayout.setHorizontalGroup(
319  searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
320  .addGroup(searchPanelLayout.createSequentialGroup()
321  .addContainerGap()
322  .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
323  .addComponent(createButtonSeparator)
324  .addComponent(resultsPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
325  .addComponent(searchField)
326  .addGroup(searchPanelLayout.createSequentialGroup()
327  .addComponent(searchNameRadio)
328  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
329  .addComponent(searchAccountRadio)
330  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
331  .addComponent(searchBtn))
332  .addGroup(searchPanelLayout.createSequentialGroup()
333  .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
334  .addComponent(createAccountBtn)
335  .addGroup(searchPanelLayout.createSequentialGroup()
336  .addComponent(createBtn)
337  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
338  .addComponent(editBtn)
339  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
340  .addComponent(deleteBtn)))
341  .addGap(0, 0, Short.MAX_VALUE)))
342  .addContainerGap())
343  );
344  searchPanelLayout.setVerticalGroup(
345  searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346  .addGroup(searchPanelLayout.createSequentialGroup()
347  .addContainerGap()
348  .addComponent(searchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
349  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
350  .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
351  .addComponent(searchNameRadio)
352  .addComponent(searchAccountRadio)
353  .addComponent(searchBtn))
354  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
355  .addComponent(resultsPane, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
356  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
357  .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
358  .addComponent(editBtn)
359  .addComponent(createBtn)
360  .addComponent(deleteBtn))
361  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
362  .addComponent(createButtonSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 4, javax.swing.GroupLayout.PREFERRED_SIZE)
363  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
364  .addComponent(createAccountBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
365  .addContainerGap())
366  );
367 
368  mainSplitPane.setLeftComponent(searchPanel);
369 
370  detailsScrollPane.setViewportView(detailsPanel);
371 
372  mainSplitPane.setRightComponent(detailsScrollPane);
373 
374  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
375  this.setLayout(layout);
376  layout.setHorizontalGroup(
377  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
378  .addComponent(mainSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 816, Short.MAX_VALUE)
379  );
380  layout.setVerticalGroup(
381  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
382  .addComponent(mainSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)
383  );
384  }// </editor-fold>//GEN-END:initComponents
385 
386  // Variables declaration - do not modify//GEN-BEGIN:variables
387  private javax.swing.JButton createAccountBtn;
388  private javax.swing.JButton createBtn;
389  private javax.swing.JSeparator createButtonSeparator;
390  private javax.swing.JButton deleteBtn;
392  private javax.swing.JScrollPane detailsScrollPane;
393  private javax.swing.JButton editBtn;
394  private javax.swing.JSplitPane mainSplitPane;
395  private javax.swing.JScrollPane resultsPane;
396  private javax.swing.JTable resultsTable;
397  private javax.swing.JRadioButton searchAccountRadio;
398  private javax.swing.JButton searchBtn;
399  private javax.swing.ButtonGroup searchButtonGroup;
400  private javax.swing.JTextField searchField;
401  private javax.swing.JRadioButton searchNameRadio;
402  private javax.swing.JPanel searchPanel;
403  // End of variables declaration//GEN-END:variables
404 
405 }
static Collection< Persona > getPersonaByName(String partialName)
Definition: Persona.java:418
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
org.sleuthkit.autopsy.centralrepository.persona.PersonaDetailsPanel detailsPanel
static Collection< Persona > getPersonaByAccountIdentifierLike(String partialName)
Definition: Persona.java:441

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