Autopsy  4.12.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 java.util.logging.Level;
26 import javax.swing.JComponent;
27 import javax.swing.JMenuItem;
28 import org.openide.awt.DynamicMenuContent;
29 import org.openide.util.NbBundle;
33 import org.sleuthkit.datamodel.Content;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
40 final class RunIngestSubMenu extends JMenuItem implements DynamicMenuContent {
41 
42  private static final Logger logger = Logger.getLogger(RunIngestSubMenu.class.getName());
43 
51  @Override
52  public JComponent[] getMenuPresenters() {
53  List<Content> dataSources = new ArrayList<>();
54 
55  try {
56  dataSources = Case.getCurrentCaseThrows().getDataSources();
57  } catch (IllegalStateException ex) {
58  // No open Cases, create a disabled empty menu
59  return getEmpty();
60  } catch (TskCoreException | NoCurrentCaseException e) {
61  logger.log(Level.INFO, "Exception getting images: " + e.getMessage());
62  }
63  JComponent[] comps = new JComponent[dataSources.size()];
64 
65  // Add Images to the component list
66  for (int i = 0; i < dataSources.size(); i++) {
67  String action = dataSources.get(i).getName();
68  JMenuItem menuItem = new JMenuItem(action);
69  menuItem.setActionCommand(action.toUpperCase());
70  menuItem.addActionListener(new RunIngestModulesAction(Collections.<Content>singletonList(dataSources.get(i))));
71  comps[i] = menuItem;
72  }
73  // If no dataSources are open, create a disabled empty menu
74  if (dataSources.isEmpty()) {
75  return getEmpty();
76  }
77  return comps;
78  }
79 
80  // returns a disabled empty menu
81  private JComponent[] getEmpty() {
82  JComponent[] comps = new JComponent[1];
83  JMenuItem emptyMenu = new JMenuItem(NbBundle.getMessage(RunIngestSubMenu.class, "RunIngestSubMenu.menuItem.empty"));
84  comps[0] = emptyMenu;
85  comps[0].setEnabled(false);
86  return comps;
87  }
88 
99  @Override
100  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
101  return getMenuPresenters();
102  }
103 
104 }

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.