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;
}
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;
}
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() };
}
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();
}
}
}
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);
}
Aggregations