Autopsy  4.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  try {
54  Case currentCase = Case.getCurrentCase();
55  defaultItem.setEnabled(currentCase.hasData());
56  } catch (IllegalStateException ex) {
57  defaultItem.setEnabled(false); // disable the menu when no case is opened
58  }
59 
60  comps[counter++] = defaultItem;
61 
62  // add the submenu
63  if (newWindowLists != null) {
64  if (newWindowLists.size() > 0) {
65 
66  JMenu submenu = new JMenu(
67  NbBundle.getMessage(this.getClass(), "DataContentDynamicMenu.menu.dataContentWin.text"));
68  for (int i = 0; i < newWindowLists.size(); i++) {
69  DataContentTopComponent dctc = newWindowLists.get(i);
70  JMenuItem item = new JMenuItem(dctc.getName());
71  item.addActionListener(new OpenTopComponentAction(dctc));
72  submenu.add(item);
73  }
74 
75  comps[counter++] = submenu;
76  }
77  }
78 
79  return comps;
80  }
81 
82  @Override
83  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
84  return getMenuPresenters();
85  }
86 }
static synchronized DataContentTopComponent findInstance()

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