Autopsy  4.5.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataResultTopComponent.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.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.JComponent;
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.Mode;
31 import org.openide.windows.RetainLocation;
32 import org.openide.windows.TopComponent;
33 import org.openide.windows.WindowManager;
39 
59 @RetainLocation("editor")
60 public class DataResultTopComponent extends TopComponent implements DataResult, ExplorerManager.Provider {
61 
62  private static final Logger logger = Logger.getLogger(DataResultTopComponent.class.getName());
63  private final ExplorerManager explorerManager = new ExplorerManager();
64  private final DataResultPanel dataResultPanel; //embedded component with all the logic
65  private boolean isMain;
66  private String customModeName;
67 
68  //keep track of tcs opened for menu presenters
69  private static final List<String> activeComponentIds = Collections.synchronizedList(new ArrayList<String>());
70 
78  public DataResultTopComponent(boolean isMain, String title) {
79  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
80  this.dataResultPanel = new DataResultPanel(title, isMain);
81  initComponents();
82  customizeComponent(isMain, title);
83  }
84 
95  DataResultTopComponent(String name, String mode, DataContentTopComponent customContentViewer) {
96  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
97  this.customModeName = mode;
98  dataResultPanel = new DataResultPanel(name, customContentViewer);
99  initComponents();
100  customizeComponent(isMain, name);
101  }
102 
103  private void customizeComponent(boolean isMain, String title) {
104  this.isMain = isMain;
105  this.customModeName = null;
106 
107  setToolTipText(NbBundle.getMessage(DataResultTopComponent.class, "HINT_NodeTableTopComponent"));
108 
109  setTitle(title); // set the title
110  setName(title);
111  getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(AddBookmarkTagAction.BOOKMARK_SHORTCUT, "addBookmarkTag"); //NON-NLS
112  getActionMap().put("addBookmarkTag", new AddBookmarkTagAction()); //NON-NLS
113 
114  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, isMain); // set option to close compoment in GUI
115  putClientProperty(TopComponent.PROP_MAXIMIZATION_DISABLED, true);
116  putClientProperty(TopComponent.PROP_DRAGGING_DISABLED, true);
117 
118  activeComponentIds.add(title);
119  }
120 
130  public static void initInstance(String pathText, Node givenNode, int totalMatches, DataResultTopComponent newDataResult) {
131  newDataResult.setNumMatches(totalMatches);
132 
133  newDataResult.open(); // open it first so the component can be initialized
134 
135  // set the tree table view
136  newDataResult.setNode(givenNode);
137  newDataResult.setPath(pathText);
138 
139  newDataResult.requestActive();
140  }
141 
153  public static DataResultTopComponent createInstance(String title, String pathText, Node givenNode, int totalMatches) {
154  DataResultTopComponent newDataResult = new DataResultTopComponent(false, title);
155 
156  initInstance(pathText, givenNode, totalMatches, newDataResult);
157 
158  return newDataResult;
159  }
160 
176  public static DataResultTopComponent createInstance(String title, final String mode, String pathText, Node givenNode, int totalMatches, DataContentTopComponent dataContentWindow) {
177  DataResultTopComponent newDataResult = new DataResultTopComponent(title, mode, dataContentWindow);
178 
179  initInstance(pathText, givenNode, totalMatches, newDataResult);
180  return newDataResult;
181  }
182 
192  public static DataResultTopComponent createInstance(String title) {
193  final DataResultTopComponent newDataResult = new DataResultTopComponent(false, title);
194 
195  return newDataResult;
196  }
197 
198  @Override
199  public ExplorerManager getExplorerManager() {
200  return explorerManager;
201  }
202 
208  public static List<String> getActiveComponentIds() {
209  return new ArrayList<>(activeComponentIds);
210  }
211 
217  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
218  private void initComponents() {
219 
220  org.sleuthkit.autopsy.corecomponents.DataResultPanel dataResultPanelLocal = dataResultPanel;
221 
222  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
223  this.setLayout(layout);
224  layout.setHorizontalGroup(
225  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226  .addComponent(dataResultPanelLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 967, Short.MAX_VALUE)
227  );
228  layout.setVerticalGroup(
229  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
230  .addComponent(dataResultPanelLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
231  );
232  }// </editor-fold>//GEN-END:initComponents
233  // Variables declaration - do not modify//GEN-BEGIN:variables
234  // End of variables declaration//GEN-END:variables
235 
236  @Override
237  public int getPersistenceType() {
238  if (customModeName == null) {
239  return TopComponent.PERSISTENCE_NEVER;
240  } else {
241  return TopComponent.PERSISTENCE_ALWAYS;
242  }
243  }
244 
245  @Override
246  public void open() {
247  setCustomMode();
248  super.open(); //To change body of generated methods, choose Tools | Templates.
249  }
250 
251  @Override
252  public List<DataResultViewer> getViewers() {
253  return dataResultPanel.getViewers();
254  }
255 
256  private void setCustomMode() {
257  if (customModeName != null) {
258  Mode mode = WindowManager.getDefault().findMode(customModeName);
259  if (mode != null) {
260  logger.log(Level.INFO, "Found custom mode, setting: {0}", customModeName);//NON-NLS
261  mode.dockInto(this);
262  } else {
263  logger.log(Level.WARNING, "Could not find mode: {0}, will dock into the default one", customModeName);//NON-NLS
264  }
265  }
266  }
267 
268  @Override
269  public void componentOpened() {
270  super.componentOpened();
271  this.dataResultPanel.open();
272  }
273 
274  @Override
275  public void componentClosed() {
276  super.componentClosed();
277  activeComponentIds.remove(this.getName());
278  dataResultPanel.close();
279  }
280 
281  @Override
282  protected String preferredID() {
283  return getName();
284  }
285 
286  @Override
287  public String getPreferredID() {
288  return getName();
289  }
290 
291  @Override
292  public void setNode(Node selectedNode) {
293  dataResultPanel.setNode(selectedNode);
294  }
295 
296  @Override
297  public void setTitle(String title) {
298  setName(title);
299  }
300 
301  @Override
302  public void setPath(String pathText) {
303  dataResultPanel.setPath(pathText);
304  }
305 
306  @Override
307  public boolean isMain() {
308  return isMain;
309  }
310 
311  @Override
312  public boolean canClose() {
313  /*
314  * If this is the results top component in the upper right of the main
315  * window, only allow it to be closed when there's no case opened or no
316  * data sources in the open case.
317  */
318  return (!this.isMain) || !Case.isCaseOpen() || Case.getCurrentCase().hasData() == false;
319  }
320 
327  public void resetTabs(Node selectedNode) {
328 
329  dataResultPanel.resetTabs(selectedNode);
330  }
331 
332  public void setSelectedNodes(Node[] selected) {
333  dataResultPanel.setSelectedNodes(selected);
334  }
335 
336  public Node getRootNode() {
337  return dataResultPanel.getRootNode();
338  }
339 
340  void setNumMatches(int matches) {
341  this.dataResultPanel.setNumMatches(matches);
342  }
343 }
static DataResultTopComponent createInstance(String title, String pathText, Node givenNode, int totalMatches)
static DataResultTopComponent createInstance(String title, final String mode, String pathText, Node givenNode, int totalMatches, DataContentTopComponent dataContentWindow)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static DataResultTopComponent createInstance(String title)
static void initInstance(String pathText, Node givenNode, int totalMatches, DataResultTopComponent newDataResult)

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.