update copyright
[fedora-idea.git] / xml / dom-openapi / src / com / intellij / util / xml / tree / DomElementsGroupNode.java
blob79c878b23c0b76691106dcc940848ba8c606ff33
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.util.xml.tree;
19 import com.intellij.ide.IdeBundle;
20 import com.intellij.lang.annotation.HighlightSeverity;
21 import com.intellij.ui.SimpleTextAttributes;
22 import com.intellij.ui.treeStructure.SimpleNode;
23 import com.intellij.util.ReflectionUtil;
24 import com.intellij.util.xml.DomElement;
25 import com.intellij.util.xml.ElementPresentationManager;
26 import com.intellij.util.xml.highlighting.DomElementAnnotationsManager;
27 import com.intellij.util.xml.highlighting.DomElementProblemDescriptor;
28 import com.intellij.util.xml.highlighting.DomElementsProblemsHolder;
29 import com.intellij.util.xml.reflect.DomCollectionChildDescription;
31 import javax.swing.*;
32 import java.util.ArrayList;
33 import java.util.List;
35 public class DomElementsGroupNode extends AbstractDomElementNode {
36 private final DomElement myParentElement;
37 private final DomElement myRootDomElement;
38 private final String myChildrenTagName;
39 private final DomCollectionChildDescription myChildDescription;
41 public DomElementsGroupNode(final DomElement modelElement, DomCollectionChildDescription description, SimpleNode parent,
42 final DomElement rootDomElement) {
43 super(modelElement, parent);
44 myParentElement = modelElement;
45 myChildDescription = description;
46 myChildrenTagName = description.getXmlElementName();
47 myRootDomElement = rootDomElement;
50 public SimpleNode[] getChildren() {
51 if (!myParentElement.isValid()) return NO_CHILDREN;
53 final List<SimpleNode> simpleNodes = new ArrayList<SimpleNode>();
54 for (DomElement domChild : myChildDescription.getStableValues(myParentElement)) {
55 if (shouldBeShown(domChild.getDomElementType())) {
56 simpleNodes.add(new BaseDomElementNode(domChild, myRootDomElement, this));
59 return simpleNodes.toArray(new SimpleNode[simpleNodes.size()]);
62 public Object[] getEqualityObjects() {
63 return new Object[]{myParentElement, myChildrenTagName};
66 protected void doUpdate() {
67 setUniformIcon(getNodeIcon());
69 clearColoredText();
71 final boolean showErrors = hasErrors();
72 final int childrenCount = getChildren().length;
74 if (childrenCount > 0) {
75 final SimpleTextAttributes textAttributes =
76 showErrors ? getWavedAttributes(SimpleTextAttributes.STYLE_BOLD) : new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, SimpleTextAttributes.REGULAR_ATTRIBUTES.getFgColor());
78 addColoredFragment(getNodeName(), textAttributes);
79 addColoredFragment(" (" + childrenCount + ')', showErrors ? IdeBundle.message("dom.elements.tree.childs.contain.errors") : null,
80 SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES);
82 else {
83 addColoredFragment(getNodeName(), SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES);
87 private boolean hasErrors() {
88 if (!myParentElement.isValid()) return false;
90 for (DomElement domElement : myChildDescription.getStableValues(myParentElement)) {
91 final DomElementAnnotationsManager annotationsManager = DomElementAnnotationsManager.getInstance(getProject());
92 final DomElementsProblemsHolder holder = annotationsManager.getCachedProblemHolder(domElement);
93 final List<DomElementProblemDescriptor> problems = holder.getProblems(domElement, true, HighlightSeverity.ERROR);
94 if (problems.size() > 0) return true;
97 return false;
100 public String getNodeName() {
101 if (!myParentElement.isValid()) return "";
103 return myChildDescription.getCommonPresentableName(myParentElement);
106 public String getTagName() {
107 return myChildrenTagName;
110 public DomElement getDomElement() {
111 return myParentElement;
115 public DomCollectionChildDescription getChildDescription() {
116 return myChildDescription;
120 public Icon getNodeIcon() {
121 Class clazz = ReflectionUtil.getRawType(myChildDescription.getType());
122 // Class arrayClass = Array.newInstance(clazz, 0).getClass();
123 return ElementPresentationManager.getIconForClass(clazz);