Autopsy  4.17.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-2019 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 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
44 public final class DataContentTopComponent extends TopComponent implements DataContent, ExplorerManager.Provider {
45 
46  private static final Logger logger = Logger.getLogger(DataContentTopComponent.class.getName());
47 
48  // reference to the "default" TC that always stays open
50  private static final long serialVersionUID = 1L;
51  // set to true if this is the TC that always stays open and is the default place to display content
52  private final boolean isDefault;
53  // the content panel holding tabs with content viewers
55  private final ExplorerManager explorerManager = new ExplorerManager();
56 
57  private Node selectedNode;
58 
59  // contains a list of the undocked TCs
60  private static final ArrayList<DataContentTopComponent> newWindowList = new ArrayList<>();
61  private static final String PREFERRED_ID = "DataContentTopComponent"; //NON-NLS
62  private static final String DEFAULT_NAME = NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent");
63  private static final String TOOLTIP_TEXT = NbBundle.getMessage(DataContentTopComponent.class, "HINT_DataContentTopComponent");
64 
65  private DataContentTopComponent(boolean isDefault, String name) {
66  initComponents();
67  setName(name);
68  setToolTipText(TOOLTIP_TEXT);
69 
70  this.isDefault = isDefault;
71 
72  dataContentPanel = new DataContentPanel(isDefault);
73  add(dataContentPanel);
74 
75  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
76 
77  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, isDefault); // prevent option to close compoment in GUI
78  logger.log(Level.INFO, "Created DataContentTopComponent instance: {0}", this); //NON-NLS
79  }
80 
90  public static DataContentTopComponent createUndocked(String filePath, Node givenNode) {
91 
92  DataContentTopComponent dctc = new DataContentTopComponent(false, filePath);
93  dctc.componentOpened();
94  dctc.setNode(givenNode);
95 
96  newWindowList.add(dctc);
97 
98  return dctc;
99  }
100 
109  public static synchronized DataContentTopComponent getDefault() {
110  if (defaultInstance == null) {
111  defaultInstance = new DataContentTopComponent(true, DEFAULT_NAME);
112  }
113  return defaultInstance;
114  }
115 
122  public static synchronized DataContentTopComponent findInstance() {
123  TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
124  if (win == null) {
125  logger.log(Level.INFO, "Cannot find " + PREFERRED_ID + " component. It will "
126  + "not be located properly in the window system."); //NON-NLS
127  return getDefault();
128  }
129 
130  if (win instanceof DataContentTopComponent) {
131  return (DataContentTopComponent) win;
132  }
133 
134  logger.log(Level.INFO, "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 
137  return getDefault();
138  }
139 
140  @Override
141  public ExplorerManager getExplorerManager() {
142  return explorerManager;
143  }
144 
145  @Override
146  public int getPersistenceType() {
147  return TopComponent.PERSISTENCE_NEVER;
148  }
149 
150  @Override
151  public void componentOpened() {
152  }
153 
154  @Override
155  public void componentClosed() {
156 
157  dataContentPanel.setNode(null);
158 
159  if (!this.isDefault) {
160  newWindowList.remove(this);
161  }
162  }
163 
164  @Override
165  protected String preferredID() {
166  if (this.isDefault) {
167  return PREFERRED_ID;
168  } else {
169  return this.getName();
170  }
171  }
172 
173  @Override
174  public void setNode(Node selectedNode) {
175  dataContentPanel.setNode(selectedNode);
176  this.selectedNode = selectedNode;
177  }
178 
179  @Override
180  public boolean canClose() {
181  /*
182  * If this is the main content viewers top component in the bottom of
183  * the main window, only it to be closed when there's no case opened or
184  * no data sources in the open case.
185  */
186  Case openCase;
187  try {
188  openCase = Case.getCurrentCaseThrows();
189  } catch (NoCurrentCaseException ex) {
190  return true;
191  }
192 
193  return (this.isDefault ==false) ||( openCase.hasData() == false);
194  }
195 
196  @Override
197  public void propertyChange(PropertyChangeEvent evt) {
198  }
199 
205  Node getNode() {
206  return selectedNode;
207  }
208 
214  public JTabbedPane getTabPanels() {
215  return dataContentPanel.getTabPanels();
216  }
217 
223  public static List<DataContentTopComponent> getNewWindowList() {
224  return newWindowList;
225  }
226 
232  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
233  private void initComponents() {
234 
235  setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
236  }// </editor-fold>//GEN-END:initComponents
237  // Variables declaration - do not modify//GEN-BEGIN:variables
238  // End of variables declaration//GEN-END:variables
239 
240 }
static DataContentTopComponent createUndocked(String filePath, Node givenNode)
static synchronized DataContentTopComponent findInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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