Autopsy  4.1
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 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.Iterator;
23 import java.util.Set;
24 import java.util.logging.Level;
25 
26 import org.openide.util.NbBundle;
28 import org.openide.util.Lookup;
29 import org.openide.windows.Mode;
30 import org.openide.windows.TopComponent;
31 import org.openide.windows.WindowManager;
33 
40 public class CoreComponentControl {
41 
42  private static final Logger logger = Logger.getLogger(CoreComponentControl.class.getName());
43  private static final String DIRECTORY_TREE = NbBundle.getMessage(CoreComponentControl.class,
44  "CoreComponentControl.CTL_DirectoryTreeTopComponent");
45  private static final String FAVORITES = NbBundle.getMessage(CoreComponentControl.class,
46  "CoreComponentControl.CTL_FavoritesTopComponent");
47 
52  public static void openCoreWindows() {
53  // TODO: there has to be a better way to do this.
54 
55  // find the data explorer top components
56  Collection<? extends DataExplorer> dataExplorers = Lookup.getDefault().lookupAll(DataExplorer.class);
57  for (DataExplorer de : dataExplorers) {
58  TopComponent explorerWin = de.getTopComponent();
59  Mode m = WindowManager.getDefault().findMode("explorer"); //NON-NLS
60  if (m != null) {
61  m.dockInto(explorerWin); // redock into the explorer mode
62  } else {
63  logger.log(Level.WARNING, "Could not find explorer mode and dock explorer window"); //NON-NLS
64  }
65  explorerWin.open(); // open that top component
66  }
67 
68  // find the data content top component
69  TopComponent contentWin = DataContentTopComponent.findInstance();
70  Mode m = WindowManager.getDefault().findMode("output"); //NON-NLS
71  if (m != null) {
72  m.dockInto(contentWin); // redock into the output mode
73  } else {
74  logger.log(Level.WARNING, "Could not find output mode and dock content window"); //NON-NLS
75  }
76 
77  contentWin.open(); // open that top component
78  }
79 
88  public static void closeCoreWindows() {
89  WindowManager wm = WindowManager.getDefault();
90  Set<? extends Mode> modes = wm.getModes();
91  Iterator<? extends Mode> iter = wm.getModes().iterator();
92 
93  TopComponent directoryTree = null;
94  TopComponent favorites = null;
95  String tcName = "";
96  while (iter.hasNext()) {
97  Mode mode = iter.next();
98  for (TopComponent tc : mode.getTopComponents()) {
99  tcName = tc.getName();
100  if (tcName == null) {
101  logger.log(Level.INFO, "tcName was null"); //NON-NLS
102  tcName = "";
103  }
104  // switch requires constant strings, so converted to if/else.
105  if (DIRECTORY_TREE.equals(tcName)) {
106  directoryTree = tc;
107  } else if (FAVORITES.equals(tcName)) {
108  favorites = tc;
109  } else {
110  tc.close();
111  }
112  }
113  }
114 
115  if (directoryTree != null) {
116  directoryTree.close();
117  }
118  if (favorites != null) {
119  favorites.close();
120  }
121  }
122 }
static synchronized DataContentTopComponent findInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

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