Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CoreComponentControl.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-18 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.corecomponentinterfaces;
20 
21 import java.util.Collection;
22 import java.util.logging.Level;
23 import org.openide.util.Lookup;
24 import org.openide.util.NbBundle;
25 import org.openide.windows.Mode;
26 import org.openide.windows.TopComponent;
27 import org.openide.windows.WindowManager;
31 
37 final public class CoreComponentControl {
38 
39  private static final Logger logger = Logger.getLogger(CoreComponentControl.class.getName());
40  @NbBundle.Messages("CoreComponentControl.CTL_DirectoryTreeTopComponent=Directory Tree")
41  private static final String DIRECTORY_TREE = Bundle.CoreComponentControl_CTL_DirectoryTreeTopComponent();
42  @NbBundle.Messages("CoreComponentControl.CTL_FavoritesTopComponent=Favorites")
43  private static final String FAVORITES = Bundle.CoreComponentControl_CTL_FavoritesTopComponent();
44 
46  }
47 
52  public static void openCoreWindows() {
53  // preload UI components (JIRA-7345). This only takes place the first time Autopsy opens a case.
55 
56  // find the data explorer top components
57  Collection<? extends DataExplorer> dataExplorers = Lookup.getDefault().lookupAll(DataExplorer.class);
58  for (DataExplorer de : dataExplorers) {
59  TopComponent explorerWin = de.getTopComponent();
60  Mode explorerMode = WindowManager.getDefault().findMode("explorer"); //NON-NLS
61  if (explorerMode == null) {
62  logger.log(Level.WARNING, "Could not find explorer mode and dock explorer window"); //NON-NLS
63  } else {
64  explorerMode.dockInto(explorerWin); // redock into the explorer mode
65  }
66  explorerWin.open(); // open that top component
67  }
68 
69  // find the data content top component
70  TopComponent contentWin = DataContentTopComponent.findInstance();
71  Mode outputMode = WindowManager.getDefault().findMode("output"); //NON-NLS
72  if (outputMode == null) {
73  logger.log(Level.WARNING, "Could not find output mode and dock content window"); //NON-NLS
74  } else {
75  outputMode.dockInto(contentWin); // redock into the output mode
76  }
77 
78  contentWin.open(); // open that top component
79  }
80 
89  public static void closeCoreWindows() {
90  TopComponent directoryTree = null;
91  TopComponent favorites = null;
92  final WindowManager windowManager = WindowManager.getDefault();
93 
94  // Set the UI selections to null before closing the top components.
95  // Otherwise it may experience errors trying to load data for the closed case.
96  for (Mode mode : windowManager.getModes()) {
97  for (TopComponent tc : windowManager.getOpenedTopComponents(mode)) {
98  if(tc instanceof DataContent) {
99  ((DataContent) tc).setNode(null);
100  } else if(tc instanceof DataResult) {
101  ((DataResult) tc).setNode(null);
102  }
103  }
104  }
105 
106  for (Mode mode : windowManager.getModes()) {
107 
108  for (TopComponent tc : windowManager.getOpenedTopComponents(mode)) {
109  String tcName = tc.getName();
110 
111  if (tcName == null) {
112  logger.log(Level.INFO, "tcName was null"); //NON-NLS
113  }
114  // switch requires constant strings, so converted to if/else.
115  if (DIRECTORY_TREE.equals(tcName)) {
116  directoryTree = tc;
117  } else if (FAVORITES.equals(tcName)) {
118  favorites = tc;
119  } else {
120  tc.close();
121  }
122  }
123  }
124 
125  if (directoryTree != null) {
126  directoryTree.close();
127  }
128  if (favorites != null) {
129  favorites.close();
130  }
131  }
132 }
static synchronized DataContentTopComponent findInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static synchronized DirectoryTreeTopComponent findInstance()

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.