Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AssociatePersonsMenuAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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.datamodel.hosts;
20 
21 import java.awt.event.ActionEvent;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.AbstractAction;
26 import javax.swing.JMenu;
27 import javax.swing.JMenuItem;
28 import javax.swing.JSeparator;
29 import org.openide.util.NbBundle.Messages;
30 import org.openide.util.actions.Presenter;
34 import org.sleuthkit.datamodel.Host;
35 import org.sleuthkit.datamodel.Person;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
43 @Messages({
44  "AssociatePersonsMenuAction_menuTitle=Associate with Person",})
45 public class AssociatePersonsMenuAction extends AbstractAction implements Presenter.Popup {
46 
47  private static final Logger logger = Logger.getLogger(AssociatePersonsMenuAction.class.getName());
48 
49  private final Host host;
50 
56  public AssociatePersonsMenuAction(Host host) {
57  super("");
58  this.host = host;
59  }
60 
61  @Override
62  @SuppressWarnings("NoopMethodInAbstractClass")
63  public void actionPerformed(ActionEvent event) {
64  }
65 
66  @Override
67  public JMenuItem getPopupPresenter() {
68  JMenu menu = new JMenu(Bundle.AssociatePersonsMenuAction_menuTitle());
69 
70  List<Person> existingPersons = Collections.emptyList();
71  try {
72  existingPersons = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getPersons();
73  } catch (NoCurrentCaseException | TskCoreException ex) {
74  logger.log(Level.WARNING, "Error getting persons for case.", ex);
75  }
76 
77  existingPersons.stream()
78  .filter(p -> p != null && p.getName() != null)
79  .sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName()))
80  .map(p -> new JMenuItem(new AssociatePersonAction(this.host, p)))
81  .forEach(menu::add);
82 
83  if (menu.getItemCount() > 0) {
84  menu.add(new JSeparator());
85  }
86 
87  menu.add(new JMenuItem(new AssociateNewPersonAction(this.host)));
88  return menu;
89  }
90 
91 }
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.