IDEA-131429 Warning tooltips overlap scrollbar
[idea/community.git] / plugins / coverage-common / src / com / intellij / coverage / CoverageProjectViewDirectoryNodeDecorator.java
1 package com.intellij.coverage;
2
3 import com.intellij.ide.projectView.PresentationData;
4 import com.intellij.ide.projectView.ProjectViewNode;
5 import com.intellij.packageDependencies.ui.PackageDependenciesNode;
6 import com.intellij.psi.PsiDirectory;
7 import com.intellij.psi.PsiElement;
8 import com.intellij.psi.PsiFile;
9 import com.intellij.psi.SmartPsiElementPointer;
10 import com.intellij.ui.ColoredTreeCellRenderer;
11
12 /**
13  * @author yole
14  */
15 public class CoverageProjectViewDirectoryNodeDecorator extends AbstractCoverageProjectViewNodeDecorator {
16   public CoverageProjectViewDirectoryNodeDecorator(final CoverageDataManager coverageDataManager) {
17     super(coverageDataManager);
18   }
19
20   public void decorate(PackageDependenciesNode node, ColoredTreeCellRenderer cellRenderer) {
21     final PsiElement element = node.getPsiElement();
22     if (element == null || !element.isValid()) {
23       return;
24     }
25
26     final CoverageDataManager manager = getCoverageDataManager();
27     final CoverageSuitesBundle currentSuite = manager.getCurrentSuitesBundle();
28     final CoverageAnnotator coverageAnnotator = currentSuite != null ? currentSuite.getAnnotator(element.getProject()) : null;
29     if (coverageAnnotator == null) {
30       // N/A
31       return;
32     }
33
34     if (element instanceof PsiDirectory) {
35       final String informationString = coverageAnnotator.getDirCoverageInformationString((PsiDirectory) element, currentSuite, manager);
36       if (informationString != null) {
37         appendCoverageInfo(cellRenderer, informationString);
38       }
39     }
40   }
41
42   public void decorate(ProjectViewNode node, PresentationData data) {
43     final CoverageDataManager manager = getCoverageDataManager();
44     final CoverageSuitesBundle currentSuite = manager.getCurrentSuitesBundle();
45     final CoverageAnnotator coverageAnnotator = currentSuite != null ? currentSuite.getAnnotator(node.getProject())
46                                                                      : null;
47     if (coverageAnnotator == null) {
48       // N/A
49       return;
50     }
51
52     final Object value = node.getValue();
53     PsiElement element = null;
54     if (value instanceof PsiElement) {
55       element = (PsiElement)value;
56     }
57     else if (value instanceof SmartPsiElementPointer) {
58       element = ((SmartPsiElementPointer)value).getElement();
59     }
60
61     String informationString = null;
62     if (element instanceof PsiDirectory) {
63       informationString = coverageAnnotator.getDirCoverageInformationString((PsiDirectory)element, currentSuite, manager);
64     } else if (element instanceof PsiFile) {
65       informationString = coverageAnnotator.getFileCoverageInformationString((PsiFile)element, currentSuite, manager);
66     }
67
68     if (informationString != null) {
69       data.setLocationString(informationString);
70     }
71   }
72
73 }