update copyright
[fedora-idea.git] / xml / dom-openapi / src / com / intellij / util / xml / tree / AbstractDomElementNode.java
blobf629d2ec661c17a59712207fc34a9973bea5f591
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.openapi.util.Key;
20 import com.intellij.ui.SimpleTextAttributes;
21 import com.intellij.ui.treeStructure.SimpleNode;
22 import com.intellij.util.ReflectionUtil;
23 import com.intellij.util.xml.DomElement;
24 import com.intellij.util.xml.DomUtil;
26 import javax.swing.*;
27 import java.lang.reflect.Type;
28 import java.util.*;
30 abstract public class AbstractDomElementNode extends SimpleNode {
32 public static final Key<Map<Class, Boolean>> TREE_NODES_HIDERS_KEY = Key.create("TREE_NODES_HIDERS_KEY");
34 private final static Comparator<Class> INHERITORS_COMPARATOR = new Comparator<Class>() {
35 public int compare(final Class o1, final Class o2) {
36 return o1.isAssignableFrom(o2) ? 1 : -1;
40 private boolean isExpanded;
43 protected AbstractDomElementNode(DomElement element) {
44 this(element, null);
47 public String toString() {
48 return getNodeName();
51 protected AbstractDomElementNode(DomElement element, SimpleNode parent) {
52 super(element.getManager().getProject(), parent);
55 abstract public DomElement getDomElement();
57 abstract public String getNodeName();
59 abstract public String getTagName();
62 public Icon getNodeIcon() {
63 return getDomElement().getPresentation().getIcon();
66 protected String getPropertyName() {
67 return getDomElement().getPresentation().getTypeName();
70 protected boolean shouldBeShown(final Type type) {
71 final Map<Class, Boolean> hiders = DomUtil.getFile(getDomElement()).getUserData(TREE_NODES_HIDERS_KEY);
72 if (type == null || hiders == null || hiders.size() == 0) return true;
74 final Class aClass = ReflectionUtil.getRawType(type);
76 List<Class> allParents = new ArrayList<Class>();
77 for (Map.Entry<Class, Boolean> entry : hiders.entrySet()) {
78 if (entry.getKey().isAssignableFrom(aClass)) {
79 allParents.add(entry.getKey());
82 if (allParents.size() == 0) return false;
84 Collections.sort(allParents, INHERITORS_COMPARATOR);
86 return hiders.get(allParents.get(0)).booleanValue();
90 protected SimpleTextAttributes getSimpleAttributes(final int style) {
91 return new SimpleTextAttributes(style, SimpleTextAttributes.REGULAR_ATTRIBUTES.getFgColor());
94 protected SimpleTextAttributes getWavedAttributes(final int style) {
95 return new SimpleTextAttributes(style | SimpleTextAttributes.STYLE_WAVED, SimpleTextAttributes.REGULAR_ATTRIBUTES.getFgColor(), SimpleTextAttributes.ERROR_ATTRIBUTES.getFgColor());
97 public boolean isExpanded() {
98 return isExpanded;
101 public void setExpanded(final boolean expanded) {
102 isExpanded = expanded;