Autopsy  4.8.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-2018 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;
31 import org.sleuthkit.datamodel.Content;
32 import org.sleuthkit.datamodel.TskCoreException;
33 
38 final class RunIngestSubMenu extends JMenuItem implements DynamicMenuContent {
39 
47  @Override
48  public JComponent[] getMenuPresenters() {
49  List<Content> dataSources = new ArrayList<>();
50 
51  try {
52  dataSources = Case.getCurrentCaseThrows().getDataSources();
53  } catch (IllegalStateException ex) {
54  // No open Cases, create a disabled empty menu
55  return getEmpty();
56  } catch (TskCoreException | NoCurrentCaseException e) {
57  System.out.println("Exception getting images: " + e.getMessage()); //NON-NLS
58  }
59  JComponent[] comps = new JComponent[dataSources.size()];
60 
61  // Add Images to the component list
62  for (int i = 0; i < dataSources.size(); i++) {
63  String action = dataSources.get(i).getName();
64  JMenuItem menuItem = new JMenuItem(action);
65  menuItem.setActionCommand(action.toUpperCase());
66  menuItem.addActionListener(new RunIngestModulesAction(Collections.<Content>singletonList(dataSources.get(i))));
67  comps[i] = menuItem;
68  }
69  // If no dataSources are open, create a disabled empty menu
70  if (dataSources.isEmpty()) {
71  return getEmpty();
72  }
73  return comps;
74  }
75 
76  // returns a disabled empty menu
77  private JComponent[] getEmpty() {
78  JComponent[] comps = new JComponent[1];
79  JMenuItem emptyMenu = new JMenuItem(NbBundle.getMessage(RunIngestSubMenu.class, "RunIngestSubMenu.menuItem.empty"));
80  comps[0] = emptyMenu;
81  comps[0].setEnabled(false);
82  return comps;
83  }
84 
95  @Override
96  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
97  return getMenuPresenters();
98  }
99 
100 }

Copyright © 2012-2018 Basis Technology. Generated on: Thu Oct 4 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.