Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
RunIngestSubMenu.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 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.ingest;
20 
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import javax.swing.JComponent;
26 import javax.swing.JMenuItem;
27 import org.openide.awt.DynamicMenuContent;
28 import org.openide.util.NbBundle;
32 import org.sleuthkit.datamodel.Content;
33 import org.sleuthkit.datamodel.TskCoreException;
34 
39 final class RunIngestSubMenu extends JMenuItem implements DynamicMenuContent {
40 
41  private static final Logger logger = Logger.getLogger(RunIngestSubMenu.class.getName());
42 
50  @Override
51  public JComponent[] getMenuPresenters() {
52  List<Content> dataSources = new ArrayList<>();
53 
54  try {
55  dataSources = Case.getCurrentCaseThrows().getDataSources();
56  } catch (IllegalStateException | NoCurrentCaseException ex) {
57  // No open Cases, create a disabled empty menu
58  return getEmpty();
59  } catch (TskCoreException e) {
60  System.out.println("Exception getting images: " + e.getMessage()); //NON-NLS
61  }
62  JComponent[] comps = new JComponent[dataSources.size()];
63 
64  // Add Images to the component list
65  for (int i = 0; i < dataSources.size(); i++) {
66  String action = dataSources.get(i).getName();
67  JMenuItem menuItem = new JMenuItem(action);
68  menuItem.setActionCommand(action.toUpperCase());
69  menuItem.addActionListener(new RunIngestModulesAction(Collections.<Content>singletonList(dataSources.get(i))));
70  comps[i] = menuItem;
71  }
72  // If no dataSources are open, create a disabled empty menu
73  if (dataSources.isEmpty()) {
74  return getEmpty();
75  }
76  return comps;
77  }
78 
79  // returns a disabled empty menu
80  private JComponent[] getEmpty() {
81  JComponent[] comps = new JComponent[1];
82  JMenuItem emptyMenu = new JMenuItem(NbBundle.getMessage(RunIngestSubMenu.class, "RunIngestSubMenu.menuItem.empty"));
83  comps[0] = emptyMenu;
84  comps[0].setEnabled(false);
85  return comps;
86  }
87 
98  @Override
99  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
100  return getMenuPresenters();
101  }
102 
103 }

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