Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataExplorerDynamicMenu.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.menuactions;
20 
21 import java.util.Collection;
22 import javax.swing.JComponent;
23 import javax.swing.JMenuItem;
24 import org.openide.awt.DynamicMenuContent;
25 import org.openide.util.Lookup;
26 import org.openide.windows.TopComponent;
30 
36 class DataExplorerDynamicMenu extends JMenuItem implements DynamicMenuContent {
37 
38  DataExplorerDynamicMenu() {
39  }
40 
41  @Override
42  public JComponent[] getMenuPresenters() {
43  Collection<? extends DataExplorer> dataExplorers = Lookup.getDefault().lookupAll(DataExplorer.class);
44 
45  int totalItem = dataExplorers.size();
46  JComponent[] comps = new JComponent[totalItem];
47 
48  int i = 0;
49  for (DataExplorer dx : dataExplorers) {
50  if (!dx.hasMenuOpenAction()) {
51  continue;
52  }
53  TopComponent explorerWin = dx.getTopComponent();
54  JMenuItem item = new JMenuItem(explorerWin.getName());
55  item.addActionListener(new OpenTopComponentAction(explorerWin));
56 
57  try {
58  Case currentCase = Case.getCurrentCaseThrows();
59  item.setEnabled(currentCase.hasData());
60  } catch (NoCurrentCaseException ex) {
61  item.setEnabled(false); // disable the menu when no case is opened
62  }
63 
64  comps[i++] = item;
65  }
66 
67  return comps;
68  }
69 
70  @Override
71  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
72  return getMenuPresenters();
73  }
74 
75 }

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