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
.GenericValue
;
7 import com
.intellij
.util
.xml
.DomUtil
;
8 import com
.intellij
.util
.xml
.reflect
.DomCollectionChildDescription
;
9 import com
.intellij
.util
.xml
.reflect
.DomFixedChildDescription
;
10 import com
.intellij
.util
.xml
.ui
.DomElementsPresentation
;
11 import jetbrains
.fabrique
.ui
.treeStructure
.SimpleNode
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Arrays
;
15 import java
.util
.Comparator
;
16 import java
.util
.List
;
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
;
26 public BaseDomElementNode(final DomElement modelElement
) {
27 this(modelElement
, null);
30 public BaseDomElementNode(final DomElement modelElement
, SimpleNode parent
) {
33 myDomElement
= modelElement
;
34 myTagName
= modelElement
.getXmlElementName();
37 public SimpleNode
[] getChildren() {
38 return doGetChildren(myDomElement
);
41 protected final SimpleNode
[] doGetChildren(final DomElement element
) {
42 if (!element
.isValid()) return NO_CHILDREN
;
44 List
<SimpleNode
> children
= new ArrayList
<SimpleNode
>();
46 for (DomFixedChildDescription description
: element
.getGenericInfo().getFixedChildrenDescriptions()) {
47 final List
<?
extends DomElement
> values
= description
.getValues(element
);
48 if (DomUtil
.isGenericValueType(description
.getType())) {
49 if (showGenericValues()) {
50 for (DomElement domElement
: values
) {
51 children
.add(new GenericValueNode((GenericValue
)domElement
, this));
56 for (DomElement domElement
: values
) {
57 children
.add(new BaseDomElementNode(domElement
, this));
62 final List
<DomCollectionChildDescription
> collectionChildrenDescriptions
= element
.getGenericInfo().getCollectionChildrenDescriptions();
63 for (DomCollectionChildDescription description
: collectionChildrenDescriptions
) {
64 children
.add(new DomElementsGroupNode(element
, description
));
67 AbstractDomElementNode
[] childrenNodes
= children
.toArray(new AbstractDomElementNode
[children
.size()]);
69 final Comparator
<AbstractDomElementNode
> comparator
= myDomElement
.getRoot().getUserData(COMPARATOR_KEY
);
70 if (comparator
!= null) {
71 Arrays
.sort(childrenNodes
, comparator
);
77 protected boolean showGenericValues() {
78 final Boolean showProperties
= myDomElement
.getRoot().getUserData(SHOW_PROPERTIES_KEY
);
79 return showProperties
== null ?
false: showProperties
;
82 public Object
[] getEqualityObjects() {
83 return new Object
[]{myDomElement
};
86 protected boolean doUpdate() {
87 if (!myDomElement
.isValid()) return true;
89 setUniformIcon(getNodeIcon());
91 if (myDomElement
.getXmlTag() != null) {
92 addColoredFragment(getNodeName(), SimpleTextAttributes
.REGULAR_ATTRIBUTES
);
95 addColoredFragment(getNodeName(), SimpleTextAttributes
.GRAYED_ATTRIBUTES
);
101 public String
getNodeName() {
102 final DomElementsPresentation presentation
= myDomElement
.getRoot().getUserData(DomElementsPresentation
.DOM_ELEMENTS_PRESENTATION
);
103 if (presentation
!= null && presentation
.getPresentationName(myDomElement
) != null) {
104 return presentation
.getPresentationName(myDomElement
);
106 return getPropertyName();
109 public String
getTagName() {
113 public final DomElement
getDomElement() {
117 public boolean isAutoExpandNode() {
118 return getParent() == null;