Autopsy  4.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 2013 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 org.openide.explorer.ExplorerManager;
27 import org.openide.explorer.ExplorerUtils;
28 import org.openide.util.NbBundle;
29 import org.openide.windows.TopComponent;
30 import org.openide.nodes.Node;
31 import org.openide.windows.Mode;
32 import org.openide.windows.WindowManager;
36 
56 public class DataResultTopComponent extends TopComponent implements DataResult, ExplorerManager.Provider {
57 
58  private static final Logger logger = Logger.getLogger(DataResultTopComponent.class.getName());
59  private ExplorerManager explorerManager = new ExplorerManager();
60  private DataResultPanel dataResultPanel; //embedded component with all the logic
61  private boolean isMain;
62  private String customModeName;
63 
64  //keep track of tcs opened for menu presenters
65  private static final List<String> activeComponentIds = Collections.synchronizedList(new ArrayList<String>());
66 
74  public DataResultTopComponent(boolean isMain, String title) {
75  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
76  this.dataResultPanel = new DataResultPanel(isMain, title);
78  customizeComponent(isMain, title);
79  }
80 
91  DataResultTopComponent(String name, String mode, DataContentTopComponent customContentViewer) {
92  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
93  this.customModeName = mode;
94  dataResultPanel = new DataResultPanel(name, customContentViewer);
96  customizeComponent(isMain, name);
97  }
98 
99  private void customizeComponent(boolean isMain, String title) {
100  this.isMain = isMain;
101  this.customModeName = null;
102 
103  setToolTipText(NbBundle.getMessage(DataResultTopComponent.class, "HINT_NodeTableTopComponent"));
104 
105  setTitle(title); // set the title
106  setName(title);
107 
108  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, isMain); // set option to close compoment in GUI
109  putClientProperty(TopComponent.PROP_MAXIMIZATION_DISABLED, true);
110  putClientProperty(TopComponent.PROP_DRAGGING_DISABLED, true);
111 
112  activeComponentIds.add(title);
113  }
114 
124  public static void initInstance(String pathText, Node givenNode, int totalMatches, DataResultTopComponent newDataResult) {
125  newDataResult.setNumMatches(totalMatches);
126 
127  newDataResult.open(); // open it first so the component can be initialized
128 
129  // set the tree table view
130  newDataResult.setNode(givenNode);
131  newDataResult.setPath(pathText);
132 
133  newDataResult.requestActive();
134  }
135 
147  public static DataResultTopComponent createInstance(String title, String pathText, Node givenNode, int totalMatches) {
148  DataResultTopComponent newDataResult = new DataResultTopComponent(false, title);
149 
150  initInstance(pathText, givenNode, totalMatches, newDataResult);
151 
152  return newDataResult;
153  }
154 
170  public static DataResultTopComponent createInstance(String title, final String mode, String pathText, Node givenNode, int totalMatches, DataContentTopComponent dataContentWindow) {
171  DataResultTopComponent newDataResult = new DataResultTopComponent(title, mode, dataContentWindow);
172 
173  initInstance(pathText, givenNode, totalMatches, newDataResult);
174  return newDataResult;
175  }
176 
186  public static DataResultTopComponent createInstance(String title) {
187  final DataResultTopComponent newDataResult = new DataResultTopComponent(false, title);
188 
189  return newDataResult;
190  }
191 
192  @Override
193  public ExplorerManager getExplorerManager() {
194  return explorerManager;
195  }
196 
202  public static List<String> getActiveComponentIds() {
203  return new ArrayList<>(activeComponentIds);
204  }
205 
211  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
212  private void initComponents() {
213 
215 
216  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
217  this.setLayout(layout);
218  layout.setHorizontalGroup(
219  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220  .addComponent(dataResultPanelLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 967, Short.MAX_VALUE)
221  );
222  layout.setVerticalGroup(
223  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224  .addComponent(dataResultPanelLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
225  );
226  }// </editor-fold>//GEN-END:initComponents
227  // Variables declaration - do not modify//GEN-BEGIN:variables
228  // End of variables declaration//GEN-END:variables
229 
230  @Override
231  public int getPersistenceType() {
232  if (customModeName == null) {
233  return TopComponent.PERSISTENCE_NEVER;
234  } else {
235  return TopComponent.PERSISTENCE_ALWAYS;
236  }
237  }
238 
239  @Override
240  public void open() {
241  setCustomMode();
242  super.open(); //To change body of generated methods, choose Tools | Templates.
243  }
244 
245  @Override
246  public List<DataResultViewer> getViewers() {
247  return dataResultPanel.getViewers();
248  }
249 
250  private void setCustomMode() {
251  if (customModeName != null) {
252  Mode mode = WindowManager.getDefault().findMode(customModeName);
253  if (mode != null) {
254  StringBuilder message = new StringBuilder("Found custom mode, setting: "); //NON-NLS
255  message.append(customModeName);
256  logger.log(Level.INFO, message.toString());
257  mode.dockInto(this);
258 
259  } else {
260  StringBuilder message = new StringBuilder("Could not find mode: "); //NON-NLS
261  message.append(customModeName);
262  message.append(", will dock into the default one"); //NON-NLS
263  logger.log(Level.WARNING, message.toString());
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  return (!this.isMain) || !Case.existsCurrentCase() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
314  }
315 
322  public void resetTabs(Node selectedNode) {
323 
324  dataResultPanel.resetTabs(selectedNode);
325  }
326 
327  public void setSelectedNodes(Node[] selected) {
328  dataResultPanel.setSelectedNodes(selected);
329  }
330 
331  public Node getRootNode() {
332  return dataResultPanel.getRootNode();
333  }
334 
335  void setNumMatches(int matches) {
336  this.dataResultPanel.setNumMatches(matches);
337  }
338 }
static boolean existsCurrentCase()
Definition: Case.java:966
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:166
static DataResultTopComponent createInstance(String title)
static void initInstance(String pathText, Node givenNode, int totalMatches, DataResultTopComponent newDataResult)

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