provided warnings in dom controls
[fedora-idea.git] / source / com / intellij / util / xml / tree / BaseDomElementNode.java
blobc3cc0d9dc9aafc1f451b2762e3d54e1f428136ef
1 package com.intellij.util.xml.tree;
3 import com.intellij.openapi.util.Key;
4 import com.intellij.ui.SimpleTextAttributes;
5 import com.intellij.util.xml.DomElement;
6 import com.intellij.util.xml.DomUtil;
7 import com.intellij.util.xml.GenericDomValue;
8 import com.intellij.util.xml.ui.TooltipUtils;
9 import com.intellij.util.xml.highlighting.DomElementAnnotationsManager;
10 import com.intellij.util.xml.highlighting.DomElementProblemDescriptor;
11 import com.intellij.util.xml.reflect.DomCollectionChildDescription;
12 import com.intellij.util.xml.reflect.DomFixedChildDescription;
13 import com.intellij.lang.annotation.HighlightSeverity;
14 import jetbrains.fabrique.ui.treeStructure.SimpleNode;
16 import java.util.*;
19 public class BaseDomElementNode extends AbstractDomElementNode {
20 public static final Key<Comparator> COMPARATOR_KEY = Key.create("COMPARATOR_KEY");
21 public static final Key<Boolean> SHOW_PROPERTIES_KEY = Key.create("SHOW_PROPERTIES_KEY");
23 private final DomElement myDomElement;
24 private final String myTagName;
27 public BaseDomElementNode(final DomElement modelElement) {
28 this(modelElement, null);
31 public BaseDomElementNode(final DomElement modelElement, SimpleNode parent) {
32 super(parent);
34 myDomElement = modelElement;
35 myTagName = modelElement.getXmlElementName();
38 public SimpleNode[] getChildren() {
39 return doGetChildren(myDomElement);
42 protected final SimpleNode[] doGetChildren(final DomElement element) {
43 if (!element.isValid()) return NO_CHILDREN;
45 List<SimpleNode> children = new ArrayList<SimpleNode>();
47 for (DomFixedChildDescription description : element.getGenericInfo().getFixedChildrenDescriptions()) {
48 final List<? extends DomElement> values = description.getValues(element);
49 if (shouldBeShowed(description.getType())) {
50 if (DomUtil.isGenericValueType(description.getType())) {
51 for (DomElement domElement : values) {
52 children.add(new GenericValueNode((GenericDomValue)domElement, this));
54 } else {
55 for (DomElement domElement : values) {
56 children.add(new BaseDomElementNode(domElement, this));
62 final List<DomCollectionChildDescription> collectionChildrenDescriptions = element.getGenericInfo().getCollectionChildrenDescriptions();
63 for (DomCollectionChildDescription description : collectionChildrenDescriptions) {
64 if (shouldBeShowed(description.getType())) {
65 children.add(new DomElementsGroupNode(element, description));
69 AbstractDomElementNode[] childrenNodes = children.toArray(new AbstractDomElementNode[children.size()]);
71 final Comparator<AbstractDomElementNode> comparator = myDomElement.getRoot().getUserData(COMPARATOR_KEY);
72 if (comparator != null) {
73 Arrays.sort(childrenNodes, comparator);
76 return childrenNodes;
79 protected boolean showGenericValues() {
80 final Boolean showProperties = myDomElement.getRoot().getUserData(SHOW_PROPERTIES_KEY);
81 return showProperties != null && showProperties;
84 public Object[] getEqualityObjects() {
85 return new Object[]{myDomElement};
88 protected boolean doUpdate() {
89 if (!myDomElement.isValid()) return true;
91 setUniformIcon(getNodeIcon());
92 clearColoredText();
93 boolean isExpanded = isExpanded();
95 final List<DomElementProblemDescriptor> problems = DomElementAnnotationsManager.getInstance().getProblems(myDomElement, true, highlightIfChildrenHasProblems(), HighlightSeverity.ERROR);
96 if (problems.size() > 0) {
97 addColoredFragment(getNodeName(), TooltipUtils.getTooltipText(problems), SimpleTextAttributes.ERROR_ATTRIBUTES); //new SimpleTextAttributes(SimpleTextAttributes.STYLE_WAVED, Color.BLACK, Color.RED)
98 } else if (myDomElement.getXmlTag() != null) {
99 addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
100 } else {
101 addColoredFragment(getNodeName(), SimpleTextAttributes.GRAYED_ATTRIBUTES);
104 return true;
107 protected boolean highlightIfChildrenHasProblems() {
108 return true;
111 public String getNodeName() {
112 final String name = myDomElement.getPresentation().getElementName();
113 return name != null ? name : getPropertyName();
116 public String getTagName() {
117 return myTagName;
120 public DomElement getDomElement() {
121 return myDomElement;
124 public boolean isAutoExpandNode() {
125 return getParent() == null;