Search in sources :

Example 16 with SimpleNode

use of com.intellij.ui.treeStructure.SimpleNode in project intellij-community by JetBrains.

the class DomModelTreeView method visit.

@Nullable
private SimpleNode visit(SimpleNode simpleNode, DomElement domElement) {
    boolean validCandidate = false;
    if (simpleNode instanceof AbstractDomElementNode) {
        final DomElement nodeElement = ((AbstractDomElementNode) simpleNode).getDomElement();
        if (nodeElement != null) {
            validCandidate = !(simpleNode instanceof DomElementsGroupNode);
            if (validCandidate && nodeElement.equals(domElement)) {
                return simpleNode;
            }
            if (!(nodeElement instanceof MergedObject) && !isParent(nodeElement, domElement)) {
                return null;
            }
        }
    }
    final Object[] childElements = myBuilder.getTreeStructure().getChildElements(simpleNode);
    if (childElements.length == 0 && validCandidate) {
        // leaf
        return simpleNode;
    }
    for (Object child : childElements) {
        SimpleNode result = visit((SimpleNode) child, domElement);
        if (result != null) {
            return result;
        }
    }
    return validCandidate ? simpleNode : null;
}
Also used : SimpleNode(com.intellij.ui.treeStructure.SimpleNode) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with SimpleNode

use of com.intellij.ui.treeStructure.SimpleNode in project intellij-community by JetBrains.

the class BaseDomElementNode method doGetChildren.

protected final SimpleNode[] doGetChildren(final DomElement element) {
    if (!element.isValid())
        return NO_CHILDREN;
    List<SimpleNode> children = new ArrayList<>();
    final XmlTag tag = element.getXmlTag();
    if (tag != null && !(tag.getContainingFile() instanceof XmlFile))
        return NO_CHILDREN;
    final XmlElementDescriptor xmlElementDescriptor = tag == null ? null : tag.getDescriptor();
    final XmlElementDescriptor[] xmlDescriptors = xmlElementDescriptor == null ? null : xmlElementDescriptor.getElementsDescriptors(tag);
    for (DomFixedChildDescription description : element.getGenericInfo().getFixedChildrenDescriptions()) {
        String childName = description.getXmlElementName();
        if (xmlDescriptors != null) {
            if (findDescriptor(xmlDescriptors, childName) == -1)
                continue;
        }
        final List<? extends DomElement> values = description.getStableValues(element);
        if (shouldBeShown(description.getType())) {
            if (DomUtil.isGenericValueType(description.getType())) {
                for (DomElement value : values) {
                    children.add(new GenericValueNode((GenericDomValue) value, this));
                }
            } else {
                for (DomElement domElement : values) {
                    children.add(new BaseDomElementNode(domElement, myRootDomElement, this));
                }
            }
        }
    }
    for (DomCollectionChildDescription description : element.getGenericInfo().getCollectionChildrenDescriptions()) {
        if (shouldBeShown(description.getType())) {
            DomElementsGroupNode groupNode = new DomElementsGroupNode(element, description, this, myRootDomElement);
            if (isMarkedType(description.getType(), CONSOLIDATED_NODES_KEY)) {
                Collections.addAll(children, groupNode.getChildren());
            } else {
                children.add(groupNode);
            }
        }
    }
    AbstractDomElementNode[] childrenNodes = children.toArray(new AbstractDomElementNode[children.size()]);
    Comparator<AbstractDomElementNode> comparator = DomUtil.getFile(myDomElement).getUserData(COMPARATOR_KEY);
    if (comparator == null) {
        comparator = getDefaultComparator(element);
    }
    if (comparator != null) {
        Arrays.sort(childrenNodes, comparator);
    }
    return childrenNodes;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) SimpleNode(com.intellij.ui.treeStructure.SimpleNode) DomCollectionChildDescription(com.intellij.util.xml.reflect.DomCollectionChildDescription) DomFixedChildDescription(com.intellij.util.xml.reflect.DomFixedChildDescription) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 18 with SimpleNode

use of com.intellij.ui.treeStructure.SimpleNode in project intellij-community by JetBrains.

the class AddElementInCollectionAction method getDomCollectionChildDescriptions.

@Override
@NotNull
protected DomCollectionChildDescription[] getDomCollectionChildDescriptions(final AnActionEvent e) {
    final DomModelTreeView view = getTreeView(e);
    SimpleNode node = view.getTree().getSelectedNode();
    if (node instanceof BaseDomElementNode) {
        List<DomCollectionChildDescription> consolidated = ((BaseDomElementNode) node).getConsolidatedChildrenDescriptions();
        if (consolidated.size() > 0) {
            return consolidated.toArray(new DomCollectionChildDescription[consolidated.size()]);
        }
    }
    final DomElementsGroupNode groupNode = getDomElementsGroupNode(view);
    return groupNode == null ? DomCollectionChildDescription.EMPTY_ARRAY : new DomCollectionChildDescription[] { groupNode.getChildDescription() };
}
Also used : BaseDomElementNode(com.intellij.util.xml.tree.BaseDomElementNode) DomModelTreeView(com.intellij.util.xml.tree.DomModelTreeView) DomElementsGroupNode(com.intellij.util.xml.tree.DomElementsGroupNode) DomCollectionChildDescription(com.intellij.util.xml.reflect.DomCollectionChildDescription) SimpleNode(com.intellij.ui.treeStructure.SimpleNode) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with SimpleNode

use of com.intellij.ui.treeStructure.SimpleNode 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 20 with SimpleNode

use of com.intellij.ui.treeStructure.SimpleNode 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)

Aggregations

SimpleNode (com.intellij.ui.treeStructure.SimpleNode)20 BaseDomElementNode (com.intellij.util.xml.tree.BaseDomElementNode)5 NullNode (com.intellij.ui.treeStructure.NullNode)4 DomElement (com.intellij.util.xml.DomElement)3 TreePath (javax.swing.tree.TreePath)3 NotNull (org.jetbrains.annotations.NotNull)3 DomCollectionChildDescription (com.intellij.util.xml.reflect.DomCollectionChildDescription)2 DomElementsGroupNode (com.intellij.util.xml.tree.DomElementsGroupNode)2 DomFileElementNode (com.intellij.util.xml.tree.DomFileElementNode)2 DomModelTreeView (com.intellij.util.xml.tree.DomModelTreeView)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 AbstractDependencyNode (com.android.tools.idea.gradle.structure.configurables.android.dependencies.treeview.AbstractDependencyNode)1 AbstractTreeUi (com.intellij.ide.util.treeView.AbstractTreeUi)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 ProjectNode (com.intellij.openapi.externalSystem.view.ProjectNode)1 TaskNode (com.intellij.openapi.externalSystem.view.TaskNode)1 Configurable (com.intellij.openapi.options.Configurable)1 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)1 PackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode)1