Autopsy  3.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 
39 public class CoreComponentControl {
40 
41  private static final Logger logger = Logger.getLogger(CoreComponentControl.class.getName());
42  private static final String DIRECTORY_TREE = NbBundle.getMessage(CoreComponentControl.class,
43  "CoreComponentControl.CTL_DirectoryTreeTopComponent");
44  private static final String FAVORITES = NbBundle.getMessage(CoreComponentControl.class,
45  "CoreComponentControl.CTL_FavoritesTopComponent");
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 m = WindowManager.getDefault().findMode("explorer"); //NON-NLS
59  if (m != null) {
60  m.dockInto(explorerWin); // redock into the explorer mode
61  } else {
62  logger.log(Level.WARNING, "Could not find explorer mode and dock explorer window"); //NON-NLS
63  }
64  explorerWin.open(); // open that top component
65  }
66 
67  // find the data content top component
68  TopComponent contentWin = DataContentTopComponent.findInstance();
69  Mode m = WindowManager.getDefault().findMode("output"); //NON-NLS
70  if (m != null) {
71  m.dockInto(contentWin); // redock into the output mode
72  } else {
73  logger.log(Level.WARNING, "Could not find output mode and dock content window"); //NON-NLS
74  }
75 
76  contentWin.open(); // open that top component
77  }
78 
87  public static void closeCoreWindows() {
88  WindowManager wm = WindowManager.getDefault();
89  Set<? extends Mode> modes = wm.getModes();
90  Iterator<? extends Mode> iter = wm.getModes().iterator();
91 
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 Logger getLogger(String name)
Definition: Logger.java:131

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.