Search in sources :

Example 6 with PackagingElement

use of com.intellij.packaging.elements.PackagingElement 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 7 with PackagingElement

use of com.intellij.packaging.elements.PackagingElement 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 8 with PackagingElement

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

the class ModuleSourceItemGroup method createElements.

@Override
@NotNull
public List<? extends PackagingElement<?>> createElements(@NotNull ArtifactEditorContext context) {
    final Set<Module> modules = new LinkedHashSet<>();
    collectDependentModules(myModule, modules, context);
    final Artifact artifact = context.getArtifact();
    final ArtifactType artifactType = artifact.getArtifactType();
    Set<PackagingSourceItem> items = new LinkedHashSet<>();
    for (Module module : modules) {
        for (PackagingSourceItemsProvider provider : PackagingSourceItemsProvider.EP_NAME.getExtensions()) {
            final ModuleSourceItemGroup parent = new ModuleSourceItemGroup(module);
            for (PackagingSourceItem sourceItem : provider.getSourceItems(context, artifact, parent)) {
                if (artifactType.isSuitableItem(sourceItem) && sourceItem.isProvideElements()) {
                    items.add(sourceItem);
                }
            }
        }
    }
    List<PackagingElement<?>> result = new ArrayList<>();
    final PackagingElementFactory factory = PackagingElementFactory.getInstance();
    for (PackagingSourceItem item : items) {
        final String path = artifactType.getDefaultPathFor(item.getKindOfProducedElements());
        if (path != null) {
            result.addAll(factory.createParentDirectories(path, item.createElements(context)));
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) PackagingElement(com.intellij.packaging.elements.PackagingElement) Artifact(com.intellij.packaging.artifacts.Artifact) ArtifactType(com.intellij.packaging.artifacts.ArtifactType) PackagingElementFactory(com.intellij.packaging.elements.PackagingElementFactory) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PackagingElement

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

the class ExtractIntoDefaultLocationAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final String pathForClasses = myArtifactEditor.getArtifact().getArtifactType().getDefaultPathFor(PackagingElementOutputKind.DIRECTORIES_WITH_CLASSES);
    if (pathForClasses != null) {
        final List<PackagingElement<?>> extracted = new ArrayList<>();
        for (PackagingSourceItem item : mySourceItemsTree.getSelectedItems()) {
            final ArtifactEditorContext context = myArtifactEditor.getContext();
            final List<? extends PackagingElement<?>> elements = item.createElements(context);
            ArtifactUtil.processElementsWithSubstitutions(elements, context, context.getArtifactType(), PackagingElementPath.EMPTY, new PackagingElementProcessor<PackagingElement<?>>() {

                @Override
                public boolean process(@NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
                    if (element instanceof FileCopyPackagingElement) {
                        final VirtualFile file = ((FileCopyPackagingElement) element).findFile();
                        if (file != null) {
                            final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file);
                            if (jarRoot != null) {
                                extracted.add(PackagingElementFactory.getInstance().createExtractedDirectory(jarRoot));
                            }
                        }
                    }
                    return true;
                }
            });
        }
        myArtifactEditor.getLayoutTreeComponent().putElements(pathForClasses, extracted);
    }
}
Also used : PackagingSourceItem(com.intellij.packaging.ui.PackagingSourceItem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) FileCopyPackagingElement(com.intellij.packaging.impl.elements.FileCopyPackagingElement) PackagingElement(com.intellij.packaging.elements.PackagingElement) PackagingElementPath(com.intellij.packaging.impl.artifacts.PackagingElementPath) ArtifactEditorContext(com.intellij.packaging.ui.ArtifactEditorContext) FileCopyPackagingElement(com.intellij.packaging.impl.elements.FileCopyPackagingElement)

Example 10 with PackagingElement

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

Aggregations

PackagingElement (com.intellij.packaging.elements.PackagingElement)18 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)13 ArrayList (java.util.ArrayList)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Artifact (com.intellij.packaging.artifacts.Artifact)4 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)4 DirectoryPackagingElement (com.intellij.packaging.impl.elements.DirectoryPackagingElement)4 NotNull (org.jetbrains.annotations.NotNull)4 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)3 PackagingSourceItem (com.intellij.packaging.ui.PackagingSourceItem)3 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 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 ArtifactType (com.intellij.packaging.artifacts.ArtifactType)2 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)2 FileCopyPackagingElement (com.intellij.packaging.impl.elements.FileCopyPackagingElement)2 ModuleOutputPackagingElement (com.intellij.packaging.impl.elements.ModuleOutputPackagingElement)2