use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class MockDomElementsEditor method initFileEditor.
protected final DomFileEditor initFileEditor(final Project project, final VirtualFile virtualFile, final String name, final Factory<? extends BasicDomElementComponent> component) {
myFileEditor = new DomFileEditor<BasicDomElementComponent>(project, virtualFile, name, component) {
@Override
public JComponent getPreferredFocusedComponent() {
return null;
}
@Override
@NotNull
protected JComponent createCustomComponent() {
final JComponent customComponent = super.createCustomComponent();
myContents = getDomComponent();
return customComponent;
}
@Override
public void reset() {
for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) {
final DomElement newValue = entry.getKey().find();
final DomElement oldValue = entry.getValue();
if (newValue != null && !newValue.equals(oldValue) || newValue == null && !oldValue.getManager().isMockElement(oldValue)) {
((StableElement) oldValue).revalidate();
}
}
super.reset();
}
@Override
public void commit() {
super.commit();
final List<EditedElementDescription> descriptions = new ArrayList<>();
final Set<PsiFile> changedFiles = new HashSet<>();
for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) {
final EditedElementDescription description = entry.getKey();
final DomElement editedElement = entry.getValue();
if (description.find() == null && editedElement.getXmlTag() != null) {
descriptions.add(description);
final XmlFile xmlFile = description.getEditedFile();
if (xmlFile != null) {
changedFiles.add(xmlFile);
}
}
}
new WriteCommandAction(project, PsiUtilCore.toPsiFileArray(changedFiles)) {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (EditedElementDescription description : descriptions) {
final DomElement editedElement = myDomElements.get(description);
DomElement element = description.addElement();
element.copyFrom(editedElement);
description.initialize(element);
removeWatchedElement(editedElement);
((StableElement) editedElement).invalidate();
}
}
}.execute();
}
};
final DomManager domManager = DomManager.getDomManager(project);
for (final DomElement element : myDomElements.values()) {
if (domManager.isMockElement(element)) {
myFileEditor.addWatchedElement(element);
}
}
return myFileEditor;
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class ApplicationLoader method registerMetaData.
private static void registerMetaData() {
final MetaDataRegistrar registrar = MetaDataRegistrar.getInstance();
registrar.registerMetaData(new AndFilter(new NamespaceFilter(RNG_NAMESPACE), new ClassFilter(XmlDocument.class)), RngNsDescriptor.class);
registrar.registerMetaData(new ClassFilter(RncDocument.class), RngNsDescriptor.class);
registrar.registerMetaData(new ElementFilter() {
@Override
public boolean isAcceptable(Object element, PsiElement context) {
if (element instanceof XmlTag) {
final XmlTag tag = (XmlTag) element;
final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
return domElement instanceof RngDefine;
}
return false;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return XmlTag.class.isAssignableFrom(hintClass);
}
}, RngDefineMetaData.class);
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class DomStructureViewBuilder method createStructureView.
@Override
@NotNull
public StructureView createStructureView(final FileEditor fileEditor, @NotNull final Project project) {
return new StructureViewComponent(fileEditor, createStructureViewModel(fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null), project, true) {
@Override
public AsyncResult<AbstractTreeNode> expandPathToElement(final Object element) {
if (element instanceof XmlElement && ((XmlElement) element).isValid()) {
final XmlElement xmlElement = (XmlElement) element;
XmlTag tag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class, false);
while (tag != null) {
final DomElement domElement = DomManager.getDomManager(xmlElement.getProject()).getDomElement(tag);
if (domElement != null) {
for (DomElement curElement = domElement; curElement != null; curElement = curElement.getParent()) {
if (myDescriptor.fun(curElement) == DomService.StructureViewMode.SHOW) {
return super.expandPathToElement(curElement.getXmlElement());
}
}
}
tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class, true);
}
}
return super.expandPathToElement(element);
}
};
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class AttributeChildInvocationHandler method ensureXmlElementExists.
@Override
public final XmlAttribute ensureXmlElementExists() {
XmlAttribute attribute = (XmlAttribute) getXmlElement();
if (attribute != null)
return attribute;
final DomManagerImpl manager = getManager();
final boolean b = manager.setChanging(true);
try {
attribute = ensureTagExists().setAttribute(getXmlElementName(), getXmlApiCompatibleNamespace(getParentHandler()), "");
setXmlElement(attribute);
getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, this);
final DomElement element = getProxy();
manager.fireEvent(new DomEvent(element, true));
return attribute;
} catch (IncorrectOperationException e) {
LOG.error(e);
return null;
} finally {
manager.setChanging(b);
}
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class CollectionElementInvocationHandler method createPathStableCopy.
@Override
public DomElement createPathStableCopy() {
final AbstractDomChildDescriptionImpl description = getChildDescription();
final DomElement parent = getParent();
assert parent != null;
final DomElement parentCopy = parent.createStableCopy();
final int index = description.getValues(parent).indexOf(getProxy());
return getManager().createStableValue((Factory<DomElement>) () -> {
if (parentCopy.isValid()) {
final List<? extends DomElement> list = description.getValues(parentCopy);
if (list.size() > index) {
return list.get(index);
}
}
return null;
});
}
Aggregations