Autopsy  4.6.0
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-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.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;
33 
38 class DataContentDynamicMenu extends JMenuItem implements DynamicMenuContent {
39 
40  @Override
41  public JComponent[] getMenuPresenters() {
42  List<DataContentTopComponent> newWindowLists = DataContentTopComponent.getNewWindowList();
43 
44  // Get DataContent provider to include in the menu
45  int totalItems = newWindowLists.size() > 0 ? 2 : 1;
46  JComponent[] comps = new JComponent[totalItems];
47  int counter = 0;
48 
49  TopComponent contentWin = DataContentTopComponent.findInstance();
50  JMenuItem defaultItem = new JMenuItem(contentWin.getName()); // set the main name
51 
52  defaultItem.addActionListener(new OpenTopComponentAction(contentWin));
53 
54  try {
55  Case currentCase = Case.getOpenCase();
56  defaultItem.setEnabled(currentCase.hasData());
57  } catch (NoCurrentCaseException ex) {
58  defaultItem.setEnabled(false); // disable the menu when no case is opened
59  }
60 
61  comps[counter++] = defaultItem;
62 
63  // add the submenu
64  if (newWindowLists != null) {
65  if (newWindowLists.size() > 0) {
66 
67  JMenu submenu = new JMenu(
68  NbBundle.getMessage(this.getClass(), "DataContentDynamicMenu.menu.dataContentWin.text"));
69  for (int i = 0; i < newWindowLists.size(); i++) {
70  DataContentTopComponent dctc = newWindowLists.get(i);
71  JMenuItem item = new JMenuItem(dctc.getName());
72  item.addActionListener(new OpenTopComponentAction(dctc));
73  submenu.add(item);
74  }
75 
76  comps[counter++] = submenu;
77  }
78  }
79 
80  return comps;
81  }
82 
83  @Override
84  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
85  return getMenuPresenters();
86  }
87 }
static synchronized DataContentTopComponent findInstance()

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