// Path: tools.findbugs.codedefects.core/src/org/nbheaven/sqe/tools/findbugs/codedefects/core/FindBugsResult.java
// public enum Mode {
// 
//     CLASS("HINT_VIEW_BY_CLASS", "org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/class.gif") {
// 
//         @Override
//         public Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly) {
//             return result.getInstanceByClass(coreBugsOnly);
//         }
//     },
//     PACKAGE("HINT_VIEW_BY_PACKAGE", "org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/package.gif") {
// 
//         @Override
//         public Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly) {
//             return result.getInstanceByPackage(coreBugsOnly);
//         }
//     },
//     CATEGORY("HINT_VIEW_BY_CATEGORY", "org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/bug.png") {
// 
//         @Override
//         public Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly) {
//             return result.getInstanceByCategory(coreBugsOnly);
//         }
//     },
//     TYPE("HINT_VIEW_BY_CATEGORY", "org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/bug2.png") {
// 
//         @Override
//         public Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly) {
//             return result.getInstanceByType(coreBugsOnly);
//         }
//     };
//     private final String hint;
//     private final Icon icon;
// 
//     Mode(String hint, String iconPath) {
//         this.hint = hint;
//         icon = new ImageIcon(ImageUtilities.loadImage(iconPath));
//     }
// 
//     public String getHint() {
//         return hint;
//     }
// 
//     public Icon getIcon() {
//         return icon;
//     }
// 
//     public abstract Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly);
// }
// 
// Path: tools.findbugs.codedefects.core/src/org/nbheaven/sqe/tools/findbugs/codedefects/core/FindBugsSession.java
// public interface FindBugsSession extends QualitySession {
// 
//     @Override
//     public FindBugsQualityProvider getProvider();
// 
//     @Override
//     public ObservableObjectValue<? extends FindBugsResult> getResultProperty();
// 
//     @Override
//     public FindBugsResult getResult();
// 
//     @Override
//     public FindBugsResult computeResultAndWait();
// 
//     public static FindBugsResult computeResultAndWait(FileObject sourceFile) {
//         return FindBugsSessionImpl.computeResultAndWait(sourceFile);
//     }
// }


import edu.umd.cs.findbugs.BugAnnotation;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.ClassAnnotation;
import edu.umd.cs.findbugs.FieldAnnotation;
import edu.umd.cs.findbugs.MethodAnnotation;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import java.awt.EventQueue;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.swing.Action;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import org.nbheaven.sqe.tools.findbugs.codedefects.core.annotations.BugAnnotationProcessor;
import org.nbheaven.sqe.tools.findbugs.codedefects.core.FindBugsResult.Mode;
import org.nbheaven.sqe.tools.findbugs.codedefects.core.FindBugsSession;
import org.openide.util.RequestProcessor;
import org.openide.util.Utilities;
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
            Object obj = selectedNode.getUserObject();
            if (obj instanceof BugInstance) {
                Action disableDetector = new DisableDetectorAction((BugInstance) obj, session.getProject());
                Action filterBugPattern = new FilterBugPattern((BugInstance) obj);
                return Utilities.actionsToPopup(new Action[]{disableDetector, filterBugPattern}, Utilities.actionsGlobalContext());
            }
        }
        return null;
    }

    /**
     * Dispatch the event to open the source file according to type of
     * annotation
     */
    private static void jumpToSource(final TreePath treePath) {
        if (null == treePath || treePath.getPathCount() == 0) {
            return;
        }
        if (EventQueue.isDispatchThread()) {
            RequestProcessor.getDefault().post(new Runnable() {

                @Override
                public void run() {
                    jumpToSource(treePath);
                }
            });
            return;
        }

// Path: tools.findbugs.codedefects.core/src/org/nbheaven/sqe/tools/findbugs/codedefects/core/FindBugsResult.java
// public enum Mode {
// 
//     CLASS("HINT_VIEW_BY_CLASS", "org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/class.gif") {
// 
//         @Override
//         public Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly) {
//             return result.getInstanceByClass(coreBugsOnly);
//         }
//     },
//     PACKAGE("HINT_VIEW_BY_PACKAGE", "org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/package.gif") {
// 
//         @Override
//         public Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly) {
//             return result.getInstanceByPackage(coreBugsOnly);
//         }
//     },
//     CATEGORY("HINT_VIEW_BY_CATEGORY", "org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/bug.png") {
// 
//         @Override
//         public Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly) {
//             return result.getInstanceByCategory(coreBugsOnly);
//         }
//     },
//     TYPE("HINT_VIEW_BY_CATEGORY", "org/nbheaven/sqe/tools/findbugs/codedefects/core/resources/bug2.png") {
// 
//         @Override
//         public Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly) {
//             return result.getInstanceByType(coreBugsOnly);
//         }
//     };
//     private final String hint;
//     private final Icon icon;
// 
//     Mode(String hint, String iconPath) {
//         this.hint = hint;
//         icon = new ImageIcon(ImageUtilities.loadImage(iconPath));
//     }
// 
//     public String getHint() {
//         return hint;
//     }
// 
//     public Icon getIcon() {
//         return icon;
//     }
// 
//     public abstract Map<?, Collection<BugInstance>> getInstanceList(final FindBugsResult result, boolean coreBugsOnly);
// }
// 
// Path: tools.findbugs.codedefects.core/src/org/nbheaven/sqe/tools/findbugs/codedefects/core/FindBugsSession.java
// public interface FindBugsSession extends QualitySession {
// 
//     @Override
//     public FindBugsQualityProvider getProvider();
// 
//     @Override
//     public ObservableObjectValue<? extends FindBugsResult> getResultProperty();
// 
//     @Override
//     public FindBugsResult getResult();
// 
//     @Override
//     public FindBugsResult computeResultAndWait();
// 
//     public static FindBugsResult computeResultAndWait(FileObject sourceFile) {
//         return FindBugsSessionImpl.computeResultAndWait(sourceFile);
//     }
// }


// Path: tools.findbugs.codedefects.core/src/org/nbheaven/sqe/tools/findbugs/codedefects/core/ui/result/BugTree.java
import edu.umd.cs.findbugs.BugAnnotation;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.ClassAnnotation;
import edu.umd.cs.findbugs.FieldAnnotation;
import edu.umd.cs.findbugs.MethodAnnotation;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import java.awt.EventQueue;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import javax.swing.Action;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import org.nbheaven.sqe.tools.findbugs.codedefects.core.annotations.BugAnnotationProcessor;
import org.nbheaven.sqe.tools.findbugs.codedefects.core.FindBugsResult.Mode;
import org.nbheaven.sqe.tools.findbugs.codedefects.core.FindBugsSession;
import org.openide.util.RequestProcessor;
import org.openide.util.Utilities;

            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
            Object obj = selectedNode.getUserObject();
            if (obj instanceof BugInstance) {
                Action disableDetector = new DisableDetectorAction((BugInstance) obj, session.getProject());
                Action filterBugPattern = new FilterBugPattern((BugInstance) obj);
                return Utilities.actionsToPopup(new Action[]{disableDetector, filterBugPattern}, Utilities.actionsGlobalContext());
            }
        }
        return null;
    }

    /**
     * Dispatch the event to open the source file according to type of
     * annotation
     */
    private static void jumpToSource(final TreePath treePath) {
        if (null == treePath || treePath.getPathCount() == 0) {
            return;
        }
        if (EventQueue.isDispatchThread()) {
            RequestProcessor.getDefault().post(new Runnable() {

                @Override
                public void run() {
                    jumpToSource(treePath);
                }
            });
            return;
        }

        FindBugsSession session = (FindBugsSession) ((DefaultMutableTreeNode) treePath.getPathComponent(0)).getUserObject();