Search in sources :

Example 1 with CompositePackagingElementNode

use of com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode in project intellij-community by JetBrains.

the class InlineArtifactAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final LayoutTreeComponent treeComponent = myEditor.getLayoutTreeComponent();
    final LayoutTreeSelection selection = treeComponent.getSelection();
    final PackagingElement<?> element = selection.getElementIfSingle();
    final PackagingElementNode<?> node = selection.getNodeIfSingle();
    if (node == null || !(element instanceof ArtifactPackagingElement))
        return;
    final CompositePackagingElement<?> parent = node.getParentElement(element);
    final CompositePackagingElementNode parentNode = node.getParentNode();
    if (parent == null || parentNode == null) {
        return;
    }
    if (!treeComponent.checkCanModifyChildren(parent, parentNode, Collections.singletonList(node)))
        return;
    treeComponent.editLayout(() -> {
        parent.removeChild(element);
        final ArtifactEditorContext context = myEditor.getContext();
        final Artifact artifact = ((ArtifactPackagingElement) element).findArtifact(context);
        if (artifact != null) {
            final CompositePackagingElement<?> rootElement = artifact.getRootElement();
            if (rootElement instanceof ArtifactRootElement<?>) {
                for (PackagingElement<?> child : rootElement.getChildren()) {
                    parent.addOrFindChild(ArtifactUtil.copyWithChildren(child, context.getProject()));
                }
            } else {
                parent.addOrFindChild(ArtifactUtil.copyWithChildren(rootElement, context.getProject()));
            }
        }
    });
    treeComponent.rebuildTree();
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) ArtifactRootElement(com.intellij.packaging.elements.ArtifactRootElement) CompositePackagingElementNode(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode) ArtifactEditorContext(com.intellij.packaging.ui.ArtifactEditorContext) Artifact(com.intellij.packaging.artifacts.Artifact) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)

Example 2 with CompositePackagingElementNode

use of com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode in project intellij-community by JetBrains.

the class MovePackagingElementAction method isEnabled.

private boolean isEnabled() {
    if (myLayoutTreeComponent.isSortElements()) {
        return false;
    }
    final PackagingElementNode<?> node = myLayoutTreeComponent.getSelection().getNodeIfSingle();
    if (node == null) {
        return false;
    }
    final CompositePackagingElementNode parent = node.getParentNode();
    if (parent == null)
        return false;
    final PackagingElement<?> element = node.getElementIfSingle();
    final CompositePackagingElement<?> parentElement = parent.getElementIfSingle();
    if (parentElement == null || element == null)
        return false;
    final List<PackagingElement<?>> children = parentElement.getChildren();
    final int index = children.indexOf(element);
    return index != -1 && 0 <= index + myDirection && index + myDirection < children.size();
}
Also used : CompositePackagingElementNode(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement)

Example 3 with CompositePackagingElementNode

use of com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode in project intellij-community by JetBrains.

the class MovePackagingElementAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final PackagingElementNode<?> node = myLayoutTreeComponent.getSelection().getNodeIfSingle();
    if (node == null)
        return;
    final CompositePackagingElementNode parent = node.getParentNode();
    if (parent == null)
        return;
    final PackagingElement<?> element = node.getElementIfSingle();
    final CompositePackagingElement<?> parentElement = parent.getElementIfSingle();
    if (parentElement == null || element == null)
        return;
    if (!myLayoutTreeComponent.checkCanModifyChildren(parentElement, parent, Arrays.asList(node)))
        return;
    final List<PackagingElement<?>> toSelect = new ArrayList<>();
    myLayoutTreeComponent.editLayout(() -> {
        final int index = parentElement.getChildren().indexOf(element);
        final PackagingElement<?> moved = parentElement.moveChild(index, myDirection);
        if (moved != null) {
            toSelect.add(moved);
        }
    });
    if (!toSelect.isEmpty()) {
        myLayoutTreeComponent.updateAndSelect(parent, toSelect);
    }
}
Also used : CompositePackagingElementNode(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode) ArrayList(java.util.ArrayList) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement)

Aggregations

CompositePackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode)3 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 PackagingElement (com.intellij.packaging.elements.PackagingElement)2 LayoutTreeComponent (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)1 LayoutTreeSelection (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection)1 Artifact (com.intellij.packaging.artifacts.Artifact)1 ArtifactRootElement (com.intellij.packaging.elements.ArtifactRootElement)1 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)1 ArtifactEditorContext (com.intellij.packaging.ui.ArtifactEditorContext)1 ArrayList (java.util.ArrayList)1