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

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