Autopsy  3.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 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 
54 public class DataResultTopComponent extends TopComponent implements DataResult, ExplorerManager.Provider {
55 
56  private static final Logger logger = Logger.getLogger(DataResultTopComponent.class.getName());
57  private ExplorerManager explorerManager = new ExplorerManager();
58  private DataResultPanel dataResultPanel; //embedded component with all the logic
59  private boolean isMain;
60  private String customModeName;
61 
62  //keep track of tcs opened for menu presenters
63  private static final List<String> activeComponentIds = Collections.synchronizedList(new ArrayList<String>());
64 
72  public DataResultTopComponent(boolean isMain, String title) {
73  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
74  this.dataResultPanel = new DataResultPanel(isMain, title);
76  customizeComponent(isMain, title);
77  }
78 
88  DataResultTopComponent(String name, String mode, DataContentTopComponent customContentViewer) {
89  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
90  this.customModeName = mode;
91  dataResultPanel = new DataResultPanel(name, customContentViewer);
93  customizeComponent(isMain, name);
94  }
95 
96  private void customizeComponent(boolean isMain, String title) {
97  this.isMain = isMain;
98  this.customModeName = null;
99 
100  setToolTipText(NbBundle.getMessage(DataResultTopComponent.class, "HINT_NodeTableTopComponent"));
101 
102  setTitle(title); // set the title
103  setName(title);
104 
105  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.valueOf(isMain)); // set option to close compoment in GUI
106  putClientProperty(TopComponent.PROP_MAXIMIZATION_DISABLED, true);
107  putClientProperty(TopComponent.PROP_DRAGGING_DISABLED, true);
108 
109  activeComponentIds.add(title);
110  }
111 
119  public static void initInstance(String pathText, Node givenNode, int totalMatches, DataResultTopComponent newDataResult) {
120  newDataResult.setNumMatches(totalMatches);
121 
122  newDataResult.open(); // open it first so the component can be initialized
123 
124  // set the tree table view
125  newDataResult.setNode(givenNode);
126  newDataResult.setPath(pathText);
127 
128  newDataResult.requestActive();
129  }
130 
140  public static DataResultTopComponent createInstance(String title, String pathText, Node givenNode, int totalMatches) {
141  DataResultTopComponent newDataResult = new DataResultTopComponent(false, title);
142 
143  initInstance(pathText, givenNode, totalMatches, newDataResult);
144 
145  return newDataResult;
146  }
147 
160  public static DataResultTopComponent createInstance(String title, final String mode, String pathText, Node givenNode, int totalMatches, DataContentTopComponent dataContentWindow) {
161  DataResultTopComponent newDataResult = new DataResultTopComponent(title, mode, dataContentWindow);
162 
163  initInstance(pathText, givenNode, totalMatches, newDataResult);
164  return newDataResult;
165  }
166 
174  public static DataResultTopComponent createInstance(String title) {
175  final DataResultTopComponent newDataResult = new DataResultTopComponent(false, title);
176 
177  return newDataResult;
178  }
179 
180  @Override
181  public ExplorerManager getExplorerManager() {
182  return explorerManager;
183  }
184 
189  public static List<String> getActiveComponentIds() {
190  return new ArrayList<>(activeComponentIds);
191  }
192 
198  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
199  private void initComponents() {
200 
202 
203  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
204  this.setLayout(layout);
205  layout.setHorizontalGroup(
206  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
207  .addComponent(dataResultPanelLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 967, Short.MAX_VALUE)
208  );
209  layout.setVerticalGroup(
210  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211  .addComponent(dataResultPanelLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
212  );
213  }// </editor-fold>//GEN-END:initComponents
214  // Variables declaration - do not modify//GEN-BEGIN:variables
215  // End of variables declaration//GEN-END:variables
216 
217  @Override
218  public int getPersistenceType() {
219  if (customModeName == null) {
220  return TopComponent.PERSISTENCE_NEVER;
221  } else {
222  return TopComponent.PERSISTENCE_ALWAYS;
223  }
224  }
225 
226  @Override
227  public void open() {
228  setCustomMode();
229  super.open(); //To change body of generated methods, choose Tools | Templates.
230  }
231 
232  @Override
233  public List<DataResultViewer> getViewers() {
234  return dataResultPanel.getViewers();
235  }
236 
237  private void setCustomMode() {
238  if (customModeName != null) {
239  //putClientProperty("TopComponentAllowDockAnywhere", Boolean.TRUE);
240  Mode mode = WindowManager.getDefault().findMode(customModeName);
241  if (mode != null) {
242  StringBuilder message = new StringBuilder("Found custom mode, setting: "); //NON-NLS
243  message.append(customModeName);
244  logger.log(Level.INFO, message.toString());
245  mode.dockInto(this);
246 
247  } else {
248  StringBuilder message = new StringBuilder("Could not find mode: "); //NON-NLS
249  message.append(customModeName);
250  message.append(", will dock into the default one"); //NON-NLS
251  logger.log(Level.WARNING, message.toString());
252  }
253  }
254  }
255 
256  @Override
257  public void componentOpened() {
258  super.componentOpened();
259  this.dataResultPanel.open();
260  }
261 
262  @Override
263  public void componentClosed() {
264  super.componentClosed();
265  activeComponentIds.remove(this.getName());
266  dataResultPanel.close();
267  }
268 
269  @Override
270  protected String preferredID() {
271  return getName();
272  }
273 
274  @Override
275  public String getPreferredID() {
276  return getName();
277  }
278 
279  @Override
280  public void setNode(Node selectedNode) {
281  dataResultPanel.setNode(selectedNode);
282  }
283 
284  @Override
285  public void setTitle(String title) {
286  setName(title);
287  }
288 
289  @Override
290  public void setPath(String pathText) {
291  dataResultPanel.setPath(pathText);
292  }
293 
294  @Override
295  public boolean isMain() {
296  return isMain;
297  }
298 
299  @Override
300  public boolean canClose() {
301  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
302  }
303 
310  public void resetTabs(Node selectedNode) {
311 
312  dataResultPanel.resetTabs(selectedNode);
313  }
314 
315  public void setSelectedNodes(Node[] selected) {
316  dataResultPanel.setSelectedNodes(selected);
317  }
318 
319  public Node getRootNode() {
320  return dataResultPanel.getRootNode();
321  }
322 
323  void setNumMatches(int matches) {
324  this.dataResultPanel.setNumMatches(matches);
325  }
326 }
static boolean existsCurrentCase()
Definition: Case.java:622
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)
static Logger getLogger(String name)
Definition: Logger.java:131
static void initInstance(String pathText, Node givenNode, int totalMatches, DataResultTopComponent newDataResult)

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