/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011-2017 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 org.openide.nodes.Node;
import org.openide.util.NbBundle;
import static org.sleuthkit.autopsy.directorytree.Bundle.*;

@NbBundle.Messages({"SelectionContext.dataSources=Data Sources",
    "SelectionContext.views=Views"})
enum SelectionContext {
    DATA_SOURCES(SelectionContext_dataSources()),
    VIEWS(SelectionContext_views()),
    OTHER("");  // Subnode of another node.

    private final String displayName;

  private  SelectionContext(String displayName) {
        this.displayName = displayName;
    }

    public static SelectionContext getContextFromName(String name) {
        if (name.equals(DATA_SOURCES.getName())) {
            return DATA_SOURCES;
        } else if (name.equals(VIEWS.getName())) {
            return VIEWS;
        } else {
            return OTHER;
        }
    }

    private String getName() {
        return displayName;
    }

    /**
     * Get the selection context of a Node in the DirectoryTree.
     *
     * @param n
     *
     * @return
     */
    public static SelectionContext getSelectionContext(Node n) {
        if (n == null || n.getParentNode() == null) {
            // Parent of root node or root node. Occurs during case open / close.
            return SelectionContext.OTHER;
        } else if (n.getParentNode().getParentNode() == null) {
            // One level below root node. Should be one of DataSources, Views, or Results
            return SelectionContext.getContextFromName(n.getDisplayName());
        } else {
            return getSelectionContext(n.getParentNode());
        }
    }

}

@@ -917,16 +917,74 @@
 urces%22,%0A
+    %22SelectionContext.dataSourceFiles=Data Source Files%22,%0A
     %22Sel
@@ -1012,16 +1012,16 @@
 iews%22%7D)%0A
-
 enum Sel
@@ -1136,16 +1136,75 @@
 THER(%22%22)
+,%0A    DATA_SOURCE_FILES(SelectionContext_dataSourceFiles())
 ;  // Su
@@ -1471,32 +1471,76 @@
 URCES.getName())
+ %7C%7C name.equals(DATA_SOURCE_FILES.getName())
 ) %7B%0A            
@@ -2359,24 +2359,24 @@
 layName());%0A
-
         %7D el
@@ -2372,32 +2372,580 @@
        %7D else %7B%0A
+            // In Group by Data Source mode, the node under root is the data source name, and%0A            // under that is Data Source Files, Views, or Results. Before moving up the tree, check%0A            // if one of those applies%0A            if (n.getParentNode().getParentNode().getParentNode() == null) %7B%0A                SelectionContext context = SelectionContext.getContextFromName(n.getDisplayName());%0A                if (context != SelectionContext.OTHER) %7B%0A                    return context;%0A                %7D%0A            %7D%0A            %0A
             retu

Make the selection context work in group by data source mode