group by library
authorAlexey Kudravtsev <cdr@intellij.com>
Fri, 7 May 2010 11:03:40 +0000 (15:03 +0400)
committerAlexey Kudravtsev <cdr@intellij.com>
Tue, 11 May 2010 06:05:11 +0000 (10:05 +0400)
platform/usageView/src/com/intellij/usages/impl/rules/UsageScopeGroupingRule.java

index 77e667f01aef317d6321736b9d1c82655d57f80e..91ff84983d548a7699c2ed445bf813ca3a1b315f 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.usages.impl.rules;
 
+import com.intellij.openapi.roots.ProjectFileIndex;
 import com.intellij.openapi.roots.ProjectRootManager;
 import com.intellij.openapi.vcs.FileStatus;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -46,29 +47,51 @@ public class UsageScopeGroupingRule implements UsageGroupingRule {
     if (virtualFile == null) {
       return null;
     }
-    boolean isInTest = ProjectRootManager.getInstance(element.getProject()).getFileIndex().isInTestSourceContent(virtualFile);
+    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
+    boolean isInLib = fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile);
+    if (isInLib) return LIBRARY;
+    boolean isInTest = fileIndex.isInTestSourceContent(virtualFile);
     return isInTest ? TEST : PRODUCTION;
   }
 
-  private static final UsageScopeGroup TEST = new UsageScopeGroup(true);
-  private static final UsageScopeGroup PRODUCTION = new UsageScopeGroup(false);
-  private static class UsageScopeGroup implements UsageGroup {
-    private final boolean isTest;
-
-    private UsageScopeGroup(boolean isTest) {
-      this.isTest = isTest;
+  private static final UsageScopeGroup TEST = new UsageScopeGroup(0) {
+    public Icon getIcon(boolean isOpen) {
+      return Icons.TEST_SOURCE_FOLDER;
     }
 
-    public void update() {
+    @NotNull
+    public String getText(UsageView view) {
+      return "Test";
+    }
+  };
+  private static final UsageScopeGroup PRODUCTION = new UsageScopeGroup(1) {
+    public Icon getIcon(boolean isOpen) {
+      return Icons.SOURCE_FOLDERS_ICON ;
     }
 
+    @NotNull
+    public String getText(UsageView view) {
+      return "Production";
+    }
+  };
+  private static final UsageScopeGroup LIBRARY = new UsageScopeGroup(2) {
     public Icon getIcon(boolean isOpen) {
-      return isTest ? Icons.TEST_SOURCE_FOLDER : Icons.SOURCE_FOLDERS_ICON;
+      return Icons.LIBRARY_ICON ;
     }
 
     @NotNull
     public String getText(UsageView view) {
-      return isTest ? "Test" : "Production";
+      return "Library";
+    }
+  };
+  private abstract static class UsageScopeGroup implements UsageGroup {
+    private final int myCode;
+
+    private UsageScopeGroup(int code) {
+      myCode = code;
+    }
+
+    public void update() {
     }
 
     public FileStatus getFileStatus() {
@@ -91,11 +114,11 @@ public class UsageScopeGroupingRule implements UsageGroupingRule {
       if (this == o) return true;
       if (!(o instanceof UsageScopeGroup)) return false;
       final UsageScopeGroup usageTypeGroup = (UsageScopeGroup)o;
-      return isTest == usageTypeGroup.isTest;
+      return myCode == usageTypeGroup.myCode;
     }
 
     public int hashCode() {
-      return isTest ? 0 : 1;
+      return myCode;
     }
   }
 }