Search in sources :

Example 6 with CompositePackagingElement

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

the class SurroundElementWithAction 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 CompositePackagingElementType<?>[] types = PackagingElementFactory.getInstance().getCompositeElementTypes();
    final List<PackagingElement<?>> selected = selection.getElements();
    if (types.length == 1) {
        surroundWith(types[0], parent, selected, treeComponent);
    } else {
        JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CompositePackagingElementType>("Surround With...", types) {

            @Override
            public Icon getIconFor(CompositePackagingElementType aValue) {
                return aValue.getCreateElementIcon();
            }

            @NotNull
            @Override
            public String getTextFor(CompositePackagingElementType value) {
                return value.getPresentableName();
            }

            @Override
            public PopupStep onChosen(final CompositePackagingElementType selectedValue, boolean finalChoice) {
                return doFinalStep(() -> surroundWith(selectedValue, parent, selected, treeComponent));
            }
        }).showInBestPositionFor(e.getDataContext());
    }
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) CompositePackagingElementType(com.intellij.packaging.elements.CompositePackagingElementType) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)

Example 7 with CompositePackagingElement

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

the class LayoutTreeComponent method update.

@Override
public boolean update(DnDEvent aEvent) {
    aEvent.setDropPossible(false);
    aEvent.hideHighlighter();
    final Object object = aEvent.getAttachedObject();
    if (object instanceof PackagingElementDraggingObject) {
        final DefaultMutableTreeNode parent = findParentCompositeElementNode(aEvent.getRelativePoint().getPoint(myTree));
        if (parent != null) {
            final PackagingElementDraggingObject draggingObject = (PackagingElementDraggingObject) object;
            final PackagingElementNode node = getNode(parent);
            if (node != null && draggingObject.canDropInto(node)) {
                final PackagingElement element = node.getFirstElement();
                if (element instanceof CompositePackagingElement) {
                    draggingObject.setTargetNode(node);
                    draggingObject.setTargetElement((CompositePackagingElement<?>) element);
                    final Rectangle bounds = myTree.getPathBounds(TreeUtil.getPathFromRoot(parent));
                    aEvent.setHighlighting(new RelativeRectangle(myTree, bounds), DnDEvent.DropTargetHighlightingType.RECTANGLE);
                    aEvent.setDropPossible(true);
                }
            }
        }
    }
    return false;
}
Also used : PackagingElementNode(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) PackagingElement(com.intellij.packaging.elements.PackagingElement) DirectoryPackagingElement(com.intellij.packaging.impl.elements.DirectoryPackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement)

Example 8 with CompositePackagingElement

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

the class LayoutTreeComponent method packInto.

public void packInto(@NotNull final List<? extends PackagingSourceItem> items, final String pathToJar) {
    final List<PackagingElement<?>> toSelect = new ArrayList<>();
    final CompositePackagingElement<?> rootElement = getArtifact().getRootElement();
    editLayout(() -> {
        final CompositePackagingElement<?> archive = PackagingElementFactory.getInstance().getOrCreateArchive(rootElement, pathToJar);
        for (PackagingSourceItem item : items) {
            final List<? extends PackagingElement<?>> elements = item.createElements(myContext);
            archive.addOrFindChildren(elements);
        }
        toSelect.add(archive);
    });
    myArtifactsEditor.getSourceItemsTree().rebuildTree();
    updateAndSelect(myTree.getRootPackagingNode(), toSelect);
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) PackagingElement(com.intellij.packaging.elements.PackagingElement) DirectoryPackagingElement(com.intellij.packaging.impl.elements.DirectoryPackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement)

Example 9 with CompositePackagingElement

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

the class ArtifactProjectStructureElement method getUsagesInElement.

@Override
public List<ProjectStructureElementUsage> getUsagesInElement() {
    final Artifact artifact = myArtifactsStructureContext.getArtifactModel().getArtifactByOriginal(myOriginalArtifact);
    final List<ProjectStructureElementUsage> usages = new ArrayList<>();
    final CompositePackagingElement<?> rootElement = myArtifactsStructureContext.getRootElement(artifact);
    ArtifactUtil.processPackagingElements(rootElement, null, new PackagingElementProcessor<PackagingElement<?>>() {

        @Override
        public boolean process(@NotNull PackagingElement<?> packagingElement, @NotNull PackagingElementPath path) {
            ProjectStructureElement element = getProjectStructureElementFor(packagingElement, ArtifactProjectStructureElement.this.myContext, ArtifactProjectStructureElement.this.myArtifactsStructureContext);
            if (element != null) {
                usages.add(createUsage(packagingElement, element, path.getPathStringFrom("/", rootElement)));
            }
            return true;
        }
    }, myArtifactsStructureContext, false, artifact.getArtifactType());
    return usages;
}
Also used : PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) ArrayList(java.util.ArrayList) ArtifactPackagingElement(com.intellij.packaging.impl.elements.ArtifactPackagingElement) LibraryPackagingElement(com.intellij.packaging.impl.elements.LibraryPackagingElement) FacetBasedPackagingElement(com.intellij.packaging.impl.elements.FacetBasedPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) ModuleOutputPackagingElement(com.intellij.packaging.impl.elements.ModuleOutputPackagingElement) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 10 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)

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