Autopsy  4.17.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;
30 
36 final public class CoreComponentControl {
37 
38  private static final Logger logger = Logger.getLogger(CoreComponentControl.class.getName());
39  @NbBundle.Messages("CoreComponentControl.CTL_DirectoryTreeTopComponent=Directory Tree")
40  private static final String DIRECTORY_TREE = Bundle.CoreComponentControl_CTL_DirectoryTreeTopComponent();
41  @NbBundle.Messages("CoreComponentControl.CTL_FavoritesTopComponent=Favorites")
42  private static final String FAVORITES = Bundle.CoreComponentControl_CTL_FavoritesTopComponent();
43 
45  }
46 
51  public static void openCoreWindows() {
52  // TODO: there has to be a better way to do this.
53 
54  // find the data explorer top components
55  Collection<? extends DataExplorer> dataExplorers = Lookup.getDefault().lookupAll(DataExplorer.class);
56  for (DataExplorer de : dataExplorers) {
57  TopComponent explorerWin = de.getTopComponent();
58  Mode explorerMode = WindowManager.getDefault().findMode("explorer"); //NON-NLS
59  if (explorerMode == null) {
60  logger.log(Level.WARNING, "Could not find explorer mode and dock explorer window"); //NON-NLS
61  } else {
62  explorerMode.dockInto(explorerWin); // redock into the explorer mode
63  }
64  explorerWin.open(); // open that top component
65  }
66 
67  // find the data content top component
68  TopComponent contentWin = DataContentTopComponent.findInstance();
69  Mode outputMode = WindowManager.getDefault().findMode("output"); //NON-NLS
70  if (outputMode == null) {
71  logger.log(Level.WARNING, "Could not find output mode and dock content window"); //NON-NLS
72  } else {
73  outputMode.dockInto(contentWin); // redock into the output mode
74  }
75 
76  contentWin.open(); // open that top component
77  }
78 
87  public static void closeCoreWindows() {
88  TopComponent directoryTree = null;
89  TopComponent favorites = null;
90  final WindowManager windowManager = WindowManager.getDefault();
91 
92  // Set the UI selections to null before closing the top components.
93  // Otherwise it may experience errors trying to load data for the closed case.
94  for (Mode mode : windowManager.getModes()) {
95  for (TopComponent tc : windowManager.getOpenedTopComponents(mode)) {
96  if(tc instanceof DataContent) {
97  ((DataContent) tc).setNode(null);
98  } else if(tc instanceof DataResult) {
99  ((DataResult) tc).setNode(null);
100  }
101  }
102  }
103 
104  for (Mode mode : windowManager.getModes()) {
105 
106  for (TopComponent tc : windowManager.getOpenedTopComponents(mode)) {
107  String tcName = tc.getName();
108 
109  if (tcName == null) {
110  logger.log(Level.INFO, "tcName was null"); //NON-NLS
111  }
112  // switch requires constant strings, so converted to if/else.
113  if (DIRECTORY_TREE.equals(tcName)) {
114  directoryTree = tc;
115  } else if (FAVORITES.equals(tcName)) {
116  favorites = tc;
117  } else {
118  tc.close();
119  }
120  }
121  }
122 
123  if (directoryTree != null) {
124  directoryTree.close();
125  }
126  if (favorites != null) {
127  favorites.close();
128  }
129  }
130 }
static synchronized DataContentTopComponent findInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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