Search in sources :

Example 6 with PomModelEvent

use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.

the class XmlTagImpl method deleteChildInternal.

@Override
public void deleteChildInternal(@NotNull final ASTNode child) {
    final PomModel model = PomManager.getModel(getProject());
    final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
    if (child.getElementType() == XmlElementType.XML_ATTRIBUTE) {
        try {
            model.runTransaction(new PomTransactionBase(this, aspect) {

                @Override
                public PomModelEvent runInner() {
                    final String name = ((XmlAttribute) child).getName();
                    XmlTagImpl.super.deleteChildInternal(child);
                    return XmlAttributeSetImpl.createXmlAttributeSet(model, XmlTagImpl.this, name, null);
                }
            });
        } catch (IncorrectOperationException e) {
            LOG.error(e);
        }
    } else {
        final ASTNode treePrev = child.getTreePrev();
        final ASTNode treeNext = child.getTreeNext();
        super.deleteChildInternal(child);
        if (treePrev != null && treeNext != null && treePrev.getElementType() == XmlElementType.XML_TEXT && treeNext.getElementType() == XmlElementType.XML_TEXT) {
            final XmlText prevText = (XmlText) treePrev.getPsi();
            final XmlText nextText = (XmlText) treeNext.getPsi();
            final String newValue = prevText.getValue() + nextText.getValue();
            // merging two XmlText-s should be done in one transaction to preserve smart pointers
            ChangeUtil.prepareAndRunChangeAction(new ChangeUtil.ChangeAction() {

                @Override
                public void makeChange(TreeChangeEvent destinationTreeChange) {
                    PsiElement anchor = prevText.getPrevSibling();
                    prevText.delete();
                    nextText.delete();
                    XmlText text = (XmlText) addAfter(XmlElementFactory.getInstance(getProject()).createDisplayText("x"), anchor);
                    text.setValue(newValue);
                }
            }, this);
        }
    }
}
Also used : TreeChangeEvent(com.intellij.pom.tree.events.TreeChangeEvent) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent) XmlAspect(com.intellij.pom.xml.XmlAspect) ASTNode(com.intellij.lang.ASTNode) PomModel(com.intellij.pom.PomModel) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 7 with PomModelEvent

use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.

the class XmlTextImpl method createEvent.

private PomModelEvent createEvent(final XmlChange... events) {
    final PomModelEvent event = new PomModelEvent(PomManager.getModel(getProject()));
    final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(PomManager.getModel(getProject()), (XmlFile) getContainingFile());
    for (XmlChange xmlChange : events) {
        xmlAspectChangeSet.add(xmlChange);
    }
    event.registerChangeSet(PomManager.getModel(getProject()).getModelAspect(XmlAspect.class), xmlAspectChangeSet);
    return event;
}
Also used : XmlAspectChangeSetImpl(com.intellij.pom.xml.impl.XmlAspectChangeSetImpl) XmlChange(com.intellij.pom.xml.events.XmlChange) XmlAspect(com.intellij.pom.xml.XmlAspect) PomModelEvent(com.intellij.pom.event.PomModelEvent)

Example 8 with PomModelEvent

use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.

the class XmlDocumentImpl method deleteChildInternal.

@Override
public void deleteChildInternal(@NotNull final ASTNode child) {
    final PomModel model = PomManager.getModel(getProject());
    final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
    try {
        model.runTransaction(new PomTransactionBase(this, aspect) {

            @Override
            public PomModelEvent runInner() {
                XmlDocumentImpl.super.deleteChildInternal(child);
                return XmlDocumentChangedImpl.createXmlDocumentChanged(model, XmlDocumentImpl.this);
            }
        });
    } catch (IncorrectOperationException ignored) {
    }
}
Also used : XmlAspect(com.intellij.pom.xml.XmlAspect) PomModel(com.intellij.pom.PomModel) PomTransactionBase(com.intellij.pom.impl.PomTransactionBase) PomModelEvent(com.intellij.pom.event.PomModelEvent) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 9 with PomModelEvent

use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.

the class XmlAttributeSetImpl method createXmlAttributeSet.

public static PomModelEvent createXmlAttributeSet(PomModel model, XmlTag xmlTag, String name, String value) {
    final PomModelEvent event = new PomModelEvent(model);
    final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(model, PsiTreeUtil.getParentOfType(xmlTag, XmlFile.class));
    xmlAspectChangeSet.add(new XmlAttributeSetImpl(xmlTag, name, value));
    event.registerChangeSet(model.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
    return event;
}
Also used : XmlAspectChangeSetImpl(com.intellij.pom.xml.impl.XmlAspectChangeSetImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlAspect(com.intellij.pom.xml.XmlAspect) PomModelEvent(com.intellij.pom.event.PomModelEvent)

Example 10 with PomModelEvent

use of com.intellij.pom.event.PomModelEvent in project intellij-community by JetBrains.

the class XmlTagChildChangedImpl method createXmlTagChildChanged.

public static PomModelEvent createXmlTagChildChanged(PomModel source, XmlTag context, XmlTagChild treeElement) {
    final PomModelEvent event = new PomModelEvent(source);
    final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(source, PsiTreeUtil.getParentOfType(context, XmlFile.class));
    xmlAspectChangeSet.add(new XmlTagChildChangedImpl(context, treeElement));
    event.registerChangeSet(source.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
    return event;
}
Also used : XmlAspectChangeSetImpl(com.intellij.pom.xml.impl.XmlAspectChangeSetImpl) XmlFile(com.intellij.psi.xml.XmlFile) XmlAspect(com.intellij.pom.xml.XmlAspect) PomModelEvent(com.intellij.pom.event.PomModelEvent)

Aggregations

PomModelEvent (com.intellij.pom.event.PomModelEvent)21 XmlAspect (com.intellij.pom.xml.XmlAspect)17 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)13 PomModel (com.intellij.pom.PomModel)12 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9 ASTNode (com.intellij.lang.ASTNode)7 XmlAspectChangeSetImpl (com.intellij.pom.xml.impl.XmlAspectChangeSetImpl)7 XmlFile (com.intellij.psi.xml.XmlFile)5 TreeChangeEvent (com.intellij.pom.tree.events.TreeChangeEvent)2 IElementType (com.intellij.psi.tree.IElementType)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 TextRange (com.intellij.openapi.util.TextRange)1 PomModelAspect (com.intellij.pom.PomModelAspect)1 PomTransaction (com.intellij.pom.PomTransaction)1 PomModelListener (com.intellij.pom.event.PomModelListener)1 TreeAspect (com.intellij.pom.tree.TreeAspect)1 TreeAspectEvent (com.intellij.pom.tree.TreeAspectEvent)1 TreeChangeEventImpl (com.intellij.pom.tree.events.impl.TreeChangeEventImpl)1 XmlChangeSet (com.intellij.pom.xml.XmlChangeSet)1