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

Copyright © 2012-2016 Basis Technology. Generated on: Tue Jun 13 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.