Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentDynamicMenu.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.List;
22 import javax.swing.JComponent;
23 import javax.swing.JMenu;
24 import javax.swing.JMenuItem;
25 import org.openide.awt.DynamicMenuContent;
26 import org.openide.util.Lookup;
27 import org.openide.util.NbBundle;
28 import org.openide.windows.TopComponent;
32 
37 class DataContentDynamicMenu extends JMenuItem implements DynamicMenuContent {
38 
39  @Override
40  public JComponent[] getMenuPresenters() {
41  List<DataContentTopComponent> newWindowLists = DataContentTopComponent.getNewWindowList();
42 
43  // Get DataContent provider to include in the menu
44  int totalItems = newWindowLists.size() > 0 ? 2 : 1;
45  JComponent[] comps = new JComponent[totalItems];
46  int counter = 0;
47 
48  TopComponent contentWin = DataContentTopComponent.findInstance();
49  JMenuItem defaultItem = new JMenuItem(contentWin.getName()); // set the main name
50 
51  defaultItem.addActionListener(new OpenTopComponentAction(contentWin));
52 
53  if (!Case.isCaseOpen() || Case.getCurrentCase().hasData() == false) {
54  defaultItem.setEnabled(false); // disable the menu items when no case is opened
55  } else {
56  defaultItem.setEnabled(true); // enable the menu items when there's a case opened / created
57  }
58 
59  comps[counter++] = defaultItem;
60 
61  // add the submenu
62  if (newWindowLists != null) {
63  if (newWindowLists.size() > 0) {
64 
65  JMenu submenu = new JMenu(
66  NbBundle.getMessage(this.getClass(), "DataContentDynamicMenu.menu.dataContentWin.text"));
67  for (int i = 0; i < newWindowLists.size(); i++) {
68  DataContentTopComponent dctc = newWindowLists.get(i);
69  JMenuItem item = new JMenuItem(dctc.getName());
70  item.addActionListener(new OpenTopComponentAction(dctc));
71  submenu.add(item);
72  }
73 
74  comps[counter++] = submenu;
75  }
76  }
77 
78  return comps;
79  }
80 
81  @Override
82  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
83  return getMenuPresenters();
84  }
85 }
static synchronized DataContentTopComponent findInstance()

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