/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sleuthkit.autopsy.corecomponentinterfaces;

import java.util.Collection;
import java.util.Iterator;
import org.openide.util.Lookup;
import org.openide.windows.Mode;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;

/**
 * Responsible for opening and closing the core windows when a case is opened and closed.
 *
 * @author jantonius
 */
public class CoreComponentControl {

    /**
     * Opens all TopComponent windows that are needed ({@link DataExplorer}, {@link DataResult}, and
     * {@link DataContent})
     */
    public static void openCoreWindows() {
        // TODO: there has to be a better way to do this.

        // find the data explorer top components
        Collection<? extends DataExplorer> dataExplorers = Lookup.getDefault().lookupAll(DataExplorer.class);
        for (DataExplorer de : dataExplorers) {
            TopComponent explorerWin = de.getTopComponent();
            Mode m = WindowManager.getDefault().findMode("explorer");
            m.dockInto(explorerWin); // redock into the explorer mode
            explorerWin.open(); // open that top component
        }

        // find the data content top component
        DataContent dc = Lookup.getDefault().lookup(DataContent.class);
        TopComponent contentWin = dc.getTopComponent();
        Mode m = WindowManager.getDefault().findMode("output");
        m.dockInto(contentWin); // redock into the output mode
        contentWin.open(); // open that top component
    }

    /**
     * Closes all TopComponent windows that needed ({@link DataExplorer}, {@link DataResult}, and
     * {@link DataContent})
     */
    public static void closeCoreWindows() {
        WindowManager wm = WindowManager.getDefault();
        Iterator<? extends Mode> iter = wm.getModes().iterator();

        while (iter.hasNext()) {
            Mode mode = iter.next();
            for (TopComponent tc : mode.getTopComponents()) {
                tc.close();
            }
        }
    }
}

@@ -675,17 +675,16 @@
 se.%0A */%0A
-%0A
 package 
@@ -787,16 +787,81 @@
 erator;%0A
+import java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A
 import o
@@ -1160,16 +1160,114 @@
 trol %7B%0A%0A
+    private static final Logger logger = Logger.getLogger(CoreComponentControl.class.getName());%0A%0A
     /**%0A
@@ -1839,24 +1839,57 @@
 explorer%22);%0A
+            if (m != null) %7B%0A    
             
@@ -1942,24 +1942,159 @@
 plorer mode%0A
+            %7D else %7B%0A                logger.log(Level.WARNING, %22Could not find explorer mode and dock explorer window%22);%0A            %7D%0A
             
@@ -2386,24 +2386,53 @@
 (%22output%22);%0A
+        if (m != null) %7B%0A    
         m.do
@@ -2478,24 +2478,145 @@
 output mode%0A
+        %7D else %7B%0A            logger.log(Level.WARNING, %22Could not find output mode and dock content window%22);%0A        %7D%0A%0A
         cont

Add some checks when locating modes to open windows