CPP-13710 - commit only current document if there are no processors that can access...
[idea/community.git] / java / idea-ui / src / com / intellij / openapi / roots / ui / configuration / projectRoot / daemon / ProjectStructureProblemsHolderImpl.java
1 package com.intellij.openapi.roots.ui.configuration.projectRoot.daemon;
2
3 import com.intellij.util.SmartList;
4 import com.intellij.xml.util.XmlStringUtil;
5 import org.jetbrains.annotations.Nls;
6 import org.jetbrains.annotations.NotNull;
7 import org.jetbrains.annotations.Nullable;
8
9 import java.util.Collections;
10 import java.util.List;
11
12 public class ProjectStructureProblemsHolderImpl implements ProjectStructureProblemsHolder {
13   private List<ProjectStructureProblemDescription> myProblemDescriptions;
14
15   @Override
16   public void registerProblem(@NotNull @Nls(capitalization = Nls.Capitalization.Sentence) String message, @Nullable String description,
17                               @NotNull ProjectStructureProblemType problemType,
18                               @NotNull PlaceInProjectStructure place,
19                               @Nullable ConfigurationErrorQuickFix fix) {
20     final List<ConfigurationErrorQuickFix> fixes = fix != null ? Collections.singletonList(fix) : Collections.emptyList();
21     registerProblem(new ProjectStructureProblemDescription(message, description, place, problemType, fixes));
22   }
23
24   @Override
25   public void registerProblem(final @NotNull ProjectStructureProblemDescription description) {
26     if (myProblemDescriptions == null) {
27       myProblemDescriptions = new SmartList<>();
28     }
29     myProblemDescriptions.add(description);
30   }
31
32   public String composeTooltipMessage() {
33     final StringBuilder buf = new StringBuilder();
34     buf.append("<html><body>");
35     if (myProblemDescriptions != null) {
36       int problems = 0;
37       for (ProjectStructureProblemDescription problemDescription : myProblemDescriptions) {
38         buf.append(XmlStringUtil.convertToHtmlContent(problemDescription.getMessage(false))).append("<br>");
39         problems++;
40         if (problems >= 10 && myProblemDescriptions.size() > 12) {
41           buf.append(myProblemDescriptions.size() - problems).append(" more problems...<br>");
42           break;
43         }
44       }
45     }
46     buf.append("</body></html>");
47     return buf.toString();
48   }
49
50   public boolean containsProblems() {
51     return myProblemDescriptions != null && !myProblemDescriptions.isEmpty();
52   }
53
54   public boolean containsProblems(final ProjectStructureProblemType.Severity severity) {
55     if (myProblemDescriptions != null) {
56       for (ProjectStructureProblemDescription description : myProblemDescriptions) {
57         if (description.getSeverity() == severity) {
58           return true;
59         }
60       }
61     }
62     return false;
63   }
64
65   public void removeProblem(@NotNull ProjectStructureProblemDescription description) {
66     if (myProblemDescriptions != null) {
67       myProblemDescriptions.remove(description);
68     }
69   }
70
71   @Nullable
72   public List<ProjectStructureProblemDescription> getProblemDescriptions() {
73     return myProblemDescriptions;
74   }
75 }