Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
MergeHostMenuAction.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 org.openide.util.NbBundle.Messages;
29 import org.openide.util.actions.Presenter;
33 import org.sleuthkit.datamodel.Host;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
40 @Messages({
41  "MergeHostMenuAction_menuTitle=Merge Into Other Host",})
42 public class MergeHostMenuAction extends AbstractAction implements Presenter.Popup {
43 
44  private static final Logger logger = Logger.getLogger(MergeHostMenuAction.class.getName());
45 
46  private final Host sourceHost;
47 
53  public MergeHostMenuAction(Host host) {
54  super("");
55  this.sourceHost = host;
56  }
57 
58  @Override
59  @SuppressWarnings("NoopMethodInAbstractClass")
60  public void actionPerformed(ActionEvent event) {
61  }
62 
63  @Override
64  public JMenuItem getPopupPresenter() {
65  JMenu menu = new JMenu(Bundle.MergeHostMenuAction_menuTitle());
66 
67  // Get a list of all other hosts
68  List<Host> otherHosts = Collections.emptyList();
69  try {
70  otherHosts = Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().getAllHosts();
71  otherHosts.remove(sourceHost);
72  } catch (NoCurrentCaseException | TskCoreException ex) {
73  logger.log(Level.WARNING, "Error getting hosts for case.", ex);
74  }
75 
76  // If there are no other hosts, disable the menu item. Otherwise add
77  // the other hosts to the menu.
78  if (otherHosts.isEmpty()) {
79  menu.setEnabled(false);
80  } else {
81  menu.setEnabled(true);
82  otherHosts.stream()
83  .filter(p -> p != null && p.getName() != null)
84  .sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName()))
85  .map(p -> new JMenuItem(new MergeHostAction(sourceHost, p)))
86  .forEach(menu::add);
87  }
88 
89  return menu;
90  }
91 
92 }
93 
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.