/*
 * 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.directorytree;

import java.awt.event.ActionEvent;
import java.util.logging.Level;
import javax.swing.AbstractAction;
import javax.swing.SwingUtilities;
import org.openide.nodes.Node;
import org.openide.windows.Mode;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.corecomponents.DataContentTopComponent;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.TskCoreException;

/**
 * Opens new ContentViewer pane in a detached window
 */
public class NewWindowViewAction extends AbstractAction{
    
    private static Logger logger = Logger.getLogger(NewWindowViewAction.class.getName());

    private Node contentNode ;

    public NewWindowViewAction(String title, Node contentNode){
        super(title);
        this.contentNode = contentNode;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Logger.noteAction(this.getClass());
        
        String name = "DataContent";
        String s = contentNode.getLookup().lookup(String.class);
        if (s != null) {
            name = s;
        } else {
            Content c = contentNode.getLookup().lookup(Content.class);
            if (c != null) {
                try {
                    name = c.getUniquePath();
                } catch (TskCoreException ex) {
                    logger.log(Level.SEVERE, "Except while calling Content.getUniquePath() on " + c);
                }
            }
        }

        final DataContentTopComponent dctc = DataContentTopComponent.createUndocked(name, null);

        Mode m = WindowManager.getDefault().findMode("outputFloat");
        m.dockInto(dctc);
        dctc.open();
        
        // Queue setting the node on the EDT thread to be done later so the dctc
        // can completely initialize.
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                dctc.setNode(contentNode);
            }
        });
    }

    

}

@@ -2680,24 +2680,94 @@
 ntentNode);%0A
+                dctc.toFront();%0A                dctc.requestActive();%0A
             

Bring the floating content viewer to the front when the 'View in new window' action is called.