fqn rename / dom rename fix (hibernate query usecase) p1
[fedora-idea.git] / dom / openapi / src / com / intellij / util / xml / DomMetaData.java
blob310d706c8eff2117ff1067e749f466a1f727d507
1 /*
2 * Copyright 2000-2007 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.
16 package com.intellij.util.xml;
18 import com.intellij.psi.PsiElement;
19 import com.intellij.psi.meta.PsiMetaData;
20 import com.intellij.psi.meta.PsiPresentableMetaData;
21 import com.intellij.psi.meta.PsiWritableMetaData;
22 import com.intellij.psi.xml.XmlTag;
23 import com.intellij.util.IncorrectOperationException;
24 import org.jetbrains.annotations.NonNls;
25 import org.jetbrains.annotations.Nullable;
27 import javax.swing.*;
29 /**
30 * @author peter
32 public class DomMetaData<T extends DomElement> implements PsiWritableMetaData, PsiPresentableMetaData, PsiMetaData {
33 private T myElement;
34 @Nullable
35 private GenericDomValue myNameElement;
37 public final PsiElement getDeclaration() {
38 return myElement.getXmlTag();
41 public T getElement() {
42 return myElement;
45 @NonNls
46 public String getName(PsiElement context) {
47 return getName();
50 @NonNls
51 public final String getName() {
52 final String s = ElementPresentationManager.getElementName(myElement);
53 if (s != null) return s;
55 return ElementPresentationManager.getNameFromNameValue(getNameElement(myElement), false);
58 public void init(PsiElement element) {
59 myElement = (T) DomManager.getDomManager(element.getProject()).getDomElement((XmlTag)element);
60 assert myElement != null : element;
61 myNameElement = getNameElement(myElement);
64 public void setElement(final T element) {
65 myElement = element;
68 @Nullable
69 protected GenericDomValue getNameElement(final T t) {
70 return myElement.getGenericInfo().getNameDomElement(t);
73 public Object[] getDependences() {
74 final PsiElement declaration = getDeclaration();
75 if (myElement != null && myElement.isValid()) {
76 return new Object[]{myElement.getRoot(), declaration};
78 return new Object[]{declaration};
81 public void setName(String name) throws IncorrectOperationException {
82 if (myNameElement != null) {
83 myNameElement.setStringValue(name);
87 public String getTypeName() {
88 return ElementPresentationManager.getTypeNameForObject(myElement);
91 public Icon getIcon() {
92 return ElementPresentationManager.getIcon(myElement);