Autopsy  4.1
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 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;
29 
35 class DataExplorerDynamicMenu extends JMenuItem implements DynamicMenuContent {
36 
37  DataExplorerDynamicMenu() {
38  }
39 
40  @Override
41  public JComponent[] getMenuPresenters() {
42  Collection<? extends DataExplorer> dataExplorers = Lookup.getDefault().lookupAll(DataExplorer.class);
43 
44  int totalItem = dataExplorers.size();
45  JComponent[] comps = new JComponent[totalItem];
46 
47  int i = 0;
48  for (DataExplorer dx : dataExplorers) {
49  if (!dx.hasMenuOpenAction()) {
50  continue;
51  }
52  TopComponent explorerWin = dx.getTopComponent();
53  JMenuItem item = new JMenuItem(explorerWin.getName());
54  item.addActionListener(new OpenTopComponentAction(explorerWin));
55 
56  try {
57  Case currentCase = Case.getCurrentCase();
58  item.setEnabled(currentCase.hasData());
59  } catch (IllegalStateException ex) {
60  item.setEnabled(false); // disable the menu when no case is opened
61  }
62 
63  comps[i++] = item;
64  }
65 
66  return comps;
67  }
68 
69  @Override
70  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
71  return getMenuPresenters();
72  }
73 
74 }

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