Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentTopComponent.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.corecomponents;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.JTabbedPane;
26 import org.openide.explorer.ExplorerManager;
27 import org.openide.explorer.ExplorerUtils;
28 import org.openide.nodes.Node;
29 import org.openide.util.NbBundle;
30 import org.openide.windows.TopComponent;
31 import org.openide.windows.WindowManager;
36 
42 // Registered as a service provider in layer.xml
43 //@TopComponent.Description(preferredID = "DataContentTopComponent")
44 //@TopComponent.Registration(mode = "output", openAtStartup = true)
45 //@TopComponent.OpenActionRegistration(displayName = "#CTL_DataContentAction", preferredID = "DataContentTopComponent")
46 public final class DataContentTopComponent extends TopComponent implements DataContent, ExplorerManager.Provider {
47 
48  private static final Logger logger = Logger.getLogger(DataContentTopComponent.class.getName());
49 
50  // reference to the "default" TC that always stays open
52  private static final long serialVersionUID = 1L;
53  // set to true if this is the TC that always stays open and is the default place to display content
54  private final boolean isDefault;
55  // the content panel holding tabs with content viewers
57  private final ExplorerManager explorerManager = new ExplorerManager();
58 
59  private Node selectedNode;
60 
61  // contains a list of the undocked TCs
62  private static final ArrayList<DataContentTopComponent> newWindowList = new ArrayList<>();
63  private static final String PREFERRED_ID = "DataContentTopComponent"; //NON-NLS
64  private static final String DEFAULT_NAME = NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent");
65  private static final String TOOLTIP_TEXT = NbBundle.getMessage(DataContentTopComponent.class, "HINT_DataContentTopComponent");
66 
67  private DataContentTopComponent(boolean isDefault, String name) {
69  setName(name);
70  setToolTipText(TOOLTIP_TEXT);
71 
72  this.isDefault = isDefault;
73 
74  dataContentPanel = new DataContentPanel(isDefault);
75  add(dataContentPanel);
76 
77  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
78 
79  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, isDefault); // prevent option to close compoment in GUI
80  logger.log(Level.INFO, "Created DataContentTopComponent instance: {0}", this); //NON-NLS
81  }
82 
92  public static DataContentTopComponent createUndocked(String filePath, Node givenNode) {
93 
94  DataContentTopComponent dctc = new DataContentTopComponent(false, filePath);
95  dctc.componentOpened();
96  dctc.setNode(givenNode);
97 
98  newWindowList.add(dctc);
99 
100  return dctc;
101  }
102 
111  public static synchronized DataContentTopComponent getDefault() {
112  if (defaultInstance == null) {
113  defaultInstance = new DataContentTopComponent(true, DEFAULT_NAME);
114  }
115  return defaultInstance;
116  }
117 
124  public static synchronized DataContentTopComponent findInstance() {
125  TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
126  if (win == null) {
127  logger.warning("Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); //NON-NLS
128  return getDefault();
129  }
130  if (win instanceof DataContentTopComponent) {
131  return (DataContentTopComponent) win;
132  }
133  logger.warning(
134  "There seem to be multiple components with the '" + PREFERRED_ID //NON-NLS
135  + "' ID. That is a potential source of errors and unexpected behavior."); //NON-NLS
136  return getDefault();
137  }
138 
139  @Override
140  public ExplorerManager getExplorerManager() {
141  return explorerManager;
142  }
143 
144  @Override
145  public int getPersistenceType() {
146  return TopComponent.PERSISTENCE_NEVER;
147  }
148 
149  @Override
150  public void componentOpened() {
151  }
152 
153  @Override
154  public void componentClosed() {
155 
156  dataContentPanel.setNode(null);
157 
158  if (!this.isDefault) {
159  newWindowList.remove(this);
160  }
161  }
162 
163  @Override
164  protected String preferredID() {
165  if (this.isDefault) {
166  return PREFERRED_ID;
167  } else {
168  return this.getName();
169  }
170  }
171 
172  @Override
173  public void setNode(Node selectedNode) {
174  dataContentPanel.setNode(selectedNode);
175  this.selectedNode = selectedNode;
176  }
177 
178  @Override
179  public boolean canClose() {
180  /*
181  * If this is the main content viewers top component in the bottom of
182  * the main window, only it to be closed when there's no case opened or
183  * no data sources in the open case.
184  */
185  Case openCase;
186  try {
187  openCase = Case.getOpenCase();
188  } catch (NoCurrentCaseException ex) {
189  return true;
190  }
191 
192  return (this.isDefault ==false) ||( openCase.hasData() == false);
193  }
194 
195  @Override
196  public void propertyChange(PropertyChangeEvent evt) {
197  }
198 
204  Node getNode() {
205  return selectedNode;
206  }
207 
213  public JTabbedPane getTabPanels() {
214  return dataContentPanel.getTabPanels();
215  }
216 
222  public static List<DataContentTopComponent> getNewWindowList() {
223  return newWindowList;
224  }
225 
231  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
232  private void initComponents() {
233 
234  setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
235  }// </editor-fold>//GEN-END:initComponents
236  // Variables declaration - do not modify//GEN-BEGIN:variables
237  // End of variables declaration//GEN-END:variables
238 
239 }
static DataContentTopComponent createUndocked(String filePath, Node givenNode)
static synchronized DataContentTopComponent findInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static final ArrayList< DataContentTopComponent > newWindowList

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.