Search in sources :

Example 86 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class CollectionElementInvocationHandler method undefineInternal.

@Override
public final void undefineInternal() {
    final DomElement parent = getParent();
    final XmlTag tag = getXmlTag();
    if (tag == null)
        return;
    getManager().cacheHandler(getCacheKey(), tag, null);
    setXmlElement(null);
    deleteTag(tag);
    getManager().fireEvent(new DomEvent(parent, false));
}
Also used : DomElement(com.intellij.util.xml.DomElement) XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 87 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class DomTemplateRunnerImpl method runTemplate.

public <T extends DomElement> void runTemplate(final T t, final Editor editor, @Nullable final Template template, Map<String, String> predefinedVars) {
    if (template != null) {
        DomElement copy = t.createStableCopy();
        PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(editor.getDocument());
        XmlTag tag = copy.getXmlTag();
        assert tag != null;
        editor.getCaretModel().moveToOffset(tag.getTextRange().getStartOffset());
        copy.undefine();
        PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(editor.getDocument());
        template.setToReformat(true);
        TemplateManager.getInstance(myProject).startTemplate(editor, template, true, predefinedVars, null);
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 88 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class DeleteDomElement method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) {
    final SimpleNode selectedNode = treeView.getTree().getSelectedNode();
    if (selectedNode instanceof BaseDomElementNode) {
        if (selectedNode instanceof DomFileElementNode) {
            e.getPresentation().setVisible(false);
            return;
        }
        final DomElement domElement = ((BaseDomElementNode) selectedNode).getDomElement();
        final int ret = Messages.showOkCancelDialog(getPresentationText(selectedNode, "Remove") + "?", "Remove", Messages.getQuestionIcon());
        if (ret == Messages.OK) {
            new WriteCommandAction(domElement.getManager().getProject(), DomUtil.getFile(domElement)) {

                @Override
                protected void run(@NotNull final Result result) throws Throwable {
                    domElement.undefine();
                }
            }.execute();
        }
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) BaseDomElementNode(com.intellij.util.xml.tree.BaseDomElementNode) DomElement(com.intellij.util.xml.DomElement) DomFileElementNode(com.intellij.util.xml.tree.DomFileElementNode) SimpleNode(com.intellij.ui.treeStructure.SimpleNode) Result(com.intellij.openapi.application.Result)

Example 89 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class DeleteDomElement method update.

@Override
public void update(AnActionEvent e, DomModelTreeView treeView) {
    final SimpleNode selectedNode = treeView.getTree().getSelectedNode();
    if (selectedNode instanceof DomFileElementNode) {
        e.getPresentation().setVisible(false);
        return;
    }
    boolean enabled = false;
    if (selectedNode instanceof BaseDomElementNode) {
        final DomElement domElement = ((BaseDomElementNode) selectedNode).getDomElement();
        if (domElement.isValid() && DomUtil.hasXml(domElement) && !(domElement.getParent() instanceof DomFileElement)) {
            enabled = true;
        }
    }
    e.getPresentation().setEnabled(enabled);
    if (enabled) {
        e.getPresentation().setText(getPresentationText(selectedNode, ApplicationBundle.message("action.remove")));
    } else {
        e.getPresentation().setText(ApplicationBundle.message("action.remove"));
    }
    e.getPresentation().setIcon(AllIcons.General.Remove);
}
Also used : BaseDomElementNode(com.intellij.util.xml.tree.BaseDomElementNode) DomElement(com.intellij.util.xml.DomElement) DomFileElementNode(com.intellij.util.xml.tree.DomFileElementNode) DomFileElement(com.intellij.util.xml.DomFileElement) SimpleNode(com.intellij.ui.treeStructure.SimpleNode)

Example 90 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-plugins by JetBrains.

the class ActionNameCustomReferenceConverter method createReferences.

@NotNull
@Override
public PsiReference[] createReferences(final GenericDomValue<String> genericDomValue, final PsiElement psiElement, final ConvertContext convertContext) {
    final PsiReferenceBase<PsiElement> ref = new PsiReferenceBase<PsiElement>(psiElement) {

        @SuppressWarnings({ "ConstantConditions" })
        public PsiElement resolve() {
            return genericDomValue.getParent().getXmlTag();
        }

        public boolean isSoft() {
            return true;
        }

        // do nothing. the element will be renamed via PsiMetaData
        public PsiElement handleElementRename(final String newElementName) throws IncorrectOperationException {
            return getElement();
        }

        @NotNull
        public Object[] getVariants() {
            final DomElement invocationElement = convertContext.getInvocationElement();
            final Action action = invocationElement.getParentOfType(Action.class, true);
            assert action != null;
            final PsiClass psiClass = action.searchActionClass();
            if (psiClass == null) {
                return EMPTY_ARRAY;
            }
            final Project project = psiClass.getProject();
            final PsiClassType classType = PsiTypesUtil.getClassType(psiClass);
            final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
            final SuggestedNameInfo info = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, classType);
            final Set<String> variants = new HashSet<>(Arrays.asList(info.names));
            variants.remove(ACTION_SUFFIX);
            // remove existing action-names
            final List<Action> actions = action.getStrutsPackage().getActions();
            ContainerUtil.process(actions, action1 -> {
                variants.remove(action1.getName().getStringValue());
                return true;
            });
            return ContainerUtil.map2Array(variants, ACTION_NAME_FUNCTION);
        }
    };
    return new PsiReference[] { ref };
}
Also used : Project(com.intellij.openapi.project.Project) DomElement(com.intellij.util.xml.DomElement) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DomElement (com.intellij.util.xml.DomElement)97 XmlTag (com.intellij.psi.xml.XmlTag)34 PsiElement (com.intellij.psi.PsiElement)19 Nullable (org.jetbrains.annotations.Nullable)19 NotNull (org.jetbrains.annotations.NotNull)15 Project (com.intellij.openapi.project.Project)11 PsiFile (com.intellij.psi.PsiFile)11 XmlFile (com.intellij.psi.xml.XmlFile)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)9 ArrayList (java.util.ArrayList)8 LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)7 ResourceElement (org.jetbrains.android.dom.resources.ResourceElement)6 DomManager (com.intellij.util.xml.DomManager)5 Style (org.jetbrains.android.dom.resources.Style)5 AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)4 XmlElement (com.intellij.psi.xml.XmlElement)4 DomElementProblemDescriptor (com.intellij.util.xml.highlighting.DomElementProblemDescriptor)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 TextRange (com.intellij.openapi.util.TextRange)3