Search in sources :

Example 11 with CompositePackagingElement

use of com.intellij.packaging.elements.CompositePackagingElement in project intellij-community by JetBrains.

the class LayoutTreeComponent method putIntoDefaultLocations.

public void putIntoDefaultLocations(@NotNull final List<? extends PackagingSourceItem> items) {
    final List<PackagingElement<?>> toSelect = new ArrayList<>();
    editLayout(() -> {
        final CompositePackagingElement<?> rootElement = getArtifact().getRootElement();
        final ArtifactType artifactType = getArtifact().getArtifactType();
        for (PackagingSourceItem item : items) {
            final String path = artifactType.getDefaultPathFor(item);
            if (path != null) {
                final CompositePackagingElement<?> parent;
                if (path.endsWith(URLUtil.JAR_SEPARATOR)) {
                    parent = PackagingElementFactory.getInstance().getOrCreateArchive(rootElement, StringUtil.trimEnd(path, URLUtil.JAR_SEPARATOR));
                } else {
                    parent = PackagingElementFactory.getInstance().getOrCreateDirectory(rootElement, path);
                }
                final List<? extends PackagingElement<?>> elements = item.createElements(myContext);
                toSelect.addAll(parent.addOrFindChildren(elements));
            }
        }
    });
    myArtifactsEditor.getSourceItemsTree().rebuildTree();
    updateAndSelect(myTree.getRootPackagingNode(), toSelect);
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) ArtifactType(com.intellij.packaging.artifacts.ArtifactType) PackagingElement(com.intellij.packaging.elements.PackagingElement) DirectoryPackagingElement(com.intellij.packaging.impl.elements.DirectoryPackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement)

Example 12 with CompositePackagingElement

use of com.intellij.packaging.elements.CompositePackagingElement in project intellij-community by JetBrains.

the class LayoutTreeComponent method removeNodes.

public void removeNodes(final List<PackagingElementNode<?>> nodes) {
    Set<PackagingElement<?>> parents = new HashSet<>();
    for (PackagingElementNode<?> node : nodes) {
        final List<? extends PackagingElement<?>> toDelete = node.getPackagingElements();
        for (PackagingElement<?> element : toDelete) {
            final Collection<PackagingNodeSource> nodeSources = node.getNodeSource(element);
            if (nodeSources.isEmpty()) {
                final CompositePackagingElement<?> parent = node.getParentElement(element);
                if (parent != null) {
                    parents.add(parent);
                    parent.removeChild(element);
                }
            } else {
                Collection<PackagingNodeSource> rootSources = getRootNodeSources(nodeSources);
                for (PackagingNodeSource source : rootSources) {
                    parents.add(source.getSourceParentElement());
                    source.getSourceParentElement().removeChild(source.getSourceElement());
                }
            }
        }
    }
    final List<PackagingElementNode<?>> parentNodes = myTree.findNodes(parents);
    for (PackagingElementNode<?> parentNode : parentNodes) {
        myTree.addSubtreeToUpdate(parentNode);
    }
}
Also used : PackagingNodeSource(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingNodeSource) PackagingElementNode(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode) PackagingElement(com.intellij.packaging.elements.PackagingElement) DirectoryPackagingElement(com.intellij.packaging.impl.elements.DirectoryPackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement)

Example 13 with CompositePackagingElement

use of com.intellij.packaging.elements.CompositePackagingElement in project intellij-community by JetBrains.

the class LayoutTreeComponent method findParentCompositeElementNode.

@Nullable
private DefaultMutableTreeNode findParentCompositeElementNode(Point point) {
    TreePath path = myTree.getPathForLocation(point.x, point.y);
    while (path != null) {
        final PackagingElement<?> element = myTree.getElementByPath(path);
        if (element instanceof CompositePackagingElement) {
            return (DefaultMutableTreeNode) path.getLastPathComponent();
        }
        path = path.getParentPath();
    }
    return null;
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with CompositePackagingElement

use of com.intellij.packaging.elements.CompositePackagingElement in project intellij-community by JetBrains.

the class ExtractArtifactAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
    final LayoutTreeSelection selection = treeComponent.getSelection();
    final CompositePackagingElement<?> parent = selection.getCommonParentElement();
    if (parent == null)
        return;
    final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
    if (parentNode == null)
        return;
    if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
        return;
    }
    final Collection<? extends PackagingElement> selectedElements = selection.getElements();
    String initialName = "artifact";
    if (selectedElements.size() == 1) {
        initialName = PathUtil.suggestFileName(ContainerUtil.getFirstItem(selectedElements, null).createPresentation(myArtifactEditor.getContext()).getPresentableName());
    }
    IExtractArtifactDialog dialog = showDialog(treeComponent, initialName);
    if (dialog == null)
        return;
    final Project project = myArtifactEditor.getContext().getProject();
    final ModifiableArtifactModel model = myArtifactEditor.getContext().getOrCreateModifiableArtifactModel();
    final ModifiableArtifact artifact = model.addArtifact(dialog.getArtifactName(), dialog.getArtifactType());
    treeComponent.editLayout(() -> {
        for (PackagingElement<?> element : selectedElements) {
            artifact.getRootElement().addOrFindChild(ArtifactUtil.copyWithChildren(element, project));
        }
        for (PackagingElement element : selectedElements) {
            parent.removeChild(element);
        }
        parent.addOrFindChild(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).createPointer(artifact, myArtifactEditor.getContext().getArtifactModel())));
    });
    treeComponent.rebuildTree();
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) ModifiableArtifact(com.intellij.packaging.artifacts.ModifiableArtifact) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent) Project(com.intellij.openapi.project.Project) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel)

Example 15 with CompositePackagingElement

use of com.intellij.packaging.elements.CompositePackagingElement 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)

Aggregations

CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)17 PackagingElement (com.intellij.packaging.elements.PackagingElement)13 ArrayList (java.util.ArrayList)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 DirectoryPackagingElement (com.intellij.packaging.impl.elements.DirectoryPackagingElement)4 Project (com.intellij.openapi.project.Project)3 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)3 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)3 LayoutTreeComponent (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)2 LayoutTreeSelection (com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection)2 CompositePackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.CompositePackagingElementNode)2 PackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode)2 Artifact (com.intellij.packaging.artifacts.Artifact)2 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)2 ArchivePackagingElement (com.intellij.packaging.impl.elements.ArchivePackagingElement)2 PackagingSourceItem (com.intellij.packaging.ui.PackagingSourceItem)2 JBZipFile (com.intellij.util.io.zip.JBZipFile)2 File (java.io.File)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 NotNull (org.jetbrains.annotations.NotNull)2