Autopsy  4.5.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-2017 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.nodes.Node;
27 import org.openide.util.NbBundle;
28 import org.openide.windows.TopComponent;
29 import org.openide.windows.WindowManager;
33 
39 // Registered as a service provider in layer.xml
40 //@TopComponent.Description(preferredID = "DataContentTopComponent")
41 //@TopComponent.Registration(mode = "output", openAtStartup = true)
42 //@TopComponent.OpenActionRegistration(displayName = "#CTL_DataContentAction", preferredID = "DataContentTopComponent")
43 public final class DataContentTopComponent extends TopComponent implements DataContent {
44 
45  private static final Logger logger = Logger.getLogger(DataContentTopComponent.class.getName());
46 
47  // reference to the "default" TC that always stays open
49  private static final long serialVersionUID = 1L;
50  // set to true if this is the TC that always stays open and is the default place to display content
51  private final boolean isDefault;
52  // the content panel holding tabs with content viewers
54 
55  // contains a list of the undocked TCs
56  private static final ArrayList<DataContentTopComponent> newWindowList = new ArrayList<>();
57  private static final String PREFERRED_ID = "DataContentTopComponent"; //NON-NLS
58  private static final String DEFAULT_NAME = NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent");
59  private static final String TOOLTIP_TEXT = NbBundle.getMessage(DataContentTopComponent.class, "HINT_DataContentTopComponent");
60 
61  private DataContentTopComponent(boolean isDefault, String name) {
63  setName(name);
64  setToolTipText(TOOLTIP_TEXT);
65 
66  this.isDefault = isDefault;
67 
68  dataContentPanel = new DataContentPanel(isDefault);
69  add(dataContentPanel);
70 
71  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, isDefault); // prevent option to close compoment in GUI
72  logger.log(Level.INFO, "Created DataContentTopComponent instance: {0}", this); //NON-NLS
73  }
74 
84  public static DataContentTopComponent createUndocked(String filePath, Node givenNode) {
85 
86  DataContentTopComponent dctc = new DataContentTopComponent(false, filePath);
87  dctc.componentOpened();
88  dctc.setNode(givenNode);
89 
90  newWindowList.add(dctc);
91 
92  return dctc;
93  }
94 
103  public static synchronized DataContentTopComponent getDefault() {
104  if (defaultInstance == null) {
105  defaultInstance = new DataContentTopComponent(true, DEFAULT_NAME);
106  }
107  return defaultInstance;
108  }
109 
116  public static synchronized DataContentTopComponent findInstance() {
117  TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
118  if (win == null) {
119  logger.warning("Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); //NON-NLS
120  return getDefault();
121  }
122  if (win instanceof DataContentTopComponent) {
123  return (DataContentTopComponent) win;
124  }
125  logger.warning(
126  "There seem to be multiple components with the '" + PREFERRED_ID //NON-NLS
127  + "' ID. That is a potential source of errors and unexpected behavior."); //NON-NLS
128  return getDefault();
129  }
130 
131  @Override
132  public int getPersistenceType() {
133  return TopComponent.PERSISTENCE_NEVER;
134  }
135 
136  @Override
137  public void componentOpened() {
138  }
139 
140  @Override
141  public void componentClosed() {
142 
143  dataContentPanel.setNode(null);
144 
145  if (!this.isDefault) {
146  newWindowList.remove(this);
147  }
148  }
149 
150  @Override
151  protected String preferredID() {
152  if (this.isDefault) {
153  return PREFERRED_ID;
154  } else {
155  return this.getName();
156  }
157  }
158 
159  @Override
160  public void setNode(Node selectedNode) {
161  dataContentPanel.setNode(selectedNode);
162  }
163 
164  @Override
165  public boolean canClose() {
166  /*
167  * If this is the main content viewers top component in the bottom of
168  * the main window, only it to be closed when there's no case opened or
169  * no data sources in the open case.
170  */
171  return (!this.isDefault) || !Case.isCaseOpen() || Case.getCurrentCase().hasData() == false;
172  }
173 
174  @Override
175  public void propertyChange(PropertyChangeEvent evt) {
176  }
177 
183  public JTabbedPane getTabPanels() {
184  return dataContentPanel.getTabPanels();
185  }
186 
192  public static List<DataContentTopComponent> getNewWindowList() {
193  return newWindowList;
194  }
195 
201  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
202  private void initComponents() {
203 
204  setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
205  }// </editor-fold>//GEN-END:initComponents
206  // Variables declaration - do not modify//GEN-BEGIN:variables
207  // End of variables declaration//GEN-END:variables
208 
209 }
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: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.