/*
 * 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;
// ATTENTION MR. PROGRAMMER:
// DO NOT COMMIT THIS CODE. IT IS NOT FOR PUBLIC CONSUMPTION
// THANK YOU
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
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.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.ingest.IngestDialog;
import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.Directory;
import org.sleuthkit.datamodel.Image;
import org.sleuthkit.datamodel.SleuthkitCase;

/**
 * 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, boolean createChildren) {
        super(arg, DirectoryTreeFilterChildren.createInstance(arg, createChildren),
                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 c = this.getLookup().lookup(Content.class);
        if (c != null) {
            actions.addAll(DirectoryTreeFilterNode.getDetailActions(c));
            actions.add(collapseAll);

            Directory dir = this.getLookup().lookup(Directory.class);
            if (dir != null) {
                actions.add(new ExtractAction("Extract Directory",
                        getOriginal()));
            }
            final Image img = this.getLookup().lookup(Image.class);
            if (img != null) {
                actions.add(new AbstractAction("Restart Ingest Modules") {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final IngestDialog ingestDialog = new IngestDialog();
                        ingestDialog.setImage(img);
                        ingestDialog.display();
                    }
                });
            }
        }
        actions.add(new DeleteArtifactsAndAttributes());
        return actions.toArray(new Action[actions.size()]);
    }

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

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

        return actions;
    }

    // ATTENTION MR. PROGRAMMER:
    // DO NOT COMMIT THIS CODE. IT IS NOT FOR PUBLIC CONSUMPTION
    // THANK YOU
    private class DeleteArtifactsAndAttributes extends AbstractAction {

        DeleteArtifactsAndAttributes() {
            super("Delete Artifacts and Attributes");
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
            try {
                String query = "delete from blackboard_artifacts";
                skCase.runQuery(query);
            } catch (SQLException ex) {
                Logger.getLogger(DirectoryTreeFilterNode.class.getName()).log(Level.INFO, "No resultset returned from query 1");
            }
            try {
                String query = "delete from blackboard_attributes";
                skCase.runQuery(query);
            } catch (SQLException ex) {
                Logger.getLogger(DirectoryTreeFilterNode.class.getName()).log(Level.INFO, "No resultset returned from query 2");
            }

            IngestManager.fireServiceEvent(IngestManager.SERVICE_HAS_DATA_EVT, NAME);

        }
    }
}

class OriginalNode {

    private Node original;

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

    Node getNode() {
        return original;
    }
}
@@ -760,141 +760,8 @@
 nt;%0A
-// ATTENTION MR. PROGRAMMER:%0A// DO NOT COMMIT THIS CODE. IT IS NOT FOR PUBLIC CONSUMPTION%0A// THANK YOU%0Aimport java.sql.SQLException;%0A
 impo
@@ -1090,54 +1090,8 @@
 up;%0A
-import org.sleuthkit.autopsy.casemodule.Case;%0A
 impo
@@ -1140,59 +1140,8 @@
 og;%0A
-import org.sleuthkit.autopsy.ingest.IngestManager;%0A
 impo
@@ -1259,54 +1259,8 @@
 age;
-%0Aimport org.sleuthkit.datamodel.SleuthkitCase;
 %0A%0A/*
@@ -3024,65 +3024,8 @@
   %7D%0A
-        actions.add(new DeleteArtifactsAndAttributes());%0A
     
@@ -3305,1171 +3305,8 @@
  %7D%0A%0A
-    // ATTENTION MR. PROGRAMMER:%0A    // DO NOT COMMIT THIS CODE. IT IS NOT FOR PUBLIC CONSUMPTION%0A    // THANK YOU%0A    private class DeleteArtifactsAndAttributes extends AbstractAction %7B%0A%0A        DeleteArtifactsAndAttributes() %7B%0A            super(%22Delete Artifacts and Attributes%22);%0A        %7D%0A%0A        @Override%0A        public void actionPerformed(ActionEvent e) %7B%0A            SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();%0A            try %7B%0A                String query = %22delete from blackboard_artifacts%22;%0A                skCase.runQuery(query);%0A            %7D catch (SQLException ex) %7B%0A                Logger.getLogger(DirectoryTreeFilterNode.class.getName()).log(Level.INFO, %22No resultset returned from query 1%22);%0A            %7D%0A            try %7B%0A                String query = %22delete from blackboard_attributes%22;%0A                skCase.runQuery(query);%0A            %7D catch (SQLException ex) %7B%0A                Logger.getLogger(DirectoryTreeFilterNode.class.getName()).log(Level.INFO, %22No resultset returned from query 2%22);%0A            %7D%0A%0A            IngestManager.fireServiceEvent(IngestManager.SERVICE_HAS_DATA_EVT, NAME);%0A%0A        %7D%0A    %7D%0A
 %7D%0A%0Ac

undo stupid