/*
 * 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.util.ArrayList;
import java.util.List;
import javax.swing.Action;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ProxyLookup;
import org.sleuthkit.datamodel.Content;

/**
 * This class sets the actions for the nodes in the directory tree and creates
 * the children filter so that files and such are hidden from the tree. 
 *
 */
class DirectoryTreeFilterNode extends FilterNode {

    private static final Action collapseAll = new CollapseAction("Collapse All");

    /** the constructor */
    DirectoryTreeFilterNode(Node arg) {
        super(arg, DirectoryTreeFilterChildren.createInstance(arg),
                new ProxyLookup(Lookups.singleton(new OriginalNode(arg)),
                arg.getLookup()));
    }

    /**
     * Right click action for the nodes in the directory tree.
     *
     * @param popup
     * @return
     */
    @Override
    public Action[] getActions(boolean popup) {
        List<Action> actions = new ArrayList<Action>();

        Content content = this.getLookup().lookup(Content.class);
        if (content != null) {
            actions.addAll(DirectoryTreeFilterNode.getActions(content));
            actions.add(collapseAll);
        }

        return actions.toArray(new Action[actions.size()]);
    }

    private static List<Action> getActions(Content c) {
        List<Action> actions = new ArrayList<Action>();

        actions.addAll(ShowDetailActionVisitor.getActions(c));

        return actions;
    }

    static class OriginalNode {

        private Node original;

        private OriginalNode(Node original) {
            this.original = original;
        }

        Node getNode() {
            return original;
        }
    }
}

@@ -990,16 +990,58 @@
 Content;
+%0Aimport org.sleuthkit.datamodel.Directory;
 %0A%0A/**%0A *
@@ -1970,24 +1970,30 @@
 lterNode.get
+Detail
 Actions(cont
@@ -1995,24 +1995,24 @@
 (content));%0A
-
             
@@ -2037,16 +2037,252 @@
 seAll);%0A
+            %0A            Directory dir = this.getLookup().lookup(Directory.class);%0A            if (dir != null) %7B%0A                actions.add(new ExtractAction(%22Extract Directory%22,%0A                        getOriginal()));%0A            %7D%0A
         
@@ -2347,24 +2347,24 @@
 )%5D);%0A    %7D%0A%0A
-
     private 
@@ -2382,24 +2382,30 @@
 %3CAction%3E get
+Detail
 Actions(Cont

add "Extract Directory" action to DirectoryTree