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

import org.sleuthkit.autopsy.datamodel.ImageNode;
import org.sleuthkit.autopsy.datamodel.VolumeNode;
import org.sleuthkit.autopsy.datamodel.FileNode;
import org.sleuthkit.autopsy.datamodel.DirectoryNode;
import javax.swing.Action;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.sleuthkit.autopsy.datamodel.ContentUtils;
import org.sleuthkit.autopsy.directorytree.ChangeViewAction;
import org.sleuthkit.datamodel.Content;

/**
 * This class wraps nodes as they are passed to the DataResult viewers.  It 
 * defines the actions that the node should have. 
 */
public class DataResultFilterNode extends FilterNode {

    private Node currentNode;

    /** the constructor */
    public DataResultFilterNode(Node arg) {
        super(arg, new DataResultFilterChildren(arg));
        this.currentNode = arg;
    }

    /**
     * Right click action for the nodes that we want to pass to the directory
     * table and the output view.
     *
     * @param popup
     * @return actions
     */
    @Override
    public Action[] getActions(boolean popup) {
        // right click action(s) for image node
        if (this.currentNode instanceof ImageNode) {
            return new Action[]{};
        } // right click action(s) for volume node
        else if (this.currentNode instanceof VolumeNode) {
            return new Action[]{};
        } // right click action(s) for directory node
        else if (this.currentNode instanceof DirectoryNode) {
            return new Action[]{
                        new ChangeViewAction("View", 0, currentNode),
                        new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(currentNode.getLookup().lookup(Content.class)))
                    };
        } // right click action(s) for the file node
        else if (this.currentNode instanceof FileNode) {
            return new Action[]{
                        // TODO: ContentNode fix - reimplement ExtractAction
                        // new ExtractAction("Extract", (FileNode) this.currentNode),
                        new ChangeViewAction("View", 0, currentNode),
                        new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(currentNode.getLookup().lookup(Content.class)))
                    };
        } else {
            return new Action[]{};
        }
    }

    /**
     * Double click action for the nodes that we want to pass to the directory
     * table and the output view.
     *
     * @return action
     */
    @Override
    public Action getPreferredAction() {
        return null;
    }
}

@@ -722,212 +722,8 @@
 h;%0A%0A
-import org.sleuthkit.autopsy.datamodel.ImageNode;%0Aimport org.sleuthkit.autopsy.datamodel.VolumeNode;%0Aimport org.sleuthkit.autopsy.datamodel.FileNode;%0Aimport org.sleuthkit.autopsy.datamodel.DirectoryNode;%0A
 impo
@@ -948,33 +948,217 @@
 euthkit.
-datamodel.Content
+autopsy.directorytree.ExtractAction;%0Aimport org.sleuthkit.datamodel.Content;%0Aimport org.sleuthkit.datamodel.ContentVisitor;%0Aimport org.sleuthkit.datamodel.Directory;%0Aimport org.sleuthkit.datamodel.File
 ;%0A%0A/**%0A 
@@ -1348,38 +1348,8 @@
  %7B%0A%0A
-    private Node currentNode;%0A
 %0A   
@@ -1475,40 +1475,8 @@
 ));%0A
-        this.currentNode = arg;%0A
     
@@ -1730,277 +1730,236 @@
     
-// right click action(s) for image node%0A        if (this.currentNode instanceof ImageNode) %7B%0A            return 
+%0A       Content content = getOriginal().getLookup().lookup(Content.class);%0A       return content.accept(
 new 
+Get
 Action
-%5B%5D%7B%7D
+ContentVisitor())
 ;%0A    
+%7D%0A
     
-%7D // right click action(s) for volume node%0A        else if (this.currentNode instanceof VolumeNode) %7B%0A            return new 
+%0A    private class GetActionContentVisitor extends ContentVisitor.Default%3C
 Action%5B%5D
 %7B%7D;%0A
@@ -1946,35 +1946,35 @@
 Default%3CAction%5B%5D
-%7B%7D;
+%3E %7B
 %0A        %7D // ri
@@ -1970,99 +1970,48 @@
     
-%7D // right click action(s) for directory node%0A        else if (this.currentNode instanceof 
+@Override%0A        public Action%5B%5D visit(
 Dire
@@ -2015,20 +2015,20 @@
 irectory
-Node
+ dir
 ) %7B%0A    
@@ -2068,32 +2068,24 @@
             
- 
-       
 new ChangeVi
@@ -2104,38 +2104,32 @@
 ew%22, 0, 
-currentNode),%0A        
+getOriginal()),%0A
         
@@ -2219,393 +2219,200 @@
 ath(
-currentNode.getLookup().lookup(Content.class)))%0A                    %7D;%0A        %7D // right click action(s) for the file node%0A        else if (this.currentNode instanceof FileNode) %7B%0A            return new Action%5B%5D%7B%0A                        // TODO: ContentNode fix - reimplement ExtractAction%0A                        // new ExtractAction(%22Extract%22, (FileNode) this.currentNode),%0A        
+dir))%0A            %7D;%0A        %7D%0A        %0A        @Override%0A        public Action%5B%5D visit(File f) %7B%0A            return new Action%5B%5D%7B%0A                new ExtractAction(%22Extract%22, getOriginal()),%0A
     
@@ -2459,30 +2459,24 @@
  0, 
-currentNode),%0A        
+getOriginal()),%0A
     
@@ -2570,53 +2570,9 @@
 ath(
-currentNode.getLookup().lookup(Content.class)
+f
 ))%0A 
@@ -2574,32 +2574,35 @@
 f))%0A            
+%7D;%0A
         %7D;%0A     
@@ -2598,24 +2598,82 @@
    %7D
-;%0A        %7D else
+%0A%0A        @Override%0A        protected Action%5B%5D defaultVisit(Content cntnt)
  %7B%0A 
@@ -2717,24 +2717,29 @@
      %7D%0A    %7D
+%0A    
 %0A%0A    /**%0A  

Clean up FileSearch DataResultFilterNode